【问题标题】:.NET Core 2.1 using environment variables for build using git hash in dotnet core command CLI.NET Core 2.1 使用环境变量在 dotnet core 命令 CLI 中使用 git hash 进行构建
【发布时间】:2025-12-27 09:15:11
【问题描述】:

如何嵌入 git hash 以在dotnet build 命令中使用,以便能够捕获它并将构建管道过程作为环境变量${hash} 并在appsettings.json 文件中为ASP 使用${hash} 环境变量。 NET Core 2.1 WebAPI?

【问题讨论】:

    标签: .net-core command-line-interface asp.net-core-2.0 git-rev-parse


    【解决方案1】:

    如果你想在你的程序集中启用 Git 版本信息,一个不错的选择是使用像 NerdBank.GitVersioning 这样的实用程序。它允许您根据 Git 提交的数量自动计算版本号,包括 Git 提交的 SHA 哈希等。

    您可以use the nbgv .NET CLI toolNerdBank.GitVersioning manually using a NuGet package

    【讨论】: