0

I’m looking for a way to use NuGet packages in projects which are included in multiple visual studio solutions.

Example: I’ve two solutions App1 and App2 both include a class library SharedProj. The structure looks like this:

├───App1
│   ├───App1
│   └───packages
│       └───NLog
├───App2
│   ├───App2
│   └───packages
│       └───NLog
└───SharedProj
    ├───packages.config

When I install a package to SharedProj it gets added to the packages.config. So far so good…

The problem is, the package will be installed into the packages directory of the open solution.

<Reference Include="Extend, Version=4.2.1, Culture=neutral, processorArchitecture=MSIL">
    <HintPath>..\App1\packages\NLog\lib\net45\NLog.dll</HintPath>
    <Private>True</Private>
</Reference>

For example, if the App1 solution is open the packages gets added to App1\packages. => A project from the App2 solution references a package from the App1 solution. Which means I ‘m not able to build App2 until I’ve restored the packages of App1.

How can I get NuGet to work in such a scenario?

musium
  • 2,942
  • 3
  • 34
  • 67

1 Answers1

1

Modify the HintPath of this reference to start with $(SolutionDir) instead of a relative path. This way the reference will be relative to whatever solution is open.

EDIT: If you do not want to update your csproj file after installing/updating each NuGet package, you could use the repositoryPath setting to set the package directory in each solution to address this issue (stackoverflow.com/q/4092759/2336787)

hsirah
  • 337
  • 1
  • 10
  • I thought about this, but I don’t want to edit the project file whenever I install or update a NugGet package – musium Nov 25 '15 at 12:00
  • 1
    You could possibly use the `repositoryPath` setting to set the package directory in each solution to address this issue (http://stackoverflow.com/q/4092759/2336787) – hsirah Nov 25 '15 at 22:34
  • Thank you, this works perfectly. I’ll accept it as the correct answer if you post it as answer. – musium Nov 26 '15 at 12:33