Search code examples
.net-corecommand-line-interfaceasp.net-core-2.0git-rev-parse

.NET Core 2.1 using environment variables for build using git hash in dotnet core command CLI


How to embed git hash to use in dotnet build command to be able to catch it and put in build pipeline process as an environment variable ${hash} and use ${hash} environment variable in appsettings..json files for ASP.NET Core 2.1 WebAPI?


Solution

  • If you want to enable Git version information in your assembly, a good option is to use utilities like NerdBank.GitVersioning. It allows you to automatically calculate the version number based on the number of Git commits, include the Git commit SHA hash, and more.

    You can use the nbgv .NET CLI tool or NerdBank.GitVersioning manually using a NuGet package.