Add build number to package version with `dotnet pack` in VSTS Build process

大兔子大兔子 提交于 2019-12-05 10:14:46

First you can select Use an environment variable for Automatic package versioning, use your defined variable such as temp ($(build.buildNumber)) as Environment variable.

More details take a look at this link: Dotnet pack automatic package versioning build number clarification

Another way is using the "arguments" field in the dotnet CLI task, you can pass additional arguments to the dotnet cli.

Using --version-suffix $(Build.BuildNumber) will pass the build number as version suffix. Make sure you don't have a <version> element set in your csproj, but rather a <versionprefix> element. The built version will look like versionprefix-versionsuffix, so for example, if you have <versionprefix>1.2.3</versionprefix> and build number 201805002, the built version will be 1.2.3-201805002. In this case do not select the automatic package versioning.

Thanks to @patricklu-msft for his suggestions.

There is it appears no built-in way to emulate the wildcard behaviour we previously had NUGET pack with dotnet pack, nor was there way to get the <Version> tag out of the project file.

So I've created a new VSTS Build task that does this: VersionTaskReader in the MarketPlace.

This extension can be pointed to a .csproj or .vbproj and will set an environment variable VERSION, and VERSION_BUILD which has the BUILDID appended. You can optionally add a prefix to make each instance different if needed.

For example, if your project contains <Version>1.1</Version> then the VERSION_BUILD would be something like 1.1.8680

Then the dotnet pack task can use the environment variable VERSION_BUILD in the versioning options screen, so that the build number automatically increments.

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