| title | Connect your Cargo project to an Azure Artifacts feed |
|---|---|
| description | Learn how to set up your Cargo project and connect to an Azure Artifacts feed. |
| ms.service | azure-devops-artifacts |
| ms.topic | how-to |
| ms.date | 01/21/2025 |
| monikerRange | >= azure-devops-2022 |
[!INCLUDE version-gt-eq-2022]
This article guides you through setting up your Cargo project, configuring the credential provider, and connecting to an Azure Artifacts feed.
| Product | Requirements |
|---|---|
| Azure DevOps | - An Azure DevOps organization. - An Azure DevOps project. - Download and install rustup. You'll need Cargo version 1.74.0 or later. |
-
Sign in to your Azure DevOps organization, and navigate to your project.
-
Select Artifacts, and then select your feed from the dropdown menu.
-
Select Connect to feed, and then select Cargo from the left navigation pane.
-
Add the provided snippet to your cargo/config.toml in your source repository. Your config.toml file should resemble the following:
-
Project-scoped feed:
[registries] FEED_NAME = { index = "sparse+https://pkgs.dev.azure.com/ORGANIZATION_NAME/PROJECT_NAME/_packaging/FEED_NAME/Cargo/index/" } -
Organization-scoped feed:
[registries] FEED_NAME = { index = "sparse+https://pkgs.dev.azure.com/ORGANIZATION_NAME/_packaging/FEED_NAME/Cargo/index/" }
-
-
Add the following snippet to your cargo/config.toml to replace the crates.io source with your feed. Replace the placeholder with your feed name:
[source.crates-io] replace-with = "FEED_NAME"
To use Cargo with Azure Artifacts, you must first set up a default credential helper. See The Cargo Book for more details.
Add the following snippet to your %USERPROFILE%.cargo\config.toml. This sets a default credential helper for the user:
[registry]
global-credential-providers = ["cargo:token", "cargo:wincred"]
Add the following snippet to your /.cargo/config.toml. This sets a default credential helper for the user:
[registry]
global-credential-providers = ["cargo:token", "cargo:libsecret"]
Add the following snippet to your /.cargo/config.toml. This sets a default credential helper for the user:
[registry]
global-credential-providers = ["cargo:token", "cargo:macos-keychain"]
-
Sign in to your Azure DevOps organization, and navigate to your project.
-
Generate a Personal access token with Packaging > Read & write scopes to authenticate with your feed.
-
Run the following command to log in to your registry. Replace the placeholder with your feed's name, and provide the personal access token you created earlier when prompted:
"Basic " + [Convert]::ToBase64String([Text.Encoding]::UTF8.GetBytes("PAT:" + (Read-Host -MaskInput "Enter PAT"))) | cargo login --registry <FEED_NAME>read -p "Enter PAT: " PAT; echo Basic $(echo -n PAT:$PAT | base64) | cargo login --registry <FEED_NAME>az login
az account get-access-token --query "join(' ', ['Bearer', accessToken])" --output tsv | cargo login --registry <FEED_NAME>
[!div class="nextstepaction"] Publish Cargo packages