Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to create an empty folder on build in Visual Studio 2010?

I have a VS2010 project which needs to create a dataIn and a dataOut directory in the bin\debug directory to allow some tests to run.

Creating the dataIn directory is easy - just add the folder with the contents to the project and set the "Copy To Output Directory" property for each of the files it contains to "Copy always" (or edit the project file to use a wildcard to catch all files, as suggested by other answers on SO) - the directory will be created automatically by VS so that the files can be copied into it.

My question: how can I ensure the dataOut directory is created automatically when needed?

There are no files to go in it, so there is nothing for this directory in the ItemGroup. If I add an entry for the directory to the project file by hand then I get the error:

"<path>\dataOut" is actually a directory.  The "Copy" task does not support copying directories.

(edit: removed underscores from the directory names so the italics would work!)

like image 674
Rob Gilliam Avatar asked Nov 02 '12 11:11

Rob Gilliam


2 Answers

Try this in the pre-build step:

if not exist "$(TargetDir)dataOut" mkdir "$(TargetDir)dataOut"

The quotes are important if you have spaces somewhere in $(TargetDir), but I'd use them regardless for robustness.

like image 129
Flynn1179 Avatar answered Oct 30 '22 18:10

Flynn1179


One way I've managed so far is the rather obvious step of adding a dummy text file to the folder and setting its "Copy to Output Directory" property to "Copy always". I've also added a post-build step to remove the dummy file afterwards, leaving the now-empty directory behind (although for this particular project, that's really only due to my fussiness - there'd be no impact if it wasn't there).

I'd still like to know if there's a better option, though ...

like image 34
Rob Gilliam Avatar answered Oct 30 '22 18:10

Rob Gilliam