Package: NuGet Packager

Last Update: 5/18/2017

Team Services | TFS 2017 | TFS 2015 Update 3 | Previous versions: XAML Build, Release

Create a NuGet package from either a .csproj or .nuspec file.

TIP

Looking for help to get started? See Use Team Build to restore and publish NuGet packages.

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 definition 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 Visual Studio Team Services 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
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.
Control options

Examples

You want to package and publish some projects in a C# class library to your Team Services 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 Visual Studio Team Services

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

Create the feed

See Create a feed.

Build steps

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 Team Services.

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 steps

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: endpoint manage

    1. Click New Service Endpoint, and then click Generic.
    2. On the Add New Generic Connection dialog box:

      • Connection Name: NuGet
      • Server URL: https://nuget.org/
      • User name: {your-name}
      • Password/Token Key: Paste API Key from your NuGet account.

NuGet Publisher Publish your NuGet package to a server and update your feed

NuGet Installer Install and update NuGet package dependencies

Q & A

Where can I learn about Visual Studio Team Services package management?

Package Management in Team Services and TFS

Where can I learn more about NuGet?

NuGet Docs Overview

NuGet Create Packaging and publishing

NuGet Consume Seting up a solution to get dependencies

How do I create a .nuspec file? Where can I learn more about it?

Creating and Publishing a Package

Nuspec Reference

Do I need an agent?

You need at least one agent to run your build or release. Get an agent.

I can't select a default agent queue and I can't queue my build or release. How do I fix this?

See queues.

I use Team Foundation Server on-premises and I don't see some of these features. Why not?

Some of these features are available only on Visual Studio Team Services and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.