Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet packages not restore in visual studio 2017

I have Asp.netCore solution which was working fine on Visual Studio 2015 and then i moved to Visual Studio 2017. Now the problem is that in Visual Studio 2017 on every nuget packages there is yellow exclamation mark. Following are solution which i have tried so far.

I'm using Visual Studio Version: 15.3.1

  • Run as 'Administrator' and restore package.
  • Clear All Nugget Cache(s) from Tools > options > NuGet Package Manager > and again restore Nuget.

You can see yellow mark on every nuget package

Note: I have searched and found following solution and tried but did not resolve my issue.

Solution 1

like image 795
Usman lqbal Avatar asked Aug 23 '17 06:08

Usman lqbal


People also ask

How do I enable NuGet package restore in Visual Studio 2017?

In Visual Studio on Windows, you can restore packages automatically or manually. First, configure Package Restore through Tools > Options > NuGet Package Manager.

How do I force a NuGet package to restore?

Restore NuGet packagesNavigate to Tools > Options > NuGet Package Manager > General, and then select the Allow NuGet to download missing packages check box under Package Restore. Enabling Restore NuGet Packages. In Solution Explorer, right-click the solution, and then select Restore NuGet Packages.

How do I enable NuGet package restore in Visual Studio 2015?

In Tools -> Options -> NuGet Package Manager -> General you need to select the "Allow NuGet to download missing packages" option which allows NuGet to restore and the "Automatically check for missing packages during build in Visual Studio" which enables on build restore.

How do I install NuGet packages missing?

To do that, go to Tools, NuGet Packaged Manager, then go to Package Manager Settings. Go to the General section, and then make sure you have a checkmark for Allow NuGet to download missing packages and also to automatically check for missing packages during the build in Visual Studio.


2 Answers

I found the answer on another thread here and credit should go to @AxelWass although he did not specifically focus it towards this, it absolutely fixes this issue. The above answer did not.


I had the same issue and solve it by opening the project in a text editor and deleting the following section:

<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.0.0\build\Microsoft.Net.Compilers.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props'))" />
   <Error Condition="!Exists('..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props')" Text="$([System.String]::Format('$(ErrorText)', '..\packages\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.1.0.0\build\Microsoft.CodeDom.Providers.DotNetCompilerPlatform.props'))" />
</Target>

Once this is removed, it will resolve this nightmare issue that VS2017 and PM seems to be unable to resolve. I too have run into this multiple times - especially when I blend many projects in the same solutions directory.

like image 185
Dave Friedel Avatar answered Sep 28 '22 15:09

Dave Friedel


As mentioned in Microsoft Installing and reinstalling packages with package restore Documentation, you should Update-Package -reinstall:

Update-Package -reinstall -ProjectName <project> command where is the name of the affected project as it appears in Solution Explorer. Use Update-Package -reinstall by itself to restore all packages in the solution.

If you still have the error, try edit your project file, check if there is A path refrence error there, also check the project/solution nuget config file.

like image 42
Jack Martin Avatar answered Sep 28 '22 17:09

Jack Martin