Skip to content

Instantly share code, notes, and snippets.

@brinko99
Created June 24, 2020 20:22
Show Gist options
  • Save brinko99/2bb84da5351403ab076d262d9d8487a4 to your computer and use it in GitHub Desktop.
Save brinko99/2bb84da5351403ab076d262d9d8487a4 to your computer and use it in GitHub Desktop.
MSBuild Target that checks if build occurred
<!--Inpired by: https://stackoverflow.com/a/13849011/84522 -->
<Target Name="GetLastModifiedTime" BeforeTargets="BeforeBuild">
<PropertyGroup>
<LastModifiedTime>%(IntermediateAssembly.ModifiedTime)</LastModifiedTime>
</PropertyGroup>
</Target>
<Target Name="CheckWasBuilt" AfterTargets="AfterBuild">
<PropertyGroup>
<!--WasBuilt is true only if a build/rebuild occurred. Can be used as a condition on other Targets that only need
to run when after a build actually occurred. Those targets should be configured with:
AfterTargets="CheckWasBuilt", Condition="$(WasBuilt) -->
<WasBuilt>false</WasBuilt>
<WasBuilt Condition="%(IntermediateAssembly.ModifiedTime) != $(LastModifiedTime)">true</WasBuilt>
</PropertyGroup>
</Target>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment