NuGet packages show "source not available" and aren't loading properly (with loading indicators stuck), follow this targeted troubleshooting guide

 1. Fix Package Sources Configuration

Check NuGet sources:

  • bash
    dotnet nuget list source

    Ensure your primary source (e.g., nuget.org) is ENABLED and reachable.

  • Re-add nuget.org:

    bash
    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

bash
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:

bash
# 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

bash
# Restore with full diagnostics
dotnet restore --verbosity diag > restore.log 2>&1

Key things to check in logs:

  • Source <name> is not available errors

  • HTTP 401/403 authentication failures

  • SSL/TLS handshake errors

5. Fix Project-Specific Issues

  • Ensure SDK version compatibility in global.json:

    json
    {
      "sdk": { "version": "8.0.400" }
    }
  • Disable parallel restores:

    bash
    dotnet restore --disable-parallel

6. Network & Security Workarounds

  • Bypass SSL validation (temporarily!):

    bash
    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):

    bash
    dotnet nuget update source nuget.org --source https://www.nuget.org/api/v2

7. Visual Studio-Specific Fixes

  1. Go to Tools > Options > NuGet Package Manager > General

  2. Uncheck:

    • "Allow NuGet to download missing packages"

    • "Automatically check for missing packages during build"

  3. Click "Clear All NuGet Cache(s)"

  4. Restart VS as Administrator


Package Source Availability Test

Verify source accessibility with this C# code:

csharp
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 outputStatus: 200 with JSON data.


Common Solutions Matrix

SymptomLikely FixCommand/Step
"Source not available"Source misconfigurationdotnet nuget update source
Packages stuck loadingCorrupted temp filesClear /tmp/NuGetScratch
HTTPS errorsSSL bypass or HTTP fallbackexport DOTNET_NUGET_HTTP_PROVIDER_ENV_SSL_VERIFY=false
Private feed issuesRe-authenticate with PATdotnet nuget update source --username ...
VS-specific hangsDisable auto-restore & clear VS cachesVS Options > NuGet > Clear Caches

Final Checks

  1. Test with new project:

    bash
    dotnet new console -n TestNuget
    cd TestNuget
    dotnet add package Newtonsoft.Json
  2. Check corporate proxies:

    • Configure proxy settings via:

      bash
      dotnet nuget config set http_proxy http://proxyserver:port

If issues persist:

  1. Share restore.log (last 20 lines)

  2. Output of:

    bash
    dotnet --info
    dotnet nuget list source
    ping api.nuget.org

No comments:

Post a Comment

Best for you