Run an MSBuild target only if project is actually built

前端 未结 1 422
我在风中等你
我在风中等你 2020-12-18 03:19

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

相关标签:
1条回答
  • 2020-12-18 03:45

    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>
    

    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.

    0 讨论(0)
提交回复
热议问题