运行一个MSBuild的目标只有当项目实际建成 [英] Run an MSBuild target only if project is actually built

查看:188
本文介绍了运行一个MSBuild的目标只有当项目实际建成的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个建立*的 / 的的.sln文件(构建中存在的所有的.sln文件)。

I have an MSBuild file that builds */.sln files (builds all .sln files that exist).

构建使用的构建的目标,因此,如果没有变化,输入文件进行,没有项目应重新建立。

The build uses the Build target, so if no changes were made to input files, no project should be built again.

我想执行一些自定义的目标的仅在一个项目居然被重新建立。

I would like to execute some custom target only if a project actually gets built again.

如何才能做到这一点?

两个 AfterBuild AfterCompile 总是被调用,不管在编译/构建实际发生。

Both AfterBuild and AfterCompile are always called, no matter if the compile/build actually takes place.

推荐答案

基本上你想要的相同的行为 PostBuildEvent 例如,让我抬头一看怎么 Microsoft.Common.Targets 做它(这个文件的总是的规定中是如何的MSBuild应该是一个很好的洞察力,可以使用)。这里的解决方案:

Basically you want the same behaviour as the PostBuildEvent for instance, so I looked up how Microsoft.Common.Targets does it (this file always provides a nice insight in to how msbuild is supposed to be used). Here's the solution:

<PropertyGroup>
  <RunPostBuildEvent>OnOutputUpdated</RunPostBuildEvent>
</PropertyGroup>
<Import Project="$(MSBuildToolsPath)\Microsoft.CSharp.targets" />
<Target Name="RunWhenBuild" AfterTargets="CoreBuild"       
        Condition="'$(_AssemblyTimestampBeforeCompile)'!='$(_AssemblyTimestampAfterCompile)'">
  <Message Importance="high" Text="RunWhenBuild!!"/>
</Target>

这就是所发生的:当有一个命名属性 RunPostBuildEvent OnOutputUpdated 的值 CoreBuild 目标的dependncies前和构建后最终将记录输出文件的时间戳。如果他们是平等的输出并没有建立。因此,所有剩下的就是让你的目标之后 CoreBuild 运行,并检查这些时间戳。

And this is what goes on: when there is a property named RunPostBuildEvent with a value of OnOutputUpdated the CoreBuild target's dependncies will eventually record the timestamp of the output file before and after the build. And if they are equal the output was not build. So all that is left is getting your target to run after CoreBuild and checking on these timestamps.

这篇关于运行一个MSBuild的目标只有当项目实际建成的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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