Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet Package restore failed for project PROJECT: Unable to find version 2.0.0 of package 'Microsoft.Net.Compilers'

I used the GitHub extension of Visual Studio 2015 to clone my project onto a new computer. I try to restore packages and I get an error that says:

NuGet Package restore failed for project PROJECT: Unable to find version 2.0.0 of package 'Microsoft.Net.Compilers' 

I've looked into some other questions about similar issues, but none of those solutions have worked for me yet.

I tried deleting the packages folder, opening up up Visual Studios again and then rebuilding. That didn't resolve it.

I tried manually installing Microsoft.Net.Compilers in Package Manager Console.

 PM> Install-Package Microsoft.Net.Compilers 

I tried removing this bit of code from the csproj file (this seemed to work for some):

    <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">   <PropertyGroup>     <ErrorText>This project references NuGet package(s) that are missing on this computer. Enable NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>   </PropertyGroup>   <Error Condition="!Exists('$(SolutionDir)\.nuget\NuGet.targets')" Text="$([System.String]::Format('$(ErrorText)', '$(SolutionDir)\.nuget\NuGet.targets'))" /> </Target> 

I tried reinstalling all packages with

Update-Package –reinstall 

So far I haven't had any luck resolving the issue. Any help is appreciated.

EDIT:

I tried the response below and received this error:  Install-Package : Some NuGet packages are missing from the solution. The packages need to be restored in order to build the dependency graph. Restore the packages before performing any operations. At line:1 char:16 + Install-Package <<<<  -Id Microsoft.Net.Compilers -Version 1.3.2 -Source nuget.org     + CategoryInfo          : InvalidOperation: (:) [Install-Package], InvalidOperationException     + FullyQualifiedErrorId : NuGetMissingPackages,NuGet.PackageManagement.PowerShellCmdlets.InstallPackageCommand 

It also prompted me to restore packages. When I hit restore, I got the same error as usual.

like image 429
Dylan Caudill Avatar asked Dec 01 '16 14:12

Dylan Caudill


People also ask

How do I fix NuGet recovery failed?

Quick solution for Visual Studio usersSelect the Tools > NuGet Package Manager > Package Manager Settings menu command. Set both options under Package Restore. Select OK. Build your project again.

How do I fix a missing NuGet package?

Enable package restore by choosing Tools > Options > NuGet Package Manager. Under Package Restore options, select Allow NuGet to download missing packages. In Solution Explorer, right click the solution and select Restore NuGet Packages.

How do I force a NuGet package to reinstall?

Switch to the Browse tab, search for the package name, select it, then select Install). For all packages, delete the package folder, then run nuget install . For a single package, delete the package folder and use nuget install <id> to reinstall the same one.


2 Answers

Based on your error message looks like you are looking for a version that no longer exists and cannot tell which Package source you have selected. I feel like you are looking for version 2.0.0 which is not available in nuget.org repository. The latest one is 2.0.0-rc and it is pre release candidate.

Please try this command if you want to get the latest version

Install-Package -Id Microsoft.Net.Compilers -Version 2.0.0-rc -Source nuget.org 

If you want the latest stable version (1.3.2), try this command

Install-Package -Id Microsoft.Net.Compilers -Version 1.3.2 -Source nuget.org 

UPDATE If the package still cannot be installed, then that package may be out of sync between packages.config, packages/ folder and .csproj file

Please follow these steps to perform manual cleanup

  1. Close visual studio.
  2. Open .csproj in a notepad or some text editor and manually remove all entries related to Microsoft.Net.Compilers
  3. Open packages.config in a notepad or some text editor and and remove entry for the Microsoft.Net.Compilers package
  4. Go to packages/ folder in windows explorer and delete the Microsoft.Net.Compilers folder
  5. Now start the visual studio and open the solution.
  6. Now try to install the package again.

Some of the entries that you may have to remove from .csproj as part of step 2 are these

<Import Project="..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props" Condition="Exists('..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props')" />  <NuGetPackageImportStamp></NuGetPackageImportStamp>  <Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild">         <PropertyGroup>           <ErrorText>This project references NuGet package(s) that are missing on this computer. Use NuGet Package Restore to download them.  For more information, see http://go.microsoft.com/fwlink/?LinkID=322105. The missing file is {0}.</ErrorText>         </PropertyGroup>         <Error Condition="!Exists('..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.3.2\build\Microsoft.Net.Compilers.props'))" /> </Target> 
like image 137
Vinod Avatar answered Oct 01 '22 14:10

Vinod


I had a similar error after a clean install of Visual Studio 2017 and had to do the following to get it to automatically restore missing NuGet packages successfully. In VS, go to "Tools > Options > NuGet Package Manager > Package Sources", and ensure the appropriate package sources show and are checked.

See below. The addition of the nuget.org package source at the top tells VS to go online to download the packages from NuGet if it can’t find the appropriate versions on the local machine.

enter image description here

like image 43
Tawab Wakil Avatar answered Oct 01 '22 13:10

Tawab Wakil