VersionInfoGenerator 3.1.0

This package has a SemVer 2.0.0 package version: 3.1.0+git-28dd070.
dotnet add package VersionInfoGenerator --version 3.1.0
NuGet\Install-Package VersionInfoGenerator -Version 3.1.0
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="VersionInfoGenerator" Version="3.1.0">
  <PrivateAssets>all</PrivateAssets>
  <IncludeAssets>runtime; build; native; contentfiles; analyzers</IncludeAssets>
</PackageReference>
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add VersionInfoGenerator --version 3.1.0
#r "nuget: VersionInfoGenerator, 3.1.0"
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
// Install VersionInfoGenerator as a Cake Addin
#addin nuget:?package=VersionInfoGenerator&version=3.1.0

// Install VersionInfoGenerator as a Cake Tool
#tool nuget:?package=VersionInfoGenerator&version=3.1.0

VersionInfoGenerator

Latest version License

A .NET library that makes csproj version information (including git state) available at runtime and compile time.

Compliant with SemVer 2.0.0

How to use

In your .csproj:

<PropertyGroup>
  <Version>1.0.0</Version> 
  <VersionPrerelease>rc1</VersionPrerelease> 
</PropertyGroup>

<ItemGroup>
  <PackageReference Include="VersionInfoGenerator" Version="3.1.0" PrivateAssets="all" />
</ItemGroup>

Output:

file_info

internal static class VersionInfo
{
    public const string RootNamespace = "VersionInfoGenerator.TestProject";
    public const string Version = "1.0.0";
    public const string VersionPrerelease = "rc1";
    public const string VersionMetadata = "git-ac717b1";
    public const string SemVer = "1.0.0-rc1+git-ac717b1";
    public const string GitRevShort = "ac717b1";
    public const string GitRevLong = "ac717b1885cd0f984cabe77dd5f37c9200795298";
    public const string GitBranch = "master";
    public const string GitTag = "v1.0.0";
    public const int GitCommitsSinceTag = 0;
    public const bool GitIsDirty = false;
}

Settings

<PropertyGroup>
  
  <Version>1.0.0</Version>
  
  <VersionValidate>true</VersionValidate>
  
  <VersionPrerelease></VersionPrerelease>
  
  <VersionMetadata>git-@@GitRevShort@@</VersionMetadata>
  
  <VersionInfoUseMetadata>true</VersionInfoUseMetadata>
  
  <VersionInfoOverrideVersions>true</VersionInfoOverrideVersions>
  
  <VersionInfoOverridePackageVersion>true</VersionInfoOverridePackageVersion>
  
  <VersionInfoOverrideRepositoryInfo>true</VersionInfoOverrideRepositoryInfo>
  
  <VersionInfoClassName>VersionInfo</VersionInfoClassName>
  
  
  <VersionInfoClassNamespace></VersionInfoClassNamespace>
  
  <VersionInfoClassNamespaceGlobal>false</VersionInfoClassNamespaceGlobal>
  
  <VersionInfoClassModifiers>internal static</VersionInfoClassModifiers>
  
  <VersionInfoGenerateClass>true</VersionInfoGenerateClass>
  
  <VersionInfoClassSerializedProperties>RootNamespace;Version;VersionPrerelease;VersionMetadata;SemVer;GitRevShort;GitRevLong;GitBranch;GitTag;GitCommitsSinceTag;GitIsDirty</VersionInfoClassSerializedProperties>
  
  <VersionInfoGenerateJson>false</VersionInfoGenerateJson>
  
  <VersionInfoJsonOutputPath>VersionInfo.json</VersionInfoJsonOutputPath>
  
  <VersionInfoJsonSerializedProperties>RootNamespace;Version;VersionPrerelease;VersionMetadata;SemVer;GitRevShort;GitRevLong;GitBranch;GitTag;GitCommitsSinceTag;GitIsDirty</VersionInfoClassJsonSerializedProperties>
</PropertyGroup>

A config file (named VersionInfoGenerator.Config.props) can be created to gain more control over the MSBuild properties, e.g.:

<Project>
  <PropertyGroup>
    <GitBinary>/path/to/git</GitBinary>
  </PropertyGroup>

  <Target Name="VersionInfoConfig" AfterTargets="VersionInfoGenerator_GetGitInfo">
    <PropertyGroup>
      <VersionMetadata>NO_TAG</VersionMetadata>
      <VersionMetadata Condition="'$(GitTag)' != ''">$(GitTag)</VersionMetadata>
    </PropertyGroup>

    <PropertyGroup Condition="'$(GitCommitsSinceTag)' != '0'">
      <VersionMetadata>$(VersionMetadata)-$(GitCommitsSinceTag)</VersionMetadata>
    </PropertyGroup>

    <PropertyGroup Condition="'$(GitBranch)' == 'master'">
      <VersionMetadata>$(VersionMetadata)-RELEASE</VersionMetadata>
    </PropertyGroup>
  </Target>
</Project>

VersionInfo.json

A JSON file can be generated for version processing by external tools, e.g.:

<PropertyGroup>
  <VersionInfoGenerateJson>true</VersionInfoGenerateJson>
</PropertyGroup>

Output (bin/Release/xxx/VersionInfo.json):

{
  "RootNamespace": "VersionInfoGenerator.TestProject",
  "Version": "1.0.0",
  "VersionPrerelease": null,
  "VersionMetadata": "git-0378e47",
  "SemVer": "1.0.0+git-0378e47",
  "GitRevShort": "0378e47",
  "GitRevLong": "0378e47109d698eeceaf07ad75e48ea36143d2e3",
  "GitBranch": "master",
  "GitTag": "v1.0.0",
  "GitCommitsSinceTag": 0,
  "GitIsDirty": false
}

Special variable substitution

Special variables can be used to customize the SemVer metadata (as an alternative to VersionInfoGenerator.Config.props):

  • @@GitRevShort@@: the 7-character hash of the current commit (suffixed with -dirty if there's uncommited changes)
  • @@GitRevLong@@: the full hash of the current commit (suffixed with -dirty if there's uncommited changes)
  • @@GitBranch@@: the current git branch
  • @@GitTag@@: the current git tag
  • @@GitCommitsSinceTag@@: the number of commits since the last git tag
  • @@VersionMetadata@: the default VersionMetadata format (git-@@GitRevShort@@)

Troubleshooting

If you encounter any issues, make sure to:

  • Rebuild the project/solution then restart your IDE
  • Test building through the command line using dotnet build
  • Update your IDE to the latest version (requires at least Visual Studio 2019 16.9; Jetbrains Rider is untested)
  • Update the dotnet runtime to the latest version

If none of the above works, open an issue.

There are no supported framework assets in this package.

Learn more about Target Frameworks and .NET Standard.

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last updated
3.1.0 106 5/10/2024
3.0.0 585 5/25/2023
2.1.7 172 5/20/2023
2.1.6 188 9/25/2022
2.1.5 132 7/28/2022
2.1.4 88 7/28/2022
2.1.3 289 7/20/2021
2.1.2 193 6/23/2021
2.1.1 178 6/23/2021
2.1.0 178 6/19/2021
2.0.3 194 6/18/2021
2.0.2 168 6/11/2021
2.0.1 129 6/9/2021
2.0.0 269 4/5/2021
1.1.1 373 3/31/2021
1.1.0 358 3/31/2021
1.0.2 312 3/25/2021
1.0.1 341 3/23/2021
1.0.0 358 3/23/2021
0.2.0 339 3/15/2021
0.1.6 303 3/15/2021
0.1.5 304 3/15/2021
0.1.4 329 3/12/2021
0.1.3 325 3/11/2021
0.1.2 323 3/11/2021
0.1.1 350 3/9/2021
0.1.0 298 3/9/2021