I have read many of the answers on SO and NuGet (and the Internet in general, really), but I can't seem to overcome the problem I am having with NuGet package restore in Visual Studio 2015. I have the following scenarios.
Solution A Structure
If I open and build Solution A I see the dialog box that shows the nuget package restore progress and the solution builds successfully.
Solution B Structure
However, assuming that I have never built Solution A (i.e. fresh pull from TFS), if I open and build Solution B I see the dialog box that shows the nuget package restore progress, but the build fails because Project A fails to build.
What appears to be happening is that that NuGet is restoring the packages for Project B, but not for Project A thus the build failure. To the point, if I look at the references for Project B all of the NuGet references have resolved, but the references for Project A are still broken.
A few points:
nuget update -self
By default, NuGet creates the solution's
packages folder in the solution root, and each project references its package DLLs to that "local" packages folder. In your example, if you open the .csproj file for Project A, you'll probably see that the reference path is something like
So when you do a fresh pull from TFS and build solution B, Project A can't find its DLLs because
c:\workspace\Solution A\packages doesn't exist yet (or whatever the absolute path is on your machine).
To correct this, use a shared package folder, created at
c:\workspace\packages. To do this, you have to add an additional node to the NuGet.config in each solution (see https://docs.nuget.org/consume/nuget-config-file for details; I am also assuming you have a NuGet folder at
<config> <add key="repositorypath" value="..\..\packages" /> </config>
I used a relative path here, but you can use an absolute path as well, and the documentation says you can use
%HOME% as well.
Do this, then restart Visual Studio. The next time you open the package manager, it should ask you if you want to restore missing packages, and assuming you click yes, it will put them in the new location. The last step is to edit the .csproj file and change all instances of
..\..\packages (or you can uninstall and reinstall the package, but I find editing the .csproj a lot faster).