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

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

问题描述

我有一个Visual Studio项目,它是作为NuGet lib软件包构建的。但是,每次发布软件包时,都必须手动更改版本号。这是容易出错的工作。
我想自动生成并增加软件包的版本号。

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.

  • GitTools/GitVersion: Easy Semantic Versioning (http://semver.org) for projects using Git
  • GitVersion Documentation
  • Versioning NuGet packages in a continuous delivery world: part 1 – Microsoft DevOps Blog
  • Versioning NuGet packages in a continuous delivery world: part 2 – Microsoft DevOps Blog
  • Versioning NuGet packages in a continuous delivery world: part 3 – Microsoft DevOps Blog

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

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


  • 给我一个错误,即AssemblyVersionAttribute是重复的。

  • 如果我添加< GenerateAssemblyInfo> false< / GenerateAssemblyInfo> 到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>

任何答复都会受到赞赏。

Any reply is appreciated.

更新

我发现有一个问题要提及我的问题:用于VS2017风格的csproj的Gitversion任务·版本#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天全站免登陆