从 C# 执行 DllImport 到非托管 C++ 时 MSBuild 4.0 存在依赖性问题图书馆
VS2010 中支持在 VS2010 中显式设置非托管 C++ 项目和 C# 项目之间的依赖关系,但在 MSBuild 4.0 中会忽略依赖关系。
据我所知,不可能从 C# 项目添加对非托管 C++ 项目的引用。
如果解决方案包含非托管和托管项目,如何确保正确的构建顺序?
Explicitly setting dependency in VS2010 between unmanaged C++ project and C# project is honored in VS2010, but dependency is ignored in MSBuild 4.0.
It is impossible to add a reference to unmanaged C++ project from C# project, afaik.
How do i ensure correct build order if a solution contains unmanaged and managed projects?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
MSBuild 有一个错误,无法正确遵守在解决方案级别添加的项目依赖项。看一下 http: //social.msdn.microsoft.com/Forums/en-US/msbuild/thread/80cc6447-b720-4806-8395-7c257b207613/ 和 https://connect.microsoft.com/VisualStudio/feedback/详细信息/613284/msbuild-4-does-not-respect-build-order-when-building-a-solution
Microsoft 在连接页面上发布的帖子表明,这是 64 位版本的 MSBuild 中的一个错误。尝试切换到 32 位版本,看看是否可以解决问题。
如果您不能这样做,或者它不起作用,还有其他两种选择。它们都不是理想的。
第一个选项是手动编辑 SLN 文件并更改项目在文件中显示的顺序以匹配您想要的构建顺序。我想维克多的解决方案会是一个更好的主意,因为对解决方案文件的额外更改可能最终会再次覆盖更改。
第二个选项是手动导出解决方案的 MSBuild“元项目”并直接编辑构建顺序并添加您需要的任何其他自定义项。据我所知,即使在 Microsoft,他们也不会“dogfood”解决方案编译 - 相反,他们在构建过程中完全避免它们并使用自定义 MSBuild 文件。
要生成 metaproj,请将环境变量 MSBuildEmitSolution 设置为 1。在解决方案上运行 MSBuild 后,您应该在同一目录中看到一个“.metaproj”文件 - 它包含 MSBuild 在内存中生成的用于编译解决方案的脚本。您应该能够进行必要的编辑,将其签入,然后设置构建服务器来编译它。
该问题将在 Visual Studio 的下一版本中消失。 Microsoft Connect 页面上有一个来自 Microsoft 的帖子,表示该问题将在下一个版本中修复,有传言称他们正在删除 .sln 文件并用适当的 MSBuild 项目替换它们。
MSBuild has a bug in it and doesn't correctly honor project dependencies added at the solution level. Take a look at http://social.msdn.microsoft.com/Forums/en-US/msbuild/thread/80cc6447-b720-4806-8395-7c257b207613/ and https://connect.microsoft.com/VisualStudio/feedback/details/613284/msbuild-4-does-not-respect-build-order-when-building-a-solution
A posting by Microsoft on the connect page indicates that its a bug in the 64-bit version of MSBuild. Try switching to the 32-bit version to see if that solves the problem.
If you can't do that, or it doesn't work, there are two other options. Neither of them are ideal.
The first option would be to manually edit the SLN file and change the order the projects appear in the file to match the build order you want. I imagine Victor's solution would be a much better idea, since additional changes to the solution file could end up overwriting the changes again.
The second option would be to manually export the MSBuild "metaproject" for the solution and edit the build order directly and add any other customizations you need. From what I've read, even at Microsoft they don't "dogfood" solution compilation - instead, they avoid them completely during builds and use custom MSBuild files instead.
To generate the metaproj, set the environment variable MSBuildEmitSolution to 1. After running MSBuild on the solution and you should see a ".metaproj" file in the same directory - it contains the script that MSBuild generates in-memory to compile the solution. You should be able to make the necessary edits, check it in, then set the build server to compile it.
The issue will disappear in the next release of Visual Studio. The Microsoft Connect page has a posting from Microsoft that it will be fixed in the next release, and rumor has it they're getting rid of .sln files and replacing them with proper MSBuild projects.