Jason Jason - 26 days ago 6
C++ Question

How do I get a simple batch file to run with my project in Visual Studio?

Basically, I have two projects, one which compiles to a dll and the other which consumes that dll. What I want is for the .dll file to be copied to the dependent project's binary folder so that project can use it. I can't just do a simple "copy" script because then my dll won't get recopied upon recompilation. It was suggested that instead I should run a couple commands, one which deletes the old dll if there is one, and then copy the newly compiled dll to the location. It was also recommended to do this with a batch file. I've never written a batch file for visual studio (or anything else for that matter) so my question is how would I:

1.) write a batch file that would say something like:

if dll exists then delete and copy over the new dll

2.) Get that batch file to run with my project in visual studio?

Thanks for any help!

Answer

You need to get the results (.dll) of one project into the other project's folder. There are multiple ways to do this, but one way is the following.

  1. Go to the project properties of your DLL project.
  2. Go to Build Events -> Post-Build Event
  3. Enter copy <filename>.dll ..\otherproject\bin /y

This will copy the DLL to the destination folder, overwriting it if it's already there (and if it's not in use). You may need to adjust the directories depending on your project structure.