C#/.NET - 如何特别是通过 CI 自动生成和增加包版本? [英] C#/.NET - How to generate and increase package version automatically especially via CI?

查看:35
本文介绍了C#/.NET - 如何特别是通过 CI 自动生成和增加包版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个作为 NuGet 库包构建的 Visual Studio 项目.但是每次发布包,都得手动修改版本号.这是一项容易出错的工作.我想自动生成和增加包版本号.

I have a Visual Studio project which is built as a NuGet lib package. But every time I publish the package, I have to change the version number manually. That's a prone-to-error work. I'd like to generate and increase the package version number automatically.

我找到了 GitVersion 工具 来解决这个问题.而且我还找了一些语义版本控制博客来解释持续交付的包版本.

I found GitVersion tool to solve this problem. And I also found some semantic versioning blogs to explain the package version of continuous delivery.

但不幸的是,GitVersion 包对我来说无法正常工作.

But unfortunately, The GitVersion package does not work correctly for me.

  • 它给了我一个错误,即 AssemblyVersionAttribute 重复.
  • 如果我将 添加到 csproj 文件中,它将什么也不做,包版本将为 0.0.0.0.
  • It gives me an error that AssemblyVersionAttribute is duplicated.
  • If I add <GenerateAssemblyInfo>false</GenerateAssemblyInfo> into the csproj file, It will do nothing and the package version will be 0.0.0.0.

也许是因为我使用的是新的 csproj 格式.请参阅此处以查看csproj 文件,该文件如下所示:

Maybe the reason is that I'm using the new csproj format. See here to view the csproj file and the file looks like this:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <TargetFrameworks>net45;net47;netstandard2.0</TargetFrameworks>
  </PropertyGroup>
</Project>

感谢任何回复.

更新:

我发现有个问题需要提及我的问题:Gitversion Task for VS2017-style csproj ·问题 #1349 · GitTools/GitVersion.我正在尝试新的解决方案.

I find that there is an issue to mention my problem: Gitversion Task for VS2017-style csproj · Issue #1349 · GitTools/GitVersion. I'm trying the new solution.

推荐答案

不确定 Jenkins,但它应该能够自己生成增量数字或时间戳,可以通过构建管道上的环境变量访问.

Not sure about Jenkins, but it should be able to generate an incremental number or timestamp by itself that can be accessed via an environment variable on your build pipeline.

我认为最灵活的方法是将带有占位符的 PackageVersion 标记添加到您的 csproj 中,然后您的构建管道可以更改:

I think the most flexible way is to add a PackageVersion tag with a placeholder to your csproj that your build pipeline can then change:

  <PropertyGroup>
    <GeneratePackageOnBuild>True</GeneratePackageOnBuild>
    <PackageVersion>$(PackageVersion)</PackageVersion>
  </PropertyGroup>

因此,在您的构建管道中,您只需传递版本,例如:

So, on your build pipeline, you just pass the version, for example:

dotnet build -p:PackageVersion=$(BUILD_TIMESTAMP)

这篇关于C#/.NET - 如何特别是通过 CI 自动生成和增加包版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆