dotnet-installer/build/GitCommitInfo.targets
2017-03-07 13:22:42 -08:00

45 lines
1.8 KiB
XML

<Project ToolsVersion="15.0">
<Target Name="WriteGitCommitInfoProps">
<Exec Command="git rev-list --count HEAD"
ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="GitInfoCommitCount" />
</Exec>
<Exec Command="git rev-parse HEAD"
ConsoleToMSBuild="true">
<Output TaskParameter="ConsoleOutput" PropertyName="GitInfoCommitHash" />
</Exec>
<ItemGroup>
<GitInfoCommitCountLines Include="$(GitInfoCommitCount)" />
<GitInfoCommitHashLines Include="$(GitInfoCommitHash)" />
</ItemGroup>
<PropertyGroup>
<!-- Batching in GitInfoCommitCount and GitInfoCommitHash here ensures that the property contains only the last line of the output -->
<GitInfoCommitCount>%(GitInfoCommitCountLines.Identity)</GitInfoCommitCount>
<GitInfoCommitCount>$(GitInfoCommitCount.PadLeft(6,'0'))</GitInfoCommitCount>
<GitInfoCommitHash>%(GitInfoCommitHashLines.Identity)</GitInfoCommitHash>
<ShouldOverWriteThePropsFile
Condition=" 'ForceStringComparison$(CommitCount)' != 'ForceStringComparison$(GitInfoCommitCount)' Or
'$(CommitHash)' != '$(GitInfoCommitHash)' ">true</ShouldOverWriteThePropsFile>
<GitCommitInfoPropsContent>
&lt;Project ToolsVersion=&quot;15.0&quot;&gt;
&lt;PropertyGroup&gt;
&lt;CommitCount&gt;$(GitInfoCommitCount)&lt;/CommitCount&gt;
&lt;CommitHash&gt;$(GitInfoCommitHash)&lt;/CommitHash&gt;
&lt;/PropertyGroup&gt;
&lt;/Project&gt;
</GitCommitInfoPropsContent>
</PropertyGroup>
<WriteLinesToFile File="$(GitCommitInfoProps)"
Lines="$(GitCommitInfoPropsContent)"
Condition=" '$(ShouldOverwriteThePropsFile)' == 'true' "
Overwrite="true" />
</Target>
</Project>