NuGet Packages are missing

2019-01-07 02:43发布

I searched this problem but none of the solutions worked. I have Visual Studio Professional 2015 installed and I am using TFS. My NuGet version is 3.1.6. This problem is happening only in my C# Web API/MVC project.

I am getting the below error:

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 ..\packages\Microsoft.Net.Compilers.1.0.0\build\Microsoft.Net.Compilers.props

  1. I do not have .nuget folder in my solutions.
  2. I have a packages folder in the solution and when I delete it, it seems like NuGet does rebuild the dependencies but the project still has the above error.
  3. I tried removing the project from TFS and it didn't fix it.
  4. Along with the above error, all the references in the project have yellow warning signs and say they are missing.
  5. When I checked the NuGet Package Manager for the project, everything that is "missing" has a green tick next to it, including Microsoft.Net.Compilers.
  6. I tried adding a new Web API/MVC project and it faced a similar problem where most references such as Owin were "missing" with the yellow warning sign.

28条回答
爷、活的狠高调
2楼-- · 2019-01-07 03:11

The issue for me was that NuGet couldn't automatically get/update the packages because the full file path would be too large. Fixed by moving my solution to a folder in my Documents instead of a deeply nested folder.

Then can right-click on solution and select "Restore NuGet Packages" (which probably isn't necessary if you just build it and let it do it for you), and then select "Manage NuGet Packages for Solution" to get all the packages updated to the latest version.

This was for a solution of a sample ASP MVC application downloaded from Microsoft's web site.

查看更多
老娘就宠你
3楼-- · 2019-01-07 03:12

I solved my issue by removing this code from .csproj file:

<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>
查看更多
欢心
4楼-- · 2019-01-07 03:13

You can also use the suggested error message as a hint. Here's how, find the Manage Packages for Solution, and click on the resolve missing nuget package.

That's it

查看更多
forever°为你锁心
5楼-- · 2019-01-07 03:13

For DevOps/build engineers, you can probably fix this running nuget restore against the affected SLN, or project if you lack a SLN. I have to do this for our CI/CD builds for all our UWP projects.

  1. Make sure nuget is installed on the build slave either in Visual Studio or standalone. If it's the latter, make sure it's in PATH and skip step 2.
  2. Either open the VS Dev CMD console, or load it via an already open one, which you can do with the instructions below:
    VS2015 call "%VS140COMNTOOLS%VsDevCmd.bat"
    or
    VS2017 call "%ProgramFiles(x86)%\Microsoft Visual Studio\2017\Enterprise\Common7\Tools\VsDevCmd.bat"
  3. call nuget restore MyStuff.SLN or call nuget restore MyStuff.csproj if there's no SLN.
查看更多
SAY GOODBYE
6楼-- · 2019-01-07 03:18

A combination of the 2 answers worked for me. First I modified the .csproj file to remove the reference to 1.0.0 version

< Target Name="EnsureNuGetPackageBuildImports" BeforeTargets="PrepareForBuild" >

  ----Error---

< /Target>

and then did

Update-Package -Reinstall

from the and it worked.

查看更多
Juvenile、少年°
7楼-- · 2019-01-07 03:19

I had this exact frustrating message. What finally worked for me was deleting all files and folders inside /packages and letting VS re-fetch everything the next build.

查看更多
登录 后发表回答