开发者

Executing POST_BUILD commands based upon file dependencies

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 operati开发者_开发问答ons 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.


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'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>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜