How to make version autoincrement in the latest .NET Core tooling?

时光总嘲笑我的痴心妄想 提交于 2019-12-04 10:16:23
natemcmaster

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.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!