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

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

问题描述

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

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.

推荐答案

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

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

但是,使用 MSBuild,您可以通过其他方式计算版本.没有一种正确的方法可以做到这一点,但这是一种方法.我们改用VersionPrefix".Microsoft.NET.Sdk 也会自动结合 VersionPrefix 和 VersionSuffix 形成Version"的最终值.

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".

在文件中:

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

在构建服务器上:

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

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

结果:

AssemblyVersion = 2.0.0.0
Package version = 2.0.0-build00123

我们的构建服务器在每次运行时生成构建号.

Our build server generates the build number on each run.

如果您想使用老式的 AssemblyVersion 星号形式,您可以在 MSBuild 中显式设置 属性.如果不是,则默认为 的major.minor.patch 值.

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>.

更多详情:

Microsoft.NET.Sdk 中有六个版本"设置.请参阅 什么是各种 MSBuild 版本属性(例如 Version、VersionPrefix 和 VersionSuffix)之间的区别? 了解更多详情.

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天全站免登陆