修改 github 操作管道中的 nupkg 版本

Modifying the version of a nupkg in github actions pipeline

我们 运行 在 GitHub 上遇到了 NuGet 管道的问题。我们将它设置为 运行 构建项目的步骤,NuGet 将其打包为特定版本(RC 版本通常类似于 1.0.0-rc.1)这工作正常,然后我们可以将工件传递给 RC 步骤并使用 NuGet 推送将其上传到需要去的地方。

当我们试图将该包从 RC 移动到 GA 时出现问题(所需的流程是:build > RC > GA),我们想采取完全相同的包并修改版本,使其不再具有 RC 标签(将其剥离为 1.0.0),但是我无法找到一种干净的方法来做这个。当前的解决方法是采用完全相同的提交并使用 GA 版本重建它,但我们更愿意只修改 RC 版本以获得正确的版本号。

是否有 NuGet 命令或我缺少的东西来完成此操作?我考虑过下载 nupkg 文件,将其安装到输出目录,然后用正确的版本重新打包,但我希望有更好的方法。

几个选项使用 Action Update Helpers

the diff. is helpful depending on what you are publishing, nuget libs you are publishing vs. custom libs - since you did not share your sample yaml/code, I am sharing both.


Option 1: use the Release Tag Updater helper lib. from here or a newer one here from Github or Market Place

对您自己有帮助,即如果您发布 NUGET 库

在 github 操作的 yaml 配置文件中,在您要重命名的阶段,您可以使用带有传入值的标签选项

# Filepath of the project to be packaged, relative to root of repository
PROJECT_FILE_PATH: YourProject/YourProject.csproj
          
# NuGet package id, used for version detection & defaults to project name
# PACKAGE_NAME: YourProject

# API key to authenticate with NuGet server
NUGET_KEY: ${{secrets.NUGET_API_KEY}}

# NuGet server uri hosting the packages, defaults to https://api.nuget.org
# NUGET_SOURCE: https://api.nuget.org
          
# Filepath with version info, relative to root of repository & defaults to PROJECT_FILE_PATH
# VERSION_FILE_PATH: Directory.Build.props

# Regex pattern to extract version info in a capturing group
# VERSION_REGEX: <Version>(.*)<\/Version>
          
# Useful with external providers like Nerdbank.GitVersioning, ignores VERSION_FILE_PATH & VERSION_REGEX
# VERSION_STATIC: 1.0.0

# Flag to toggle git tagging, enabled by default
# TAG_COMMIT: true

# Format of the git tag, [*] gets replaced with actual version
# TAG_FORMAT: v*

Option 2: Modify/roll your own yaml properties file

恕我直言,您的自定义库,即如果您需要超出标准的东西 yaml properties 并且您还需要更多。

例如在最后的 release 阶段,使用 yaml 部署部分使用此 lib.

将其命名为您想要的名称
   # your previous yaml code ... there should be a section with the below tage configured and it will look for it an update.


主要区别在于一个目标是标记名称的主要和次要版本并且对 Nuget 包有帮助。

第二个允许您创建超出范围的内容并将其自定义为标签。