Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

NuGet for solutions with multiple projects

Tags:

.net

nuget

People also ask

How do I add a NuGet package to multiple projects?

Right-click your solution > Manage NuGet Packages for Solution... ... Or: Tools > Library Package Manager > Manage NuGet Packages for Solution... And if you go to the Installed packages area you can 'Manage' a single package across every project in the solution.

How do I install NuGet from another project?

Simply copy existing packages. config file to your new project. Include this file into the project. Then follow to Package Manager Console and execute Update-Package -reinstall command.

How do I consolidate a NuGet package?

Click on “Manage NuGet Packages for Solution…” to open a slightly extended dialog to manage your NuGet packages: Browse, Installed and Updates work like the menus in the “default” NuGet packages dialog but contain all projects of this solution. The big addition is the Consolidate tab.

Does NuGet automatically install dependencies?

As I remember in the past nuget manager did dependencies installation automatically. The package manager will show the dependencies even if they are not explicitly declared in nuspec (docs.microsoft.com/en-us/nuget/reference/…) - as they are added automaticalky.


For anybody stumbling across this, now there is the following option :

Right-click your solution > Manage NuGet Packages for Solution...

... Or:

Tools > Library Package Manager > Manage NuGet Packages for Solution...

And if you go to the Installed packages area you can 'Manage' a single package across every project in the solution.


Use the console to target multiple projects

Tools > Library Package Manager > Package Manager Console

then use this command

Get-Project PROJECT-NAMES-WITH-COMMAS | Install-Package PACKAGENAME

for example

Get-Project Core,UI | Install-Package FluentDateTime

This sweet deal works for me:

PM> Get-Project -all | where {$_.Name -match "Songhay.Silverlight" -and
    $_.Name -notmatch "ApplicationLoader" -and $_.Name -notmatch ".Xml"}
    | ForEach-Object {Install-Package MvvmLight -project $_.Name}

If you want to install a package across multiple solutions I wrote a handy Powershell script for doing it, see here.

You can even filter the Get-Project -All command and target a sub-set of the project list.


You should use the "Add Library Package Reference" for all your external library on every project in your solution. You'll end up with a packages.config per project.

However, you'll download the package only one time and reuse them locally for all your other projects.


In Package Manager Console you can write the following command:

Get-Project -all | ForEach-Object {Get-Package -ProjectName $_.Name -filter 
PACKAGE_NAME} | where-object { $_.id -eq 'PACKAGE_NAME' } | Install-Package 
PACKAGE_NAME -Version VERSION

You can use that command for install or update as well (Update-Package)