Updating Visual Studio project references from NuGet packages.config (2)

Here’s a small refinement to the script I wrote a while back to update VS project references from the packages.config file:

function Sync-References([string]$PackageId) {
  get-project -all | %{
    $proj = $_ ;
    Write-Host $proj.name; 
    get-package -project $proj.name | ? { $_.id -match $PackageId } | % { 
      Write-Host $_.id; 
      uninstall-package -projectname $proj.name -id $_.id -version $_.version -RemoveDependencies -force ;
      install-package -projectname $proj.name -id $_.id -version $_.version
    }
  }
}

You can then use it to update selected packages, eg:

Sync-References FluentAssertions
About these ads

Posted on April 4, 2012, in Uncategorized and tagged , , . Bookmark the permalink. 6 Comments.

  1. Steven T. Cramer

    Hmm trying to do the same thing. I have some T4 templates that conditionally use packages and I would like the csproj file to udpate. Is there an easier way now?

  1. Pingback: Updating a NuGet package across all projects in Visual Studio | Dan Haywood

  2. Pingback: Updating Visual Studio project references from NuGet packages.config | Dan Haywood

  3. Pingback: Restore NuGet packages from packages.config | Dan Haywood

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

Follow

Get every new post delivered to your Inbox.

Join 242 other followers