How to install a package into all projects of a solution

This is a script that I've been keeping in my toolbox since NuGet was first released.

Ever now and then I need to do an install of a package across all projects in a solution. log4net is an example of the kind of thing you'd want to globally install, so is Autofac.

Well here's a script to run from the Package Management Console:

Get-Project -All | Install-Package packageName

This is also available as a gist.

Note: replace packageName with what you want to install ;).

Challenge to the reader

*Update: With a tip-off from David Fowler you can compress the script even more. If you want to see the original just check out the gist history.

Installing into a project subset

Since this is just a powershell script you can also apply filters, so if you have say multiple test projects you do run this:

Get-Project -All | where { $_.Name.EndsWith(".Test") } | Install-Package NSubstitute

Woot!

nuget
Posted by: Aaron Powell
Last revised: 24 Mar, 2011 10:11 PM History

Comments

Aboo
Aboo
26 Feb, 2011 10:49 PM

Great tip

Thanks for sharing it.

26 Feb, 2011 10:54 PM

Far be it from me to nitpick ;)

Why would you want to install Autofac in every project in your solution ? Surely you'd only reference your container from your application boundaries.

26 Feb, 2011 10:58 PM

Damian:

If you're using Modules to wire up the components from each tier then you'll need Autofac. Take FunnelWeb for example, we don't want the repository implementations accessed directly so we use a Module to handle their setup.

27 Feb, 2011 08:48 AM

@Aaron, How about a project only for dependencies?

The project can have a reference to everything else and have the wiring/modules for DI setup. This can be its only role and then it can be reference from the entry project (exe/web) that calls one method in it that does all the wiring.

Of course it sounds bad to have something reference everything else, but would love to hear your take on that approach.

blog comments powered by Disqus