3

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?

3 Answers 3

1

You cam use a post-build event.

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

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.
4
  • These links show answers that are to vague. I'm also utilizing Vb.net, not C#. I need very specific answers and in depth explanations on how to solve my particular situation.
    – Freesnöw
    Jun 8, 2012 at 8:52
  • 1
    It is both .NET, really, there is not that much difference. The offered solutions are not that vague, they are pretty clear to me. I updated my post to include the solution, all ready for you. I hope you can use it.
    – Styxxy
    Jun 9, 2012 at 16:47
  • Hey, that worked really well. Sorry that I'm so dumb :P. 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. +1 for you for the help so far, though!
    – Freesnöw
    Jun 10, 2012 at 18:41
  • 1
    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. I updated the answer.
    – Styxxy
    Jun 10, 2012 at 20:28
1

You can write your own custom Post-Build event (Select project -> Properties -> Build Events) with xcopy command. You can use $(solution) macro for your solution directory and specify relative path to your files.

1

I had the same issue, but the accepted answer didn't solve it. What worked for me was to enable deployment in Local.testsettings (under Solution Items).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.