32

Setting up a simple class library to build and publish to VSTS's own feed, I see this error when the NuGet package runs.

Could not find version number data in BUILD_BUILDNUMBER

I have the "Use Build number to version package" option ticked. Expected VSTS to just work.

knocte
  • 16,941
  • 11
  • 79
  • 125
Luke Puplett
  • 42,091
  • 47
  • 181
  • 266

4 Answers4

40

The tip for "Use Build number to version package" states:

Will use the build number to version you package. Under General set the build format to be '$(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)'

Following this did get me past this issue (and on to a new one).

Default value:

[Default value]

Correct Value:

[Correct Value]

Frank V
  • 25,141
  • 34
  • 106
  • 144
  • Was the new issue anything to do with paths too long? How did you fix it? – Joel B Feb 24 '17 at 03:22
  • I figured min out, I was using a glob pattern to locate my `.nuspec` file for a Node.js project and the `node_modules` folder was creating paths far too long for Window's liking. Hardcoded the path to the `.nuspec` and that fixed it. Thanks for your answer. Got me to my next problem! – Joel B Feb 25 '17 at 17:47
  • 6
    note that the Build number format option is now under the "Options" tab – tster Jun 07 '17 at 18:28
  • 4
    you can do this in yaml by adding : `name: $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)` – Justin Moore Oct 01 '18 at 16:55
9

This is because your build number does not match the regex in "Nuget Packager" step. Following is the regex that nuget packager task used to find the build number. You can set your build number format base on this. General, the format like 1.2.3 or 1.2.3.4 would work.

Write-Verbose "Autoversion: Getting version number from build"
##Get Version from Build

# Regular expression pattern to find the version in the build number 
# and then apply it to the assemblies
$VersionRegex = "\d+\.\d+\.\d+(?:\.\d+)?"
Eddie Chen - MSFT
  • 29,708
  • 2
  • 46
  • 60
1

If what you want is the major.minor.patch.unique-to-build then you use the Use the date and time option.

In yaml, the equivalent is

- task: NuGetCommand@2
  displayName: Pack
  inputs:
    command: 'pack'
    packagesToPack: '**/*.csproj'
    versioningScheme: 'byPrereleaseNumber'
    majorVersion: '1'
    minorVersion: '0'
    patchVersion: '0'
farlee2121
  • 2,959
  • 4
  • 29
  • 41
0

I had a variable in my .nuspec file:

<tags>Build#$build$</tags>

that was incorrectly parameterized in the package build step. With the package step open in the build editor, I expanded the 'Advanced' section added to 'Additional Build Properties' this text

build=$(Build.BuildNumber)
sirdank
  • 3,351
  • 3
  • 25
  • 58