Johnny Cash
Johnny Cash

Reputation: 21

VSTS Build/AzureDevOps - nupkg file name does not contain the version in unspecified file

I am using Nuget Packager task step to get the nupkg file out of my csproj, and my .nuspec file contains the version number:

<version>1.1.2<version>

However, the resulting file only contains my build name, and has random numbers attached to it. For instance: MyProject.0.0.7416.19926.nupkg.

Automatic Package versioning option is turned off because I assumed the version would be used from the .nuspec file. I've also included YAML definition for the Nuget packager.

{
      "enabled": true,
      "continueOnError": false,
      "alwaysRun": false,
      "displayName": "NuGet Packager ",
      "timeoutInMinutes": 0,
      "condition": "succeeded()",
      "task": {
        "id": "333b11bd-d341-40d9-afcf-b32d5ce6f24b",
        "versionSpec": "0.*",
        "definitionType": "task"
      },
      "inputs": {
        "searchPattern": "$/...csproj",
        "outputdir": "$(Build.StagingDirectory)\\packages",
        "includeReferencedProjects": "false",
        "versionByBuild": "false",
        "versionEnvVar": "Version",
        "requestedMajorVersion": "1",
        "requestedMinorVersion": "0",
        "requestedPatchVersion": "0",
        "configurationToPack": "$(BuildConfiguration)",
        "buildProperties": "",
        "nuGetAdditionalArgs": "",
        "nuGetPath": "$(System.DefaultWorkingDirectory)\\build\\nuget.exe"
      }
    }

I'm using a new version for nugget.exe thats why the path in nuGetPath.

Upvotes: 0

Views: 156

Answers (1)

Krzysztof Madej
Krzysztof Madej

Reputation: 40543

Since Nuget Packager task is deprecated I would recommend you use DotNetCoreCLI@2. You need to decalre nuspec file in csproj

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFramework>netstandard2.0</TargetFramework>
    <NuspecFile>package.nuspec</NuspecFile>
  </PropertyGroup>

</Project>

here is my nuspec file:

<?xml version="1.0" encoding="utf-8"?>
<package xmlns="http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd">
    <metadata>
        <!-- Required elements-->
        <id>UniqeName</id>
        <version>1.1.2</version>
        <description>UniqueName</description>
        <authors>Krzysztof Madej</authors>

        <!-- Optional elements -->
        <!-- ... -->
    </metadata>
    <files>
        <file src="bin\Release\netstandard2.0\*" target="lib" />
    </files>
</package>

And with this YAML build definition:

variables:
  buildConfiguration: 'Release'

steps:

- task: DotNetCoreCLI@2
  displayName: "dotnet pack"
  inputs:
    command: 'pack'
    arguments: '--configuration $(buildConfiguration)'
    packagesToPack: '$(System.DefaultWorkingDirectory)/stackoverflow/08-nuget-packager/SampleApp.csproj'
    versioningScheme: 'off'
    outputDir: '$(Build.ArtifactStagingDirectory)'

- bash: ls $(Build.ArtifactStagingDirectory)

You will get in Build.ArtifactStagingDirectory your nuget package with versioning defined in nuspec file.

Since in title you gave a choice to choos between VSTS Build and Azure DevOps I presented solution for Azure DevOps. I'm not sure if this is relevant in any way to VSTS.

Azure DevOps log

Upvotes: 1

Related Questions