我有一个构建 */.sln 文件的 MSBuild 文件(构建所有存在的 .sln 文件).
I have an MSBuild file that builds */.sln files (builds all .sln files that exist).
构建使用 Build 目标,因此如果没有对输入文件进行任何更改,则不应再次构建任何项目.
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 做到了(这个文件 always 提供了关于如何使用 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 目标的依赖关系最终会记录下来构建前后输出文件的时间戳.如果它们相等,则不会生成输出.所以剩下的就是让你的目标在 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 目标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
有没有办法知道是否有人为您的网站添加了书签Is there a way to know if someone has bookmarked your website?(有没有办法知道是否有人为您的网站添加了书签?)
使用不同的 .Net 语言?Use of Different .Net Languages?(使用不同的 .Net 语言?)
确定 ASP.NET 站点的“活动"用户数Determining an #39;active#39; user count of an ASP.NET site(确定 ASP.NET 站点的“活动用户数)
跟踪当前在线用户的最佳方式Best way to keep track of current online users(跟踪当前在线用户的最佳方式)
推荐一个开源的.NET统计库Recommend an Open Source .NET Statistics Library(推荐一个开源的.NET统计库)
给定轮班列表,创建时间表的摘要描述Create a summary description of a schedule given a list of shifts(给定轮班列表,创建时间表的摘要描述)