0

I have a DLL POST_BUILD step that copies the DLL to directory A. Suppose I then delete the file from directory A. I then hit F5 inside Visual Studio and the file is not copied.

What are my options here? How do I specify that there is a set of operations that must be executed both every time the DLL is linked, and when the file in directory A is out of date with (or missing)?

EDIT: This is specifically an unmanaged C++ project, and only has .vcproj files, generated by CMake. Therefore, editing the .vcproj is not practical in my workflow.

Ritch Melton
  • 11,498
  • 4
  • 41
  • 54
bgoodr
  • 2,744
  • 1
  • 30
  • 51

2 Answers2

1

The post build commands are only executed when msbuild determines that the project needs to be rebuilt. It doesn't otherwise know that your project has a dependency on that file since it doesn't parse the post build commands, that's unpractical.

By far the simplest solution is to just not delete that file, there's little point. Another way to do it, making msbuild smarter, is to add the file to your project. Use Project + Add Existing Item. Set Build action = Content, Copy to Output Directory = Copy if Newer. It does clog up your project tree a bit of course.

Hans Passant
  • 922,412
  • 146
  • 1,693
  • 2,536
  • I'll have to accept that as the answer even though that may not be possible within the confines of the CMake syntax. – bgoodr Sep 30 '11 at 00:11
1

Hans's approach is good too.

Rather than using the IDE hooks, you are better off by editing the project directly as msbuild provides a complete set of tasks for doing what you want.

If you edit the .csproj file (right click -> unload project -> edit) and add a post-build step, you'll get the dirty copy behaviour you want:

<Target Name="AfterBuild">
  <ItemGroup>
    <BuildArtifacts Include="MyDll.dll"/>
    <FileWrites Include="$(DestDir)\*.*" />
  </ItemGroup>
  <Copy SourceFiles="@(BuildArtifacts)" DestinationFiles="->'$(DestDir)\%(Filename)%(Extension)'" />
</Target>
Ritch Melton
  • 11,498
  • 4
  • 41
  • 54
  • A clarification: This is specifically an unmanaged C++ project, and only has .vcproj files, generated by CMake. Therefore, editing the .vcproj is not practical in my workflow. I'll edit the problem statement to indicate that CMake is being used. – bgoodr Sep 30 '11 at 00:06