ppatierno
ppatierno

Reputation: 10065

Add reference to same Nuget package but for different targets

I have a solution in Visual Studio 2013 with more C# project files that have source code in common but are targeting for different platforms (.Net, WinRT, .Net Micro Framework and so on). All the csproj files are under the same directory.

These projects use a Nuget package that is available for all the above platforms itself.

If I add this Nuget package for one of the project (ex. .Net), the package.config file is created and inside has reference to that target (ex. .Net). The package is downloaded in the packages folder.

If I try to add the same package but for a different target to another project in the solution, the UI tells me that the package is already installed. It's true because a package.config file is already there but I'd like to have the same package for a different target.

So my question is the following : how can I add the same Nuget package to all different projects but with different targets ?

Thanks, Paolo

Upvotes: 0

Views: 496

Answers (1)

Kiliman
Kiliman

Reputation: 20312

Unfortunately, I don't think NuGet supports your scenario.

NuGet expects the packages.config file to be in the same folder as the .csproj file. There should be a 1-to-1 relation between these files. You should create a separate folder for each project rather than keep all .csproj files in the same folder.

If you want to share code across multiple projects, the easiest way is to use the new Shared Project support in Visual Studio. Normally this only applies to Universal Projects, but there is an extension[1] that you can install that enables Shared Projects for all project types.

Simply create a new Shared Project. Add all you common code to it. Then in your platform specific projects, you can simply Add Shared Project Reference.

Since each project is now independent, NuGet will add the appropriate package.

Hope this helps. Good luck!


[1] Shared Project Reference Manager https://visualstudiogallery.msdn.microsoft.com/315c13a7-2787-4f57-bdf7-adae6ed54450

Upvotes: 1

Related Questions