|
1 | 1 | ---
|
2 |
| -title: Publish and restore NuGet packages with dotnet CLI |
3 |
| -description: How to connect to a feed and use the dotnet CLI to publish and restore NuGet packages. |
| 2 | +title: Publish NuGet packages with dotnet CLI |
| 3 | +description: Learn how to connect to a feed and use the dotnet CLI to publish NuGet packages. |
4 | 4 | ms.assetid: CA2DCB9D-93FB-4E2D-B953-BF78D5687B35
|
5 | 5 | ms.service: azure-devops-artifacts
|
6 | 6 | ms.custom: devx-track-dotnet
|
7 |
| -ms.topic: conceptual |
8 |
| -ms.date: 04/17/2024 |
| 7 | +ms.topic: tutorial |
| 8 | +ms.date: 01/13/2025 |
9 | 9 | monikerRange: '>= azure-devops-2020'
|
10 |
| -"recommendations": "true" |
11 | 10 | ---
|
12 | 11 |
|
13 |
| -# Publish and restore NuGet packages from the command line (dotnet) |
| 12 | +# Publish NuGet packages from the command line (dotnet) |
14 | 13 |
|
15 | 14 | [!INCLUDE [version-lt-eq-azure-devops](../../includes/version-lt-eq-azure-devops.md)]
|
16 | 15 |
|
17 |
| -Azure Artifacts enables you to publish and restore your NuGet packages to and from your feed, allowing you to share them with others according to your feed's visibility settings. This guide walks you through configuring your project to publish or restore packages using the dotnet command-line interface. |
| 16 | +This guide walks you through configuring your project to publish NuGet packages using the dotnet command-line interface. |
18 | 17 |
|
19 | 18 | ## Prerequisites
|
20 | 19 |
|
21 |
| -- An Azure DevOps organization and a project. Create an [organization](../../organizations/accounts/create-organization.md) or a [project](../../organizations/projects/create-project.md#create-a-project) if you haven't already. |
| 20 | +| **Product** | **Requirements** | |
| 21 | +|--------------------|-----------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------| |
| 22 | +| **Azure DevOps** | - An Azure DevOps [organization](../../organizations/accounts/create-organization.md).<br>- An Azure DevOps [project](../../organizations/projects/create-project.md).<br> - An Azure Artifacts [feed](../get-started-nuget.md#create-feed).<br> - Download and install the [Azure Artifacts Credential Provider](https://github.com/microsoft/artifacts-credprovider).<br> - Download and install [.NET Core SDK (2.1.400+)](https://dotnet.microsoft.com/en-us/download). | |
22 | 23 |
|
23 |
| -- An Azure Artifacts feed. [Create a new feed](../get-started-nuget.md#create-feed) if you don't have one already. |
24 |
| - |
25 |
| -- Download and install the [Azure Artifacts Credential Provider](https://github.com/microsoft/artifacts-credprovider). |
26 |
| - |
27 |
| -- Download and install [.NET Core SDK (2.1.400+)](https://dotnet.microsoft.com/en-us/download). |
28 |
| - |
29 |
| -## Connect to feed |
| 24 | +## Connect to a feed |
30 | 25 |
|
31 | 26 | ::: moniker range="azure-devops"
|
32 | 27 |
|
| 28 | +1. Sign in to your Azure DevOps organization, and then navigate to your project. |
| 29 | + |
33 | 30 | 1. Select **Artifacts**, and then select your feed from the dropdown menu.
|
34 | 31 |
|
35 | 32 | 1. Select **Connect to feed**, and then select **dotnet** from the *NuGet* section on the left.
|
@@ -78,52 +75,56 @@ Azure Artifacts enables you to publish and restore your NuGet packages to and fr
|
78 | 75 |
|
79 | 76 | ::: moniker-end
|
80 | 77 |
|
81 |
| -## Publish packages |
| 78 | +## Publish packages to a feed in the same organization |
82 | 79 |
|
83 |
| -Run the following command to publish a package to your feed. Replace the placeholders with the appropriate information: |
| 80 | +Run the following command to publish a package to your feed. Replace the placeholders with the appropriate values: |
84 | 81 |
|
85 | 82 | ```CLI
|
86 | 83 | dotnet nuget push --source https://pkgs.dev.azure.com/<ORGANIZATION_NAME>/<PROJECT_NAME>/_packaging/<FEED_NAME>/nuget/v3/index.json --api-key <ANY_STRING> <PACKAGE_PATH>
|
87 | 84 | ```
|
88 | 85 |
|
89 |
| -**Example**: *dotnet nuget push --source https://pkgs.dev.azure.com/MyOrg/MyProject/_packaging/MyFeed/nuget/v3/index.json --api-key AZ bin/MyPackage.5.0.2.nupkg* |
| 86 | +**Example**: |
| 87 | + |
| 88 | +```CLI |
| 89 | +dotnet nuget push --source https://pkgs.dev.azure.com/MyOrg/MyProject/_packaging/MyFeed/nuget/v3/index.json --api-key AZ bin/MyPackage.5.0.2.nupkg |
| 90 | +``` |
| 91 | + |
90 | 92 |
|
91 | 93 | > [!NOTE]
|
92 |
| -> The `api-key` is only used as a placeholder. |
| 94 | +> The `api-key` is required, but you can provide any string as its value when publishing to an Azure Artifacts feed. |
93 | 95 |
|
94 |
| -## Publish packages from external sources |
| 96 | +## Publish packages to a feed in another organization |
95 | 97 |
|
96 |
| -1. Create a [personal access token](../../organizations/accounts/use-personal-access-tokens-to-authenticate.md) (PAT) with **packaging read and write** scope. |
| 98 | +To publish your NuGet packages to a feed in a different Azure DevOps organization, you must first create a personal access token (PAT) in the target organization. |
97 | 99 |
|
98 |
| -1. Replace the *<PERSONAL_ACCESS_TOKEN>* placeholder with your personal access token, and then run the following command to add your package source to your *nuget.config* file. This adds your PAT to your *nuget.config*. Make sure to store this file securely and not check it into source control. |
| 100 | +1. Navigate to the organization hosting the target feed and create a [personal access token](../../organizations/accounts/use-personal-access-tokens-to-authenticate.md) (PAT) with **Packaging** > **Read & write** scope. |
| 101 | + |
| 102 | +1. Replace the *<PERSONAL_ACCESS_TOKEN>* placeholder with your personal access token, and then run the following command to add your package source to your *nuget.config* file. Ensure that this file is stored securely and is not checked into source control. |
99 | 103 |
|
100 | 104 | ```CLI
|
101 | 105 | 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>
|
102 | 106 | ```
|
103 | 107 |
|
104 |
| -1. Publish your package: |
| 108 | +1. Run the following command to publish your package: |
105 | 109 |
|
106 | 110 | ```CLI
|
107 | 111 | dotnet nuget push --source <SOURCE_NAME> --api-key <ANY_STRING> <PACKAGE_PATH>
|
108 | 112 | ```
|
109 | 113 |
|
110 | 114 | **Example**:
|
111 |
| -*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* |
112 |
| -*dotnet nuget push --source MySource --api-key AZ nupkgs/mypackage.1.1.0.nupkg* |
113 | 115 |
|
114 |
| -> [!NOTE] |
115 |
| -> If your organization is using a firewall or a proxy server, make sure you allow the [Azure Artifacts Domain URLs and IP addresses](../../organizations/security/allow-list-ip-url.md#azure-artifacts). |
| 116 | +```CLI |
| 117 | +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 |
116 | 118 |
|
117 |
| -## Restore packages |
| 119 | +dotnet nuget push --source MySource --api-key AZ nupkgs/mypackage.1.1.0.nupkg |
| 120 | +``` |
118 | 121 |
|
119 |
| -Run the following command to restore your packages. The `--interactive` flag is used to prompt the user for credentials: |
| 122 | +> [!NOTE] |
| 123 | +> If your organization is using a firewall or a proxy server, make sure you allow the [Azure Artifacts Domain URLs and IP addresses](../../organizations/security/allow-list-ip-url.md#azure-artifacts). |
120 | 124 |
|
121 |
| -```CLI |
122 |
| -dotnet restore --interactive |
123 |
| -``` |
124 | 125 |
|
125 |
| -## Related articles |
| 126 | +## Related content |
126 | 127 |
|
127 |
| -- [Connect to Azure Artifacts feeds (NuGet.exe)](./nuget-exe.md) |
| 128 | +- [Restore NuGet packages (dotnet)](restore-nuget-packages-dotnet.md) |
128 | 129 | - [Publish packages with Azure Pipelines (YAML/Classic)](../../pipelines/artifacts/nuget.md)
|
129 |
| -- [Use packages from NuGet Gallery](./upstream-sources.md) |
| 130 | +- [Use packages from NuGet.org](./upstream-sources.md) |
0 commit comments