NuGet Packager task version 0.*

TFS 2017 | TFS 2015 | TFS 2013

Use this task to create a NuGet package from either a .csproj or .nuspec file.

Demands

None

Arguments

Argument Description
Path/Pattern to nuspec files

Specify .csproj files (for example, ***.csproj) for simple projects. In this case:

  • The packager compiles the .csproj files for packaging.
  • You must specify Configuration to Package (see below).
  • You do not have to check in a .nuspec file. If you do check one in, the packager honors its settings and replaces tokens such as $id$ and $description$.

Specify .nuspec files (for example, *.nuspec) for more complex projects, such as multi-platform scenarios in which you need to compile and package in separate steps. In this case:

  • The packager does not compile the .csproj files for packaging.
  • Each project is packaged only if it has a .nuspec file checked in.
  • The packager does not replace tokens in the .nuspec file (except the <version/> element, see Use build number to version package, below). You must supply values for elements such as <id/> and <description/>. The most common way to do this is to hardcode the values in the .nuspec file.

To package a single file, click the ... button and select the file. To package multiple files, use single-folder wildcards (*) and recursive wildcards (). For example, specify *.csproj to package all .csproj files in all subdirectories in the repo.

You can use multiple patterns separated by a semicolon to create more complex queries. You can negate a pattern by prefixing it with "-:". For example, specify *.csproj;-:***Tests.csproj to package all .csproj files except those ending in 'Tests' in all subdirectories in the repo.

Use build number to version package Select if you want to use the build number to version your package. If you select this option, for the pipeline options, set the build number format to something like $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)

The build number format must be {some_characters}_0.0.0.0. The characters and the underscore character are omitted from the output. The version number at the end must be a unique number in a format such as 0.0.0.0 that is higher than the last published number.

The version number is passed to nuget pack with the -Version option.

Versions are shown prominently on NuGet servers. For example they are listed on the Azure Artifacts feeds page and on the NuGet.org package page.

Package Folder (Optional) Specify the folder where you want to put the packages. You can use a variable such as $(Build.StagingDirectory)\packages

If you leave it empty, the package will be created in the same directory that contains the .csproj or .nuspec file.

Advanced options

Argument Description
Configuration to Package If you are packaging a .csproj file, you must specify a configuration that you are building and that you want to package. For example: Release
Additional build properties Semicolon delimited list of properties used to build the package. For example, you could replace <description>$description$</description> in the .nuspec file this way: Description="This is a great package"

Using this argument is equivalent to supplying properties from nuget pack with the -Properties option.

NuGet Arguments (Optional) Additional arguments passed nuget pack.
Path to NuGet.exe (Optional) Path to your own instance of NuGet.exe. If you specify this argument, you must have your own strategy to handle authentication.

Task control options

Examples

You want to package and publish some projects in a C# class library to your Azure Artifacts feed.

`-- Message
    |-- Message.sln
    `-- ShortGreeting
        |-- ShortGreeting.csproj
        |-- Class1.cs
        `-- Properties
            |-- AssemblyInfo.cs
    `-- LongGreeting
        |-- LongGreeting.csproj
        |-- Class1.cs
        `-- Properties
            |-- AssemblyInfo.cs

Prepare

AssemblyInfo.cs

Make sure your AssemblyInfo.cs files contain the information you want shown in your packages. For example, AssemblyCompanyAttribute will be shown as the author, and AssemblyDescriptionAttribute will be shown as the description.

Variables tab

Name Value
$(BuildConfiguration) release
$(BuildPlatform) any cpu

Options

Setting Value
Build number format $(BuildDefinitionName)_$(Year:yyyy).$(Month).$(DayOfMonth)$(Rev:.r)

Publish to Azure Artifacts

Make sure you've prepared the build as described above.

Create the feed

See Create a feed.

Build tasks

Build: Visual Studio Build


Build: Visual Studio Build

Build your solution.

  • Solution: *.sln
  • Platform: $(BuildPlatform)
  • Configuration: $(BuildConfiguration)
Package: NuGet Packager


Package: NuGet Packager

Package your projects.

  • Path/Pattern to nuspec files: *.csproj
  • Use Build number to version package: Selected
  • Advanced, Configuration to Package: Release
Package: NuGet Publisher


Package: NuGet Publisher

Publish your packages to Azure Artifacts.

Publish to NuGet.org

Make sure you've prepared the build as described above.

Register with NuGet.org

If you haven't already, register with NuGet.org.

Build tasks

Build: Visual Studio Build


Build: Visual Studio Build

Build your solution.

  • Solution: *.sln
  • Platform: $(BuildPlatform)
  • Configuration: $(BuildConfiguration)
Package: NuGet Packager


Package: NuGet Packager

Package your projects.

  • Path/Pattern to nuspec files: *.csproj
  • Use Build number to version package: Selected
  • Advanced, Configuration to Package: Release
Package: NuGet Publisher


Package: NuGet Publisher

Publish your packages to NuGet.org.

  • Path/Pattern to nupkg: ***.nupkg
  • Feed type: External NuGet Feed
  • NuGet Server Endpoint:

    1. Click "New service connection", and then click Generic.
    2. On the Add New Generic Connection dialog box: