Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I make sure every file in an included directory is copied to the destination in Visual Studio?

I'm building an application that has quite a few files that need to be included in the destination directory. So far, there haven't been very many files so I would simply change the settings of each file individually to Copy to Output Directory :: Copy if newer. The problem now is that I'm adding files at an exponential rate.

enter image description here

Do any of you know how to make all of the files that are sub of the "Some_Directory" have the Copy to Output Directory :: Copy if newer set how I want it?

like image 881
Freesnöw Avatar asked Dec 29 '25 21:12

Freesnöw


1 Answers

You cam use a post-build event.

Using following posts, I made a post event that does exactly what you want:

  • Copying files into the application folder at compile time
  • Copy to Output Directory copies folder structure but only want to copy files
  • Visual Studio adds .dll and .pdb to project after compiling

Now, you can easily edit Post-build events, go to your project settings and go to the Compile tab, now click the Build Events and put following line in the *Post-build event command line" text box:

xcopy "$(ProjectDir)Test\*.*" "$(TargetDir)Test\\" /E /I /F /Y

See this image: post-build event

In your case you will have to change "Test" by "some_directory" and that's all.

There is one caveat, however. This copies every file every time my project builds. The folder that is being copied is over 3MB (I'm developing quite a large project). This makes debugging take quite a long time because every time I do a build it has to move all of the content over. Is there a way to make it only copy over files that have been updated since the last build? This is why I was using the Copy if newer option.

You can add the /D parameter (you can look that up with xcopy /? in your command prompt).

/D:m-d-y     Copies files changed on or after the specified date.
             If no date is given, copies only those files whose
             source time is newer than the destination time.
like image 133
Styxxy Avatar answered Dec 31 '25 10:12

Styxxy