How to to produce both release and pre-release packages from one nuspec in VSTS?

狂风中的少年 提交于 2019-12-22 18:02:10

问题


Currently my build produces both packages having a newer version every time:

Release: Automatic package versioning = Use the build number
Pre-release: Additional build properties = Version=$(user.BuildFullVersion)-beta

And the only one nuspec has a placeholder to version:

<version>$version$</version>

I want to increment version manually, that it - repetitive build would produce same version until I increment it manually.

How can I achieve that still having single nuspec?

Can I adjust package version in the pack tasks like this:

Release: $(PackageVersion) = $(PackageVersion)
Pre-release: $(PackageVersion) = $(PackageVersion)-beta

Or something similar.


回答1:


To produce two packages by a nuspec, you can use two NuGet tasks (NuGet custom instead NuGet pack):

NuGet task:

Command: custom

Command and arguments:

pack $(Build.SourcesDirectory)\Package.nuspec -Version $(Build.BuildNumber) -OutputDirectory $(build.artifactstagingdirectory)

NuGet task:

Command: custom

Command and arguments:

pack $(Build.SourcesDirectory)\Package.nuspec -Version $(Build.BuildNumber) -Suffix beta -OutputDirectory $(build.artifactstagingdirectory)

If you set the $(Build.BuildNumber) as the format like MyProject-Daily_1.0.94.0 while you want to add the version for nuget package as 1.0.94.0, you can define a variable in your build definition and set the value by cutting the substring of $(Build.BuildNumber). detail steps as below:

In Variables Tab, add a variable (such as version) with any value (such as temp).

Add a PowerShell Task before NuGet tasks with the settings,

Type: Inline Script

Inline Script:

$s1=$(Build.BuildNumber).split('_')[1].split(' ')
Write-Host "##vso[task.setvariable variable=version]$s1"

Then in the NuGet Custom tasks use $(version) to replace $(Build.BuildNumber) for -version option. Such as nuget pack -version $(version).



来源:https://stackoverflow.com/questions/45601861/how-to-to-produce-both-release-and-pre-release-packages-from-one-nuspec-in-vsts

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