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条回答
一纸荒年 Trace。
2楼-- · 2019-01-07 03:25

For anyone who stumbles here with the issue I had (some but not all packages being restored on a build server), the final piece of the puzzle for me was adding a NuGet.config in the root of my solution, sibling to the .SLN file as David Ebbo explained here: http://blog.davidebbo.com/2014/01/the-right-way-to-restore-nuget-packages.html.

From Ebbo's blog post, the file contents for me are simply

<?xml version="1.0" encoding="utf-8"?>
<configuration>
  <packageSources>
    <add key="nuget.org" value="https://www.nuget.org/api/v2/" />
  </packageSources>
</configuration>

UPDATE:

The NuGet API URL has changed for v3 (current as of Sept 2016). From https://www.nuget.org/

<add key="nuget.org" value="https://api.nuget.org/v3/index.json" />
查看更多
Melony?
3楼-- · 2019-01-07 03:25

The error message is completely correct. I tried all the tricks and none worked. The project (simple MVC Web App test) moved from Windows 8.1 VS 2015 Community to my new test box on Windows 10. All the latest updates to VS 2015 applied. I could not even install any newer version of the compilers package.

Loop:
<LOOP>This seems to be a Ground Hog Day phenomena.</LOOP>
GoTo Loop

I finally just copied Microsoft.Net.Compilers.1.0.0 from the old project into the new one and it worked. I could then start to update other packages to newer version. Looks like a nuget project upgrade process bug to me.

NOTE: The original project was created in VS 2015 and does not have any legacy nuget methodologies.

查看更多
够拽才男人
4楼-- · 2019-01-07 03:25

Mine worked when I copied packages folder along with solution file and project folder. I just did not copy packages folder from previous place.

查看更多
家丑人穷心不美
5楼-- · 2019-01-07 03:27

I realize this question is old, however I ran into this same situation today and wanted to throw in my 2 cents for anyone recent finding this issue. An ASP MVC project I had manually moved to a subfolder in my solution and then removed and readded to the solution, using Visual Studio 2017, was giving the error mentioned. Moving the "lib" and "packages" folders to the root of the same subfolder as the MVC project fixed my issue.

查看更多
孤傲高冷的网名
6楼-- · 2019-01-07 03:28

For me my gitignore file was ignoring my packages folder. The following gitignore line was causing the issue -

**/packages/*

Removed and it restored my packages folder. Hope this helps someone else.

查看更多
成全新的幸福
7楼-- · 2019-01-07 03:29

Just enable NuGet Package Restore. Right click your solution > choose 'Enable NuGet Package Restore'.

Right click your solution > choose 'Enable NuGet Package Restore'

This will create the .nuget folder with NuGet.Config file and fixed my problem.

查看更多
登录 后发表回答