dotnet-installer/build/GitCommitInfo.targets

51 lines
2.2 KiB
Text
Raw Normal View History

2017-02-08 22:02:29 +00:00
<Project ToolsVersion="15.0">
<Target Name="WriteGitCommitInfoProps">
<Exec Command="git rev-list --count HEAD"
ConsoleToMSBuild="true"
Condition=" '$(GitInfoCommitCount)' == '' ">
<Output TaskParameter="ConsoleOutput" PropertyName="GitInfoCommitCount" />
</Exec>
2017-02-10 20:13:44 +00:00
<Exec Command="git rev-parse HEAD"
ConsoleToMSBuild="true"
Condition=" '$(GitInfoCommitHash)' == '' ">
<Output TaskParameter="ConsoleOutput" PropertyName="GitInfoCommitHash" />
</Exec>
2017-02-08 22:02:29 +00:00
2017-03-07 21:22:13 +00:00
<ItemGroup>
<GitInfoCommitCountLines Include="$(GitInfoCommitCount)" />
<GitInfoCommitHashLines Include="$(GitInfoCommitHash)" />
</ItemGroup>
2017-02-08 22:02:29 +00:00
<PropertyGroup>
2017-03-07 21:22:13 +00:00
<!-- Batching in GitInfoCommitCount and GitInfoCommitHash here ensures that the property contains only the last line of the output -->
<GitInfoCommitCount>%(GitInfoCommitCountLines.Identity)</GitInfoCommitCount>
2017-03-07 19:04:18 +00:00
<GitInfoCommitCount>$(GitInfoCommitCount.PadLeft(6,'0'))</GitInfoCommitCount>
2017-03-07 21:22:13 +00:00
<GitInfoCommitHash>%(GitInfoCommitHashLines.Identity)</GitInfoCommitHash>
2017-02-08 22:02:29 +00:00
<GitCommitInfoPropsContent>
&lt;Project ToolsVersion=&quot;15.0&quot; xmlns=&quot;http://schemas.microsoft.com/developer/msbuild/2003&quot;&gt;
2017-02-08 22:02:29 +00:00
&lt;PropertyGroup&gt;
&lt;CommitCount&gt;$(GitInfoCommitCount)&lt;/CommitCount&gt;
2017-02-08 22:02:29 +00:00
&lt;CommitHash&gt;$(GitInfoCommitHash)&lt;/CommitHash&gt;
&lt;/PropertyGroup&gt;
&lt;/Project&gt;
</GitCommitInfoPropsContent>
<ExistingGitCommitInfoProps Condition=" Exists('$(GitCommitInfoProps)') ">
$([System.IO.File]::ReadAllText($(GitCommitInfoProps)))
</ExistingGitCommitInfoProps>
<ShouldOverwriteGitCommitInfoPropsFile>false</ShouldOverwriteGitCommitInfoPropsFile>
<ShouldOverwriteGitCommitInfoPropsFile
Condition=" '$(ExistingGitCommitInfoProps.Trim())' != '$(GitCommitInfoPropsContent.Trim())' ">true</ShouldOverwriteGitCommitInfoPropsFile>
2017-02-08 22:02:29 +00:00
</PropertyGroup>
2017-03-07 20:02:47 +00:00
2017-02-08 22:02:29 +00:00
<WriteLinesToFile File="$(GitCommitInfoProps)"
Lines="$(GitCommitInfoPropsContent)"
Condition=" '$(ShouldOverwriteGitCommitInfoPropsFile)' == 'true' "
2017-02-09 18:50:21 +00:00
Overwrite="true" />
2017-02-08 22:02:29 +00:00
</Target>
</Project>