Sometimes, you just need to push a NuGet package to Azure DevOps Artifacts quickly, but things don’t go as smoothly as expected. You might run into authentication issues where the text-based credential prompts don’t accept your login details, and you don’t have immediate access to your Personal Access Token (PAT).
In such cases, the best solution is to force NuGet to open the credentials window, allowing you to enter your credentials manually and get the package uploaded.
Note: The following steps update the version of NuGet in the folder where you run these commands.
Step 1: Update NuGet to the Latest Version
To ensure you’re using the latest NuGet version, you can either update it via PowerShell or download it manually:
Option 1: Update NuGet via PowerShell (Admin Mode)
.\nuget update -self
Option 2: Download NuGet Manually
If you prefer, download the latest version from NuGet.org and replace your existing nuget.exe
.
Step 2: Set Environment Variables
These environment variables enable logging and ensure NuGet uses the Azure DevOps credential provider.
$env:NUGET_CREDENTIAL_PROVIDER_DEBUG = "true"
$env:NUGET_CREDENTIAL_PROVIDER_LOG_PATH = "$env:TEMP\NuGetCredentialProvider.log"
$env:VSS_NUGET_EXTERNAL_FEED_ENDPOINTS = '[{"endpoint":"https://{your-project}.pkgs.visualstudio.com/_packaging/{your-source-name}/nuget/v3/index.json","username":"{your-email-address}","password":""}]'
Replace {your-project}
, {your-source-name}
, and {your-email-address}
with the actual values from Azure DevOps.
Step 3: Reset the NuGet Credential Provider
Reinstall the credential provider using the following commands:
Remove-Item -Recurse -Force "$env:USERPROFILE\.nuget\plugins" -ErrorAction SilentlyContinue
[Net.ServicePointManager]::SecurityProtocol = [Net.SecurityProtocolType]::Tls12
Invoke-Expression ((New-Object System.Net.WebClient).DownloadString('https://aka.ms/install-artifacts-credprovider.ps1'))
After installation, restart PowerShell (Admin Mode).
Step 4: Register Your NuGet Source
To ensure NuGet is correctly configured, remove any outdated sources and add the correct one.
if (.\nuget sources list | Select-String "{your-source-name}") {
.\nuget sources remove -Name "{your-source-name}"
}
.\nuget sources add -Name "{your-source-name}" -Source "https://{your-project}.pkgs.visualstudio.com/_packaging/{your-source-name}/nuget/v3/index.json" -Username "any" -Password "any"
This ensures your NuGet source is correctly registered before pushing the package.
Step 5: Push Your NuGet Package
Finally, push your package to Azure DevOps:
.\nuget push "{path-to-package}" -Source "https://{your-project}.pkgs.visualstudio.com/_packaging/{your-source-name}/nuget/v3/index.json" -ApiKey az
Final Thoughts
At this point, a credentials window should pop up, allowing you to log in. Once authenticated, your NuGet package will be successfully uploaded to Azure DevOps Artifacts.
These steps help when:
- You’re stuck in text-based credential prompts that don’t accept your credentials.
- You don’t have immediate access to your PAT.
- You need a quick fix to push a NuGet package from your local machine.
Let me know if this guide helped you, or if you’ve found a faster way to resolve this issue!
Recent Comments