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

梦想与她 提交于 2019-12-06 06:57:17

问题


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.


回答1:


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.



来源:https://stackoverflow.com/questions/42180137/how-to-make-version-autoincrement-in-the-latest-net-core-tooling

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