如何在最新的.NET Core工具中使版本自动递增? [英] How to make version autoincrement in the latest .NET Core tooling?

查看:474
本文介绍了如何在最新的.NET Core工具中使版本自动递增?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用最新的(截至今天).NET Core工具。在此处,您可以在< Version>中指定版本。 MSBuild属性。但是,与[assembly:AssemblyVersion]不同,它似乎不支持通配符。如何以相同的方式自动使版本递增?



解释为什么这是一个坏主意,应该怎么做也将是一个很好的答案。

p>

解决方案

MSBuild中的Version属性不像project.json那样支持星号(通配符)格式。



但是,使用MSBuild,您可以通过其他方式计算版本。没有正确的方法来执行此操作,但是这是一种方法。我们改用 VersionPrefix。 Microsoft.NET.Sdk还将自动将VersionPrefix和VersionSuffix组合在一起以形成版本的最终值。



在文件中:

 < PropertyGroup> 
< VersionPrefix> 2.0.0< / VersionPrefix>
< / PropertyGroup>

在构建服务器上:

  msbuild.exe / t:Pack / p:VersionSuffix = build00123 

// //相当于dotnet.exe
dotnet pack --version-suffix build00123

结果:

  AssemblyVersion = 2.0.0.0 
软件包版本= 2.0.0-build00123

我们的构建服务器会在每次运行时生成内部版本号。



如果要使用老式的AssemblyVersion星号形式,可以显式设置 &Build;< AssemblyVersion> 属性。如果不是,则默认为major.minor.patch值< Version>



更多详细信息:



Microsoft.NET.Sdk中有六个版本设置。请参阅什么是
这样的MSBuild版本属性之间的区别,例如Version,VersionPrefix和VersionSuffix?。

I am using the latest (as of today) .NET Core tooling. There, you specify version in an <Version> MSBuild property. However, unlike [assembly:AssemblyVersion], this does not appear to support wildcards. How do I make version increment automatically in the same way?

Explaining why this is a bad idea, and what should be done instead would also be a good answer.

解决方案

The Version property in MSBuild does not support asterisks (wildcard) format as project.json did.

However, with MSBuild you can compute a version in other ways. There is no one right way to do it, but here is one approach. We use "VersionPrefix" instead. Microsoft.NET.Sdk will also automatically combine VersionPrefix and VersionSuffix to form the final value of "Version".

In file:

<PropertyGroup>
  <VersionPrefix>2.0.0</VersionPrefix>
</PropertyGroup>

On build server:

msbuild.exe /t:Pack /p:VersionSuffix=build00123 

// or, the dotnet.exe equivalent
dotnet pack --version-suffix build00123

Result:

AssemblyVersion = 2.0.0.0
Package version = 2.0.0-build00123

Our build server generates the build number on each run.

If you want to use the old-school AssemblyVersion asterisk form, you can explicitly set the <AssemblyVersion> property in MSBuild. If not, this defaults to the major.minor.patch value of <Version>.

More details:

There are half-a-dozen "version" settings in Microsoft.NET.Sdk. See What is the difference between various MSBuild version properties, such as Version, VersionPrefix, and VersionSuffix? for more details.

这篇关于如何在最新的.NET Core工具中使版本自动递增?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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