title | description | ms.assetid | ms.service | ms.topic | ms.date | monikerRange |
---|---|---|---|---|---|---|
Publish and restore NuGet packages with the NuGet CLI |
How to connect to your feed and publish NuGet packages using the NuGet CLI |
C7D75946-1F00-4BD7-87C8-225BBAE9982B |
azure-devops-artifacts |
conceptual |
04/18/2024 |
<= azure-devops |
[!INCLUDE version-lt-eq-azure-devops]
With Azure Artifacts, you can publish your NuGet packages to both public and private feeds, enabling you to share them with others based on your feed's visibility settings. This article will guide you through connecting to your Azure Artifacts feed and publishing and restoring your NuGet packages.
-
An Azure DevOps organization and a project. Create an organization or a project if you haven't already.
-
An Azure Artifacts feed. Create a new feed if you don't have one already.
-
The latest NuGet version.
::: moniker range="azure-devops"
-
Sign in to your Azure DevOps organization, and then navigate to your project.
-
Select Artifacts, and then select your feed from the dropdown menu.
-
Select Connect to feed, and then select NuGet.exe from the left navigation pane.
-
Add a nuget.config file to your project, in the same folder as your .csproj or .sln file. Paste the provided XML snippet into your file. The snippet should look like the following:
-
Organization-scoped feed:
<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <clear /> <add key="<SOURCE_NAME>" value="https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json" /> </packageSources> </configuration>
-
Project-scoped feed:
<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <clear /> <add key="<SOURCE_NAME>" value="https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json" /> </packageSources> </configuration>
-
::: moniker-end
::: moniker range="azure-devops-2020 || azure-devops-2022"
-
Sign in to your Azure DevOps server, and then navigate to your project.
-
Select Artifacts, and then select your feed.
-
Select Connect to Feed, and then select NuGet.exe from the left navigation pane.
-
Follow the instructions in the Project setup section to connect to your feed.
::: moniker-end
::: moniker range="azure-devops-2019"
-
Sign in to your Azure DevOps server, and then navigate to your project.
-
Select Artifacts, and then select your feed.
-
Select Connect to Feed, and then select NuGet from the left navigation pane.
-
Follow the provided instructions to add your package source URL to your nuget.config file.
::: moniker-end
Run the following command to publish your packages to your feed. Replace the placeholders with the relevant information:
nuget push <PACKAGE_PATH> -src https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json -ApiKey <ANY_STRING>
Example:
nuget push MyPackage.5.0.2.nupkg -src https://pkgs.dev.azure.com/MyOrg/MyProject/_packaging/MyFeed/nuget/v3/index.json -ApiKey AZ
Note
The ApiKey
is required, but you can use any arbitrary value when pushing to Azure Artifacts feeds.
-
Create a personal access token (PAT) with packaging read and write scope.
-
Add your package source to your nuget.config file. This will add your PAT to your nuget.config file. Store this file in a safe location, and make sure that you don't check it into source control.
nuget sources Add -Name <SOURCE_NAME> -Source https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json -UserName <USER_NAME> -Password <PERSONAL_ACCESS_TOKEN> -config <PATH_TO_NUGET_CONFIG_FILE>
-
Publish your NuGet package to your feed:
nuget push <PACKAGE_PATH> -src <SOURCE_NAME> -ApiKey <ANY_STRING>
Example:
nuget sources Add -Name "MySource" -Source https://pkgs.dev.azure.com/MyOrg/MyProject/_packaging/MyFeed/nuget/v3/index.json -UserName MyUserName -Password YourPersonalAccessToken -config ./nuget.config
nuget push nupkgs/mypackage.1.1.8.nupkg -src MySource -ApiKey AZ
Note
If your organization is using a firewall or a proxy server, make sure you allow Azure Artifacts Domain URLs and IP addresses.
Run the following command in your project directory to restore your packages:
nuget.exe restore