title | description | ms.assetid | ms.service | ms.custom | ms.topic | ms.date | monikerRange | recommendations |
---|---|---|---|---|---|---|---|---|
Publish and restore packages with dotnet CLI |
How to connect to a feed and use the dotnet CLI to publish and restore NuGet packages |
CA2DCB9D-93FB-4E2D-B953-BF78D5687B35 |
azure-devops-artifacts |
devx-track-dotnet |
conceptual |
06/28/2022 |
<= azure-devops |
true |
[!INCLUDE version-lt-eq-azure-devops]
With Azure Artifacts, you can publish and restore your NuGet packages to/from your feed and share them with others based on your feed's visibility settings. This article will guide you through setting up your project to publish and restore your packages using the dotnet command-line interface.
-
An Azure DevOps organization. Create an organization, if you don't have one already.
-
An Azure Artifacts feed. Create a new feed if you don't have one already.
-
Download and install .NET SDK.
::: moniker range=">= azure-devops-2019"
-
Select Artifacts, and then select your feed from the dropdown menu.
-
Select Connect to feed.
:::image type="content" source="../media/connect-to-feed-azure-devops-newnav.png" alt-text="Screenshot showing how to connect to a feed.":::
-
Select dotnet from the NuGet section.
-
Create a nuget.config file in the same folder as your .csproj or .sln file. Copy the following XML snippet and paste it into your new file:
-
Organization-scoped feed:
<?xml version="1.0" encoding="utf-8"?> <configuration> <packageSources> <clear /> <add key="<FEED_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="<FEED_NAME>" value="https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json" /> </packageSources> </configuration>
::: moniker-end
::: moniker range="tfs-2018"
-
Select Build and Release > Packages.
-
Select your feed from the dropdown menu or create one if you haven't.
-
Select Connect to feed.
:::image type="content" source="../media/connect-to-feed.png" alt-text="A screenshot showing how to connect to a feed in TFS.":::
-
Select NuGet and follow the instruction to connect to your feed.
::: moniker-end
To publish a package to your feed, run the following command in an elevated command prompt. Replace the placeholders with the appropriate information:
dotnet nuget push <PACKAGE_PATH> --source https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json --api-key <ANY_STRING>
Note
The api-key
is only used as a placeholder.
-
Example:
dotnet nuget push MyPackage.5.0.2.nupkg --source https://pkgs.dev.azure.com/MyOrg/MyProject/_packaging/MyFeed/nuget/v3/index.json --api-key AZ
-
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. Make sure to store this file in a safe place, and do not check this file into source control.
dotnet nuget add source https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json --name <SOURCE_NAME> --username <USER_NAME> --password <PERSONAL_ACCESS_TOKEN> --configfile <PATH_TO_NUGET_CONFIG_FILE>
-
Publish your package:
dotnet nuget push <PACKAGE_PATH> --source <SOURCE_NAME> --api-key <ANY_STRING>
-
Example:
dotnet nuget add source https://pkgs.dev.azure.com/MyOrg/MyProject/_packaging/MyFeed/nuget/v3/index.json --name MySource --username MyUserName --password MyPersonalAccessToken --configfile ./nuget.config dotnet nuget push nupkgs/mypackage.1.1.0.nupkg --source MySource --api-key AZ
Note
If your organization is using a firewall or a proxy server, make sure you allow Azure Artifacts Domain URLs and IP addresses.
To restore your packages, run the following command in an elevated command prompt. The --interactive
flag is used to prompt the user for credentials.
dotnet restore --interactive