1. Fix Package Sources Configuration
Check NuGet sources:
dotnet nuget list source
Ensure your primary source (e.g., nuget.org) is ENABLED and reachable.
Re-add nuget.org:
dotnet nuget remove source nuget.org dotnet nuget add source https://api.nuget.org/v3/index.json -n nuget.org
2. Clear NuGet Cache & Temp Files
dotnet nuget locals all --clear rm -rf /tmp/NuGetScratch/ # Linux/macOS del %TEMP%\NuGetScratch\* # Windows
3. Update NuGet Credentials (Private Feeds)
For Azure DevOps or private feeds:
# Re-authenticate feed dotnet nuget update source <SourceName> --username <User> --password <PAT> --store-password-in-clear-text
Use
--store-password-in-clear-text
only for testing
4. Enable Detailed Logging
# Restore with full diagnostics dotnet restore --verbosity diag > restore.log 2>&1
Key things to check in logs:
Source <name> is not available
errorsHTTP 401/403 authentication failures
SSL/TLS handshake errors
5. Fix Project-Specific Issues
Ensure SDK version compatibility in
global.json
:{ "sdk": { "version": "8.0.400" } }
Disable parallel restores:
dotnet restore --disable-parallel
6. Network & Security Workarounds
Bypass SSL validation (temporarily!):
export DOTNET_NUGET_HTTP_PROVIDER_ENV_SSL_VERIFY=false # Linux/macOS setx DOTNET_NUGET_HTTP_PROVIDER_ENV_SSL_VERIFY "false" # Windows
Use HTTP instead of HTTPS (if blocked):
dotnet nuget update source nuget.org --source https://www.nuget.org/api/v2
7. Visual Studio-Specific Fixes
Go to
Tools > Options > NuGet Package Manager > General
Uncheck:
"Allow NuGet to download missing packages"
"Automatically check for missing packages during build"
Click "Clear All NuGet Cache(s)"
Restart VS as Administrator
Package Source Availability Test
Verify source accessibility with this C# code:
using var httpClient = new HttpClient(); var response = await httpClient.GetAsync("https://api.nuget.org/v3/index.json"); Console.WriteLine($"Status: {response.StatusCode}"); Console.WriteLine(await response.Content.ReadAsStringAsync());
Expected output: Status: 200
with JSON data.
Common Solutions Matrix
Symptom | Likely Fix | Command/Step |
---|---|---|
"Source not available" | Source misconfiguration | dotnet nuget update source |
Packages stuck loading | Corrupted temp files | Clear /tmp/NuGetScratch |
HTTPS errors | SSL bypass or HTTP fallback | export DOTNET_NUGET_HTTP_PROVIDER_ENV_SSL_VERIFY=false |
Private feed issues | Re-authenticate with PAT | dotnet nuget update source --username ... |
VS-specific hangs | Disable auto-restore & clear VS caches | VS Options > NuGet > Clear Caches |
Final Checks
Test with new project:
dotnet new console -n TestNuget cd TestNuget dotnet add package Newtonsoft.Json
Check corporate proxies:
Configure proxy settings via:
dotnet nuget config set http_proxy http://proxyserver:port
If issues persist:
Share
restore.log
(last 20 lines)Output of:
dotnet --info dotnet nuget list source ping api.nuget.org
No comments:
Post a Comment