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:

gbs
  • 7,196
  • 5
  • 43
  • 69

2 Answers2

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!

Community
  • 1
  • 1
Xavier Decoster
  • 14,580
  • 5
  • 35
  • 46
  • 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 '13 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? – Xavier Decoster Jul 23 '13 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 '13 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. – Xavier Decoster Jul 23 '13 at 19:39
  • I updated Solution2 .targets RestoreCommand to point to Solution1/packages and that seems to be working to restore Library1 packages. But now Solution2/Project1 also has it's own packages. How will Solution2 know to restore those? – gbs Jul 23 '13 at 20:58
  • You'll need to set the outputdirectory on a per project basis then. Updated my answer again. – Xavier Decoster Jul 23 '13 at 21:37
  • let us [continue this discussion in chat](http://chat.stackoverflow.com/rooms/34019/discussion-between-gbs-and-xavier-decoster) – gbs Jul 23 '13 at 22:00
  • Now it's loading my Solution1/Library1 packages correctly when I open/build Solution2. The only trouble left is my Solution2/website which uses AjaxControlToolkit package which isn't loading. I will post another question on this. Thanks for all your help. – gbs Jul 24 '13 at 20:29
  • yw! feel free to link the other question :) – Xavier Decoster Jul 24 '13 at 21:21
  • It looks like Package Restore isn't supported for Websites: http://nuget.codeplex.com/workitem/1663 Any idea if that has changed? – gbs Jul 24 '13 at 23:26
  • 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 '16 at 00:58
  • @Nuzzolilo yes it is a workaround and that has worked well. Though now I have a simpler solution and that it to use $(SolutionDir) for the Hint path. This is mainly because the shared library is a part of two different solutions. Ideal solution would be for us have our own Nuget server to host the common libraries instead of adding reference as External Project. – gbs Aug 25 '16 at 02:11
  • Using the $(SolutionDir) macro within your .csproj file is what I do also – marknuzz Aug 26 '16 at 14:16
  • hi @XavierDecoster is this suggestion still valid even when [automatic restore is more favoured over msbuild-integrated restore](https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore#migrating-to-automatic-restore) ? – YS. Aug 22 '17 at 23:56
2

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

Community
  • 1
  • 1
Roi Shabtai
  • 2,981
  • 2
  • 31
  • 47