MSbuild构建顺序问题-先进行预构建,然后再进行从属项目 [英] MSbuild build order issue - pre-build steps first or dependent projects first

查看:309
本文介绍了MSbuild构建顺序问题-先进行预构建,然后再进行从属项目的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个依赖于项目B的项目A.项目A具有一些预生成任务,这些任务依赖于项目B中生成的某些文件.在Visual Studio中生成时,没有问题.但是,使用MSBuild.exe时会出现问题,因为构建顺序为:

I have a project A depending on project B. Project A has some pre-build tasks that is dependent of some generated files from project B. When I build in Visual Studio, no problem. But when using MSBuild.exe, then there is problem because the build order is:

  • A的预构建步骤<-失败,因为B尚未编译
  • B已编译<-预计将首先执行
  • A已编译

使用MSBuild是否是预期的行为? 有没有办法告诉MSBuild在A的预构建步骤之前先做B?

Is it the expected behaviour using MSBuild? Is there a way to tell MSBuild to do B first before A's prebuild steps?

我正在使用VS2010 C#和C ++/CLI.我不认为是否可以提供其他信息,但是这里是这样称呼的:

I am using VS2010 C# and C++/CLI. I don't think if offeres additional info but here is how it is called:

Running process (C:\Windows\Microsoft.NET\Framework\v4.0.30319\MSBUILD.exe "..\..\..\dev\build\MyProj.sln" /t:Clean /p:Configuration=Release;Platform=Win32)

推荐答案

简短答案

删除构建事件,然后将以下内容添加到项目(.csproj):

Remove your build event, and add something like the following to your project (.csproj):

<Target Name="AfterResolveReferences">
  <Exec Command="echo helloworld" />
</Target>

更多信息

您可以在此处阅读有关自定义构建过程的信息: http://msdn.microsoft.com/en-us/library/ms366724%28v=vs.110%29.aspx

You can read about customising the build process here: http://msdn.microsoft.com/en-us/library/ms366724%28v=vs.110%29.aspx

在ResolveReferences之前会触发Build Before Build事件,因此,如果在您的项目的BeforeBuild事件发生时尚未构建您引用的项目,那么BeforeBuild事件将失败.

The Before Build event is fired before ResolveReferences, so if the project you reference has not already been built by the time it comes to your project's BeforeBuild event, then your BeforeBuild event will fail.

要解决此问题,您应该使用其他入口点来自定义构建过程.在上面的示例中,我使用AfterResolveReferences,因为这将确保您引用的所有项目都已构建.

To overcome this, you should use a different entry point to customize the build process. In the above example, I use AfterResolveReferences, since this will ensure that all projects which you reference are already built.

这篇关于MSbuild构建顺序问题-先进行预构建,然后再进行从属项目的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆