Nuget Artifact Registry
About 1370 wordsAbout 5 min
Create Artifact Registry
Refer to Create Artifact Registry
Obtain Artifact Registry Address
Refer to Obtain Artifact Registry Address
Create Access Token
All resources in the Cloud Native Build platform (including repositories, Artifact Registry, OPENAPI, etc.) require an access token for operations. Create Access Token
Local Usage
Client Instructions
Client/Tool | dotnet CLI | nuget.exe |
---|---|---|
Use Case | .NET Core/.NET 5+ projects | Legacy .NET Framework projects |
Cross-platform Support | Native support | Requires Mono |
Installation | Installed with .NET SDK, no additional setup | Requires downloading nuget.exe |
Credential Management Commands
You can use CNB's access token as login credentials. Configuration commands:
1. Configure Username/Password Credentials
Replace <TOKEN>
with the access token, <TOKEN_NAME>
with the credential name, <GROUP_NAME>
with the organization name, <REPO_NAME>
with the Artifact Registry name
dotnet nuget add source https://nuget.cnb.cool/<GROUP_NAME>/<REPO_NAME>/-/packages/v3/index.json --name <TOKEN_NAME> --username cnb --password <TOKEN> --store-password-in-clear-text
# Example: Add credential cnb.nuget
# dotnet nuget add source https://nuget.cnb.cool/cnb/nuget/-/packages/v3/index.json --name cnb.nuget --username cnb --password 29bGg84xqRf3ZweNpYlL92e7tDv --store-password-in-clear-text
2. List all credentials
dotnet nuget list source
3. Remove Credential
Replace <TOKEN_NAME>
with the credential name
dotnet nuget remove source <TOKEN_NAME>
# Example: Remove credential cnb.nuget
# dotnet nuget remove source cnb.nuget
4. Credential Storage Location
Client/Tool | |
---|---|
Windows | %AppData%\NuGet\NuGet.Config |
Linux/macOS | ~/.config/NuGet/NuGet.Config or ~/.nuget/NuGet/NuGet.Config |
1. Configure Username/Password Credentials
Replace <TOKEN>
with the access token, <TOKEN_NAME>
with the credential name, <GROUP_NAME>
with the organization name, <REPO_NAME>
with the Artifact Registry name
nuget sources add -source https://nuget.cnb.cool/<GROUP_NAME>/<REPO_NAME>/-/packages/v3/index.json -name <TOKEN_NAME> -username cnb -password <TOKEN> -StorePasswordInClearText
# Example: Add credential cnb.nuget
# nuget sources add -source https://nuget.cnb.cool/cnb/nuget/-/packages/v3/index.json -name cnb.nuget -username cnb -password 29bGg84xqRf3ZweNpYlL92e7tDv -StorePasswordInClearText
2. Configure API Key Credentials
Replace <TOKEN>
with the access token, <GROUP_NAME>
with the organization name, <REPO_NAME>
with the Artifact Registry name
nuget setapikey <TOKEN> -source https://nuget.cnb.cool/<GROUP_NAME>/<REPO_NAME>/-/packages/v3/index.json
# Example: Add API key credential
# nuget setapikey 29bGg84xqRf3ZweNpYlL92e7tDv -source https://nuget.cnb.cool/cnb/nuget/-/packages/v3/index.json
3. List All Credentials
nuget sources
4. Remove Credential
Replace <TOKEN_NAME>
with the credential name
nuget sources remove -name <TOKEN_NAME>
# Example: Remove credential cnb.nuget
# nuget sources remove -name cnb.nuget
5. Credential Storage Location
Client/Tool | |
---|---|
Windows | %AppData%\NuGet\NuGet.Config |
Linux/macOS | ~/.config/NuGet/NuGet.Config or ~/.nuget/NuGet/NuGet.Config |
Artifact Management Commands
Ensure credentials are configured before executing artifact management commands.
1. Pull Artifact
Replace <PACKAGE_NAME>
with the package name, <VERSION>
with the version number, <TOKEN_NAME>
with the credential name
dotnet add package <PACKAGE_NAME> --version <VERSION> --source <TOKEN_NAME>
# Example: Pull version 1.0.0 of mynupkg package from the Artifact Registry named cnb.nuget
# dotnet pack mynupkg.csproj --configuration Release --output nupkgs
2. Build Artifact
Replace <CSPROJ_PATH>
with the .csproj file path, <PKG_PATH>
with the nupkg package output path, <VERSION>
with the version number
dotnet pack <CSPROJ_PATH> -p:PackageVersion=<VERSION> --configuration Release --output <PKG_PATH>
# Example: Build artifact
# dotnet pack mynupkg.csproj --configuration Release --output nupkgs
# Or build a specific version artifact
# dotnet pack mynupkg.csproj -p:PackageVersion=1.0.0 --configuration Release --output nupkgs
3. Push Artifact
Replace <NUPKG_PATH>
with the nupkg package path, <TOKEN_NAME>
with the credential name
dotnet nuget push <NUPKG_PATH> --source <TOKEN_NAME>
# Example: Push version 1.0.0 of mynupkg package to the Artifact Registry named cnb.nuget
# dotnet nuget push ./mynupkg.1.0.0.nupkg --source cnb.nuget
4. Delete Artifact
Replace <PACKAGE_NAME>
with the package name, <VERSION>
with the version number, <TOKEN_NAME>
with the credential name
dotnet nuget delete <PACKAGE_NAME> <VERSION> --source <TOKEN_NAME>
# Example: Delete version 1.0.0 of mynupkg package from the Artifact Registry named cnb.nuget
# dotnet nuget delete mynupkg 1.0.0 --source cnb.nuget
5. Query Package Information
Replace <PACKAGE_NAME>
with the package name, <TOKEN_NAME>
with the credential name
dotnet package search <PACKAGE_NAME> --source <TOKEN_NAME>
# Example: Query packages containing mynuget from the Artifact Registry named cnb.nuget
# dotnet package search mynuget --source cnb.nuget
6. Clear local HTTP request cache
dotnet nuget locals http-cache --clear
7. Clear all local cache
dotnet nuget locals all --clear
1. Pull Artifact
Replace <PACKAGE_NAME>
with the package name, <VERSION>
with the version number, <TOKEN_NAME>
with the credential name
nuget install <PACKAGE_NAME> -version <VERSION> -source <TOKEN_NAME>
# Example: Pull version 1.0.0 of mynupkg package from the Artifact Registry named cnb.nuget
# nuget install mynupkg -version 1.0.0 -source cnb.nuget
2. Build Artifact
Replace <CSPROJ_PATH>
with the .csproj file path, <PKG_PATH>
with the nupkg package output path
nuget pack <CSPROJ_PATH> -Version <VERSION> -Properties Configuration=Release
# Example: Build artifact
# nuget pack mynupkg.csproj -Properties Configuration=Release
# Or build a specific version artifact
# nuget pack mynupkg.csproj -Version 1.0.0 -Properties Configuration=Release
3. Push Artifact
Replace <NUPKG_PATH>
with the nupkg package path, <TOKEN_NAME>
with the credential name
nuget push <NUPKG_PATH> -source <TOKEN_NAME>
# Example: Push version 1.0.0 of mynupkg package to the Artifact Registry named cnb.nuget
# nuget push ./mynupkg.1.0.0.nupkg -source cnb.nuget
4. Delete Artifact
Replace <PACKAGE_NAME>
with the package name, <VERSION>
with the version number, <TOKEN_NAME>
with the credential name
nuget delete <PACKAGE_NAME> <VERSION> -source <TOKEN_NAME>
# Example: Delete version 1.0.0 of mynupkg package from the Artifact Registry named cnb.nuget
# nuget delete mynupkg 1.0.0 -source cnb.nuget
5. Query Package Information
Replace <PACKAGE_NAME>
with the package name, <TOKEN_NAME>
with the credential name
nuget search <PACKAGE_NAME> -source <TOKEN_NAME>
# Example: Query packages containing mynuget from the Artifact Registry named cnb.nuget
# nuget search mynuget -source cnb.nuget
6. Clear local HTTP request cache
nuget locals http-cache -clear
7. Clear all local cache
nuget locals all -clear
Usage in Cloud Native Build
Build nupkg packages in the pipeline and push them to the Artifact Registry named by the credential.
Replace <REPO_URL>
with the Artifact Registry address, <TOKEN_NAME>
with the credential name, <CSPROJ_PATH>
with the .csproj file path, <PKG_PATH>
with the nupkg package output path, <NUPKG_NAME>
with the nupkg package name
main:
push:
- docker:
image: mcr.microsoft.com/dotnet/sdk:9.0
stages:
- name: Configure nuget repository address, username, and password
script: dotnet nuget add source <REPO_URL> --name <TOKEN_NAME> --username cnb --password <TOKEN> --store-password-in-clear-text
- name: Package nuget artifact
script: dotnet pack <CSPROJ_PATH> --configuration Release --output <PKG_PATH>
- name: Push nuget artifact to CNB
script: dotnet nuget push <PKG_PATH>/<NUPKG_NAME> --source <TOKEN_NAME>
- Example:
main:
push:
- docker:
image: mcr.microsoft.com/dotnet/sdk:9.0
stages:
- name: Configure nuget repository address, username, and password
script: dotnet nuget add source https://nuget.cnb.cool/cnb/nuget/-/packages/v3/index.json --name cnb.nuget --username cnb --password cnb_token --store-password-in-clear-text
- name: Build nuget artifact
script: dotnet pack mynupkg.csproj --configuration Release --output nupkgs
- name: Push nuget artifact to CNB
script: dotnet nuget push nupkgs/*.nupkg --source cnb.nuget
Usage in Workspaces
1. Configure dotnet development environment in .cnb.yml
$:
vscode:
- docker:
image: mcr.microsoft.com/dotnet/sdk:9.0
2. Configure nuget repository address, username, and password
Replace <REPO_URL>
with the Artifact Registry address, <TOKEN_NAME>
with the credential name, <TOKEN>
with the credential
dotnet nuget add source <REPO_URL> --name <TOKEN_NAME> --username cnb --password <TOKEN> --store-password-in-clear-text
dotnet pack xxx.csproj --configuration Release --output nupkgs
dotnet nuget push "nupkgs/*.nupkg" --source <TOKEN_NAME>
- Example: Add credential cnb.nuget, build nuget artifact, and push it to CNB
dotnet nuget add source https://nuget.cnb.cool/cnb/nuget/-/packages/v3/index.json --name cnb.nuget --username cnb --password 29bGg84xqRf3ZweNpYlL92e7tDv --store-password-in-clear-text
dotnet pack mynupkg.csproj --configuration Release --output nupkgs
dotnet nuget push "nupkgs/*.nupkg" --source cnb.nuget
FAQ
Q1: Encountered 401 Forbidden error
Possible cause: Insufficient permissions for the credential.
Solution: Reconfigure the access token with the required permissions. Token acquisition: Personal Settings -> Access Tokens -> Add Access Token -> Select the appropriate permissions for the Artifact Registry.
Q2: Encountered 403 Forbidden error
Possible cause: Incorrect credential configuration.
Solution: Configure the correct access token for the Artifact Registry. Token acquisition: Personal Settings -> Access Tokens -> Add Access Token -> Select the appropriate permissions for the Artifact Registry.
Q3: Encountered 409 Forbidden error
Possible cause: Package already exists and overwriting is not allowed.
Solution: To overwrite the package, go to the corresponding Artifact Registry -> Artifact Registry Settings -> Policy Management -> Select "Allow Overwriting Existing Versions".
Q4: How to support HTTP
Possible cause: Client only supports HTTPS by default.
Solution:
Client/Tool | HTTP support |
---|---|
dotnet CLI | Specify --allow-insecure-connections when adding the repository credential |
nuget.exe | Specify -AllowInsecureConnections when adding the repository credential |
More Usage
For more Nuget usage, refer to the official documentation.
View file content to verify terminology usage