Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Add Git commit count to version
<Project>
<PropertyGroup>
<GenerateNuspecDependsOn>AddGitCommitCountToVersion;$(GenerateNuspecDependsOn)</GenerateNuspecDependsOn>
<!-- this is only used in NuGet 4.6.0 -->
<GetPackageVersionDependsOn>AddGitCommitCountToVersion;$(GetPackageVersionDependsOn)</GetPackageVersionDependsOn>
</PropertyGroup>
<Target Name="AddGitCommitCountToVersion"
BeforeTargets="PrepareForBuild;_GenerateRestoreProjectSpec"
Condition=" '$(DisableGitVersionSuffix)' != 'true' ">
<Exec Command="git rev-list --count HEAD" ConsoleToMSBuild="true" StandardOutputImportance="low">
<Output TaskParameter="ConsoleOutput" PropertyName="GitCommitCount" />
</Exec>
<PropertyGroup>
<PreReleaseLabel Condition=" '$(PreReleaseLabel)' == '' ">beta</PreReleaseLabel>
<VersionCommitCountSuffix>$(GitCommitCount.PadLeft(6, '0'))</VersionCommitCountSuffix>
<Version>$(Version)-$(PreReleaseLabel)-$(VersionCommitCountSuffix)</Version>
<PackageVersion>$(Version)</PackageVersion>
</PropertyGroup>
</Target>
</Project>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment