Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet not getting missing packages

I have following project structure in VSS

enter image description here

Now in Visual Studio 2010 Pro: I open Solution2 and then add Library1 as external project.

Library1 is referencing two external libraries which I get via NuGet. When I build my Solution2 it all works fine. So I checked-in all my project.

Issue: When another developer gets the Solution2 from sourcesafe and builds, it says Library1 is missing those external libraries dlls.

Tried following:

1: http://docs.nuget.org/docs/workflows/using-nuget-without-committing-packages

So now I have .nuget folder under Solution2 which gets checked-in. But that's still not bringing the dlls.

My doubt is the Library1 being in a separate solution is causing this issue.

Any ideas how to get missing packages automatically via NuGet?

Update:
Xavier's suggestions helped and here are two of his blog posts:

  • http://xavierdecoster.com/how-to-nuget-package-restore-when-sharing-projects-between-solutions
  • http://xavierdecoster.com/debugging-nuget-package-restore
like image 899
gbs Avatar asked Jul 22 '13 20:07

gbs


People also ask

Why is my NuGet package not updating?

This can happen if the XML elements in the .csproj file that reference the old package version number had been manually added or edited, NuGet will not remove or update them if they had been manually added/edited, so the project is now looking for packages that have been deleted.

How do I restore NuGet packages in Visual Studio?

(In Visual Studio, the references appear in Solution Explorer under the Dependencies \ NuGet or the References node.) To follow the required steps to restore packages, see Restore packages.

How to update NuGet to the latest version?

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.

Why am I getting a NuGet installation error when trying to build?

This error occurs when you attempt to build a project that contains references to one or more NuGet packages, but those packages are not presently installed on the computer or in the project.


2 Answers

With your current setup, you should make sure you have enabled NuGet Package Restore on both solutions and the Solution2 nuget.targets should point the nuget install command to the Solution1\Packages outputdirectory. Your folder structure will look like this:

Folder structure

Reason: the Library1.csproj references are pointing to the Solution1\Packages location. When adding this project to Solution2, the project references are not changed, but the solution will restore the packages in Solution2\Packages instead of Solution1\Packages.

If you already have installed packages in the projects of Solution2, you'll need to make sure those still restore against Solution2\Packages. To do that, I'd recommend you to set an MSBuild property within the shared project files (above the import statement for the nuget.targets file) and pass this MSBuild property value into the RestoreCommand.

E.g.:

<PackagesOutDir>$(SolutionDir)..\Libraries\Packages</PackagesOutDir>

And adjust the nuget.targets file, e.g.:

<PackagesOutDir Condition="$(PackagesOutDir) == ''">$(SolutionDir)\Packages</PackagesOutDir>

...

<RestoreCommand>... -o "$(PackagesOutDir) "</RestoreCommand>


Optionally, If you want to use a single Packages folder, you could modify both .nuget\NuGet.targets files and set the -o (or -OutputDirectory) switch for the nuget install command.

Appending this to the RestoreCommand element: -o "$(SolutionDir..\Packages" will ensure all packages get restored in a single location:

enter image description here

Note that you will have to manually update the installed package references each time you install a NuGet package after doing this!

like image 91
Xavier Decoster Avatar answered Nov 13 '22 13:11

Xavier Decoster


Check out our answer here: Nuget Package restore with git submodule, This option does not involves any *.csproj manipulation

like image 34
Roi Shabtai Avatar answered Nov 13 '22 13:11

Roi Shabtai