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!)
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.
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 ...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With