2

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.

Community
  • 1
  • 1
abatishchev
  • 98,240
  • 88
  • 296
  • 433

1 Answers1

4

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

enter image description here

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

Marina Liu
  • 36,876
  • 5
  • 61
  • 74
  • Hi Marina, thanks for your response, it definitely helps! Few questions, please. When I used the built-in pack command it passes the version properly, e.g. `-version 1.0.94.0`. But when I use `-Version $(Build.BuildNumber)` it becomes `-Version MyProject-Daily_1.0.94.0` what of course doesn't work. What is the variable the built-in command uses? – abatishchev Aug 10 '17 at 19:28
  • Also do I understand correctly that custom command doesn't support wildcard path, it needs one nuspec at a time? – abatishchev Aug 10 '17 at 20:16
  • I added the method to use the version like `1.0.94.0` for nuget packages, you can find it in the end of my answer. And yes, the custom commands doesn't support wildcards. – Marina Liu Aug 11 '17 at 03:50
  • Oh, bummer. That's a showstopper for us then. We have several projects within single repo ("shared") and single build/release definitions we'd like to pack. Creating separate step for each would be too much hassle. – abatishchev Aug 13 '17 at 04:41