5

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:

2 Answers 2

5

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!

14
  • Xavier, I do have Restore enabled on both solution and have exact same structure you mentioned with .nuget and packages folder under each solution. I only included repositories.config file in Packages folder though. On my local machine it works fine but when another developer grabs Solution2 from VSS, only Library1 project is fetched and not the packages folder. I will play a bit with .targets. Thanks.
    – gbs
    Jul 23, 2013 at 16:33
  • Strictly speaking, the Packages folder doesn't have to be committed (although I prefer to have the repositories.config file in VCS as well). Which version of nuget.exe is being used in the .nuget folders? you can update it to the latest using "nuget.exe update -self". Also, are you using TFS? If so, are the workspace mappings correct? Jul 23, 2013 at 17:55
  • NuGet Ver 2.6.4. I am using VisualSourceSafe. One thing I noticed when I open Solution2, the packages needed for Library1 are installed in Solution2/packages folder but Library1 isn't able to load them.
    – gbs
    Jul 23, 2013 at 17:58
  • 1
    I think that nails it. I've updated my answer. Your Library1 project is referencing the binaries from Solution1\Packages. Solution2 however will restore the packages in Solution2\Packages and not update any project references. Jul 23, 2013 at 19:39
  • 1
    You're kidding, right? You should never set a library's metadata to require knowledge about the hosting project (e.g. a "\..\Libraries" path). This is the worst kind of hack. This will indeed work, if your developers downloading your library have a folder structure exactly the same as how they set it up here.
    – marknuzz
    Apr 23, 2016 at 0:58
2

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

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.