'NuGet unable to find the version of a package

Running the command

nuget.exe restore .\MySolution.sln

gives this error:

Unable to find version '1.0.0' of package 'Microsoft.Net.Compilers'.

where the package has previously been installed and restored, but it has somehow become corrupt.



Solution 1:[1]

I was able to resolve this on macOS using the following command to reset my NuGet caches / indexes:

dotnet nuget locals --clear all

Afterwards I was able to restore my packages successfully:

dotnet restore

Solution 2:[2]

I had the same problem, but I needed to stay with nuget.exe 2.8 due to not being able to upgrade the version of .NET Framework installed on our build server (2.8 is the last version that still works with .NET 4.0).

The cause turned out to be having nuget.config only pointing to the v3 API. The solution is to add in the v2 API. For example,

<configuration>
  <activePackageSource>
    <add key="All" value="(Aggregate source)" />
  </activePackageSource>
  <packageSources>
    <add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
    <add key="nuget v2" value="https://www.nuget.org/api/v2" />
  </packageSources>
</configuration>

Solution 3:[3]

Because I stumbled over this multiple times recently, here is my solution:

  1. Go to C:\Users\<User>\AppData\Roaming\NuGet\
  2. Open NuGet.config
  3. Add <add key="keyName" value="path to repository"> in <packageSources>. In my case it was a network folder pointing to \\JENKINS\nuGet Repository

So it should look similiar to this:

<?xml version="1.0" encoding="utf-8"?>
<configuration>
    <packageRestore>
        <add key="enabled" value="True" />
        <add key="automatic" value="True" />
    </packageRestore>
    <packageSources>
        <add key="local" value="\\JENKINS\nuGet Repository" />
        <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
        <add key="nuget.org" value="https://api.nuget.org/v3/index.json" protocolVersion="3" />
    </packageSources>
    <disabledPackageSources />
    <activePackageSource>
        <add key="All" value="(Aggregate source)" />
    </activePackageSource>
</configuration>

Solution 4:[4]

If using dotnet cli and based on this document, you can use the dotnet restore command with some options, such as -f, --no-cache, and --ignore-failed-sources:

dotnet restore -f --no-cache --ignore-failed-sources

With this command .NET Core does not search in cached packages.

Solution 5:[5]

I was facing the same problem, but all your answers were not helping me.

Then, I found that my clock was delayed (I changed computer that day) and I had not realized that.

This simple correction made it all work normally. The package version does exist, but because it is considered to be in "the future", NuGet was giving this error that version x.x.x could not be found.

I think this is a huge mistake, because it doesn’t care what time the packages are. If you have a versions list, the datetime it was published is not important.

Solution 6:[6]

For me, what solved the problem was running the following command inside the solution folder:

nuget restore -NoCache -NonInteractive

Solution 7:[7]

In our case we upgraded the NuGet extension in Visual Studio from 3.3.x to 3.4.4.

You can find the update in menu Tools ? Extensions and Updates ? Updates ? Visual Studio Gallery.

Solution 8:[8]

In my case, I have upgraded my NuGet to the latest version, but I still got the error.

Then I find that, at Solution Root Folder ? 'packages' folder, there's repositories.config in it, and opening the file, you'll see all packages.config that is being used:

<repository path="..\Common\Luna.Common\packages.config" />
<repository path="..\Common\Luna.ComponentBehaviors\packages.config" />
<repository path="..\Common\Luna.Data\packages.config" />
<repository path="..\Common\Luna.WPF.ApplicationFramework\packages.config" />
<repository path="..\GuyWire\Luna.Basic.GuyWire\packages.config" />

And it is storing the information 1.0.0:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="Iesi.Collections" version="3.1.0.4000" targetFramework="net40" />
  <package id="log4net" version="2.0.3" targetFramework="net40" />
  <package id="NHibernate" version="1.0.0" targetFramework="net40" />
  <package id="uNhAddIns" version="1.0.0" targetFramework="net40" />
</packages>

Because in fact I'm referencing the DLL file by file, so I don't need to get by NuGet. I deleted the packages.config file and then the error was solved.

Solution 9:[9]

My problem was that I had "Package source" set to my own specific NuGet server instead of All.

Solution 10:[10]

Clearing the Nuget cache worked for me.

To do it from Visual Studio just open Tools -> Options -> Nuget Package Manager -> General and click on the button Clear All Nuget Cache(s)