根据文件依赖关系执行 POST_BUILD 命令
我有一个 DLL POST_BUILD 步骤,将 DLL 复制到目录 A。假设我然后从目录 A 中删除该文件。然后我在 Visual Studio 中按 F5,但该文件没有被复制。
我在这里有什么选择?如何指定每次链接 DLL 时以及目录 A 中的文件过期(或丢失)时都必须执行的一组操作?
编辑:这具体是一个非托管 C++ 项目,并且仅具有由 CMake 生成的 .vcproj 文件。因此,编辑 .vcproj 在我的工作流程中不切实际。
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.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
仅当 msbuild 确定需要重建项目时才会执行构建后命令。否则它不知道您的项目依赖于该文件,因为它不解析构建后命令,这是不切实际的。
到目前为止,最简单的解决方案是不删除该文件,没有什么意义。另一种使 msbuild 更智能的方法是将文件添加到项目中。使用项目+添加现有项目。设置构建操作 = 内容,复制到输出目录 = 如果较新则复制。当然,它确实会堵塞您的项目树。
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.
汉斯的做法也不错。
您最好直接编辑项目,而不是使用 IDE 挂钩,因为 msbuild 提供了一组完整的任务来执行您想要的操作。
如果编辑 .csproj 文件(右键单击 -> 卸载项目 -> 编辑)并添加构建后步骤,您将获得所需的脏复制行为:
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: