NuGet task
Version 2.* | Other versions
Azure Pipelines | TFS 2018
Use this task in a build or release pipeline to install and update NuGet package dependencies, or package and publish NuGet packages.
Note
In Microsoft Team Foundation Server (TFS) 2018 and previous versions, build and release pipelines are called definitions, service connections are called service endpoints, stages are called environments, and jobs are called phases.
If your code depends on NuGet packages, make sure to add this step before your Visual Studio Build step. Also make sure to clear the deprecated Restore NuGet Packages checkbox in that step.
Tip
Looking for help to get started? See the how-tos for restoring and publishing packages.
Tip
This version of the NuGet task uses NuGet 4.1.0 by default. To select a different version of NuGet, use the Tool Installer.
Note
Using or creating .NET Core or .NET Standard packages? Use the .NET Core task, which has full support for all package scenarios currently supported by dotnet, including restore, pack, and nuget push.
YAML snippet
# NuGet
# Restore, pack, or push NuGet packages, or run a NuGet command. Supports NuGet.org and authenticated feeds like Package Management and MyGet. Uses NuGet.exe and works with .NET Framework apps. For .NET Core and .NET Standard apps, use the .NET Core task.
- task: NuGetCommand@2
inputs:
#command: 'restore' # Options: restore, pack, push, custom
#restoreSolution: '**/*.sln' # Required when command == Restore
#feedsToUse: 'select' # Options: select, config
#vstsFeed: # Required when feedsToUse == Select
#includeNuGetOrg: true # Required when feedsToUse == Select
#nugetConfigPath: # Required when feedsToUse == Config
#externalFeedCredentials: # Optional
#noCache: false
#disableParallelProcessing: false
restoreDirectory:
#verbosityRestore: 'Detailed' # Options: quiet, normal, detailed
#packagesToPush: '$(Build.ArtifactStagingDirectory)/**/*.nupkg;!$(Build.ArtifactStagingDirectory)/**/*.symbols.nupkg' # Required when command == Push
#nuGetFeedType: 'internal' # Required when command == Push# Options: internal, external
#publishVstsFeed: # Required when command == Push && NuGetFeedType == Internal
#publishPackageMetadata: true # Optional
#allowPackageConflicts: # Optional
#publishFeedCredentials: # Required when command == Push && NuGetFeedType == External
#verbosityPush: 'Detailed' # Options: quiet, normal, detailed
#packagesToPack: '**/*.csproj' # Required when command == Pack
#configuration: '$(BuildConfiguration)' # Optional
#packDestination: '$(Build.ArtifactStagingDirectory)' # Optional
#versioningScheme: 'off' # Options: off, byPrereleaseNumber, byEnvVar, byBuildNumber
#includeReferencedProjects: false # Optional
#versionEnvVar: # Required when versioningScheme == ByEnvVar
#majorVersion: '1' # Required when versioningScheme == ByPrereleaseNumber
#minorVersion: '0' # Required when versioningScheme == ByPrereleaseNumber
#patchVersion: '0' # Required when versioningScheme == ByPrereleaseNumber
#packTimezone: 'utc' # Required when versioningScheme == ByPrereleaseNumber# Options: utc, local
#includeSymbols: false # Optional
#toolPackage: # Optional
#buildProperties: # Optional
#basePath: # Optional
#verbosityPack: 'Detailed' # Options: quiet, normal, detailed
#arguments: # Required when command == Custom
Versioning schemes
For byPrereleaseNumber, the version will be set to whatever you choose for major, minor, and patch, plus the date and time in the format yyyymmdd-hhmmss
.
For byEnvVar, the version will be set as whatever environment variable, e.g. MyVersion
(no $, just the environment variable name), you provide. Make sure the environment variable is set to a proper SemVer e.g. 1.2.3
or 1.2.3-beta1
.
For byBuildNumber, the version will be set to the build number, ensure that your build number is a proper SemVer e.g. 1.0.$(Rev:r)
. If you select byBuildNumber, the task will extract a dotted version, 1.2.3.4
and use only that, dropping any label. To use the build number as is, you should use byEnvVar as described above, and set the environment variable to BUILD_BUILDNUMBER
.
Restore NuGet packages
Demands
None
Arguments
Argument | Description |
---|---|
Path to solution, packages.config, or project.json | Copy the Solution argument in your Visual Studio Build step and paste it here, or create a link using the Link button in the information panel. |
Feeds and authentication | |
Feeds to use |
Feed(s) I select here:
|
Advanced | |
Disable local cache | Prevents NuGet from using packages from local machine caches. |
Destination directory | Specifies the folder in which packages are installed. If no folder is specified, packages are restored into a packages/ folder alongside the selected solution, packages.config, or project.json. |
Verbosity | Specifies the amount of detail displayed in the output. |
Control options |
Examples
Install NuGet dependencies
You're building a Visual Studio solution that depends on a NuGet feed.
`-- ConsoleApplication1
|-- ConsoleApplication1.sln
|-- NuGet.config
`-- ConsoleApplication1
|-- ConsoleApplication1.csproj
Build steps
![]() Package: NuGet |
Install your NuGet package dependencies.
|
![]() Build: Visual Studio Build |
Build your solution.
|
Pack NuGet packages
Demands
None
Arguments
Argument | Description |
---|---|
Path to csproj or nuspec file(s) to pack |
Specify .csproj files (for example, **\*.csproj ) for simple projects. In this case:
**\*.nuspec ) for more complex projects, such as multi-platform scenarios in which you need to compile and package in separate steps. In this case:
-: , use ! instead.
|
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 or $(BuildConfiguration)
|
Package folder |
(Optional) Specify the folder where you want to put the packages. You can use a variable such as $(Build.ArtifactStagingDirectory) If you leave it empty, the package will be created in the root of your source tree.
|
Pack options | |
Automatic package versioning | This blog post provides an overview of the automatic package versioning available here. |
Advanced | |
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.
|
Verbosity | Specifies the amount of detail displayed in the output. |
Control options |
Push NuGet packages
Demands
None
Arguments
Argument | Description |
---|---|
Path to NuGet package(s) to publish |
Specify the packages you want to publish.
|
Target feed location |
|
Advanced | |
Verbosity | Specifies the amount of detail displayed in the output. |
Control options |
Publishing symbols
When you push packages to an Azure Artifacts/Package Management feed, you can also publish symbols using the Index Sources & Publish Symbols task.
Publishing packages to TFS with IIS Basic authentication enabled
This task is unable to publish NuGet packages to a TFS Package Management feed that is running on a TFS server with IIS Basic authentication enabled. See here for more details.
Custom NuGet command
YAML snippet
# NuGet Command
# Deprecated: use the “NuGet” task instead. It works with the new Tool Installer framework so you can easily use new versions of NuGet without waiting for a task update, provides better support for authenticated feeds outside this organization/collection, and uses NuGet 4 by default.
- task: NuGet@0
inputs:
command:
arguments:
Arguments
Argument | Description |
---|---|
Command and arguments | NuGet command and arguments you want to pass as your custom command. |
End-to-end example
You want to package and publish some projects in a C# class library to your Azure Artifacts feed.
You want to package and publish some projects in a C# class library to your TFS Package Management 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
Publish to a TFS feed
- Make sure you've prepared the build as described above.
- If you haven't already, create a feed.
- Add the following build steps:
![]() Package: NuGet |
Install your NuGet package dependencies.
|
![]() Build: Visual Studio Build |
Build your solution.
|
![]() Package: NuGet |
Package your projects.
|
![]() Package: NuGet |
Publish your packages.
|
Option 2: publish to NuGet.org
- Make sure you've prepared the build as described above.
- If you haven't already, register with NuGet.org.
- Use the steps in the previous section, but substitute the final step for the step shown here.
![]() Package: NuGet |
Publish your packages to NuGet.org.
|
Task versions
Task: NuGet (formerly NuGet Restore at 1.*, NuGet Installer at 0.*)
Task version | Azure Pipelines | TFS |
---|---|---|
2.* | Available | Appeared in 2018 |
1.* | Deprecated but available | Appeared in 2017 Update 2, deprecated in 2018 |
0.* | Deprecated but available | Appeared in 2017, deprecated in 2017 Update 2 |
Task: NuGet Packager
Task version | Azure Pipelines | TFS |
---|---|---|
0.* | Deprecated but available | Available in TFS < 2018, deprecated in TFS >= 2018 |
Task: NuGet Publisher
Task version | Azure Pipelines | TFS |
---|---|---|
0.* | Deprecated but available | Available in TFS < 2018, deprecated in TFS >= 2018 |
Task: NuGet Command
Task version | Azure Pipelines | TFS |
---|---|---|
0.* | Deprecated but available | Available in TFS < 2017 Update 2, deprecated in TFS >= 2018 |
Open source
These tasks are open source on GitHub. Feedback and contributions are welcome.
Q & A
Why should I check in a NuGet.Config?
Checking a NuGet.Config into source control ensures that a key piece of information needed to build your project-the location of its packages-is available to every developer that checks out your code.
However, for situations where a team of developers works on a large range of projects, it's also possible to add an Azure Artifacts feed to the global NuGet.Config on each developer's machine. In these situations, using the "Feeds I select here" option in the NuGet task replicates this configuration.
Where can I learn about Azure Artifacts?
Package Management in Azure Artifacts and TFS
Where can I learn more about NuGet?
NuGet Docs Overview
NuGet Create Packaging and publishing
NuGet Consume Setting up a solution to get dependencies
What other kinds of apps can I build?
What other kinds of build tasks are available?
How do we protect our codebase from build breaks?
Git: Improve code quality with branch policies with an option to require that code builds before it can be merged to a branch. For GitHub repositories, similar policies are available in GitHub's repository settings under Branches.
TFVC: Use gated check-in.
How do I modify other parts of my build pipeline?
Specify your build tasks to run tests, scripts, and a wide range of other processes.
Specify build options such as specifying how completed builds are named, building multiple configurations, creating work items on failure.
Specify the repository to pick the source of the build and modify options such as how the agent workspace is cleaned.
Set build triggers to modify how your CI builds run and to specify scheduled builds.
Specify build retention policies to automatically delete old builds.
I selected parallel multi-configuration, but only one build is running at a time.
If you're using Azure Pipelines, you might need more parallel jobs. See Parallel jobs in Azure Pipelines.
How do I see what has changed in my build pipeline?
View the change history of your build pipeline
Do I need an agent?
You need at least one agent to run your build or release. Get an agent for Linux, macOS, or Windows.
I can't select a default agent pool and I can't queue my build or release. How do I fix this?
See Agent pools.
I use TFS on-premises and I don't see some of these features. Why not?
Some of these features are available only on Azure Pipelines and not yet available on-premises. Some features are available on-premises if you have upgraded to the latest version of TFS.
Feedback
We'd love to hear your thoughts. Choose the type you'd like to provide:
Our feedback system is built on GitHub Issues. Read more on our blog.
Loading feedback...