Category Archives: powershell

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 | %{
    Write-Host $proj.name; 
    $proj = $_ ;
    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

Updating Visual Studio project references from NuGet packages.config

(Among other things), NuGet offers an alternative way of managing project references in Visual Studio.

The usual flow is to right-click on References, and choose “Manage NuGet Packages”.  The NuGet dialog then pops up, showing available packages.  Once you’ve selected a package, NuGet will:

  • download the package to your repository (if required)
  • update the VS project file (.csproj or .vbproj etc)
  • update its own packages.config file.

What if things get out-of-sync, though, eg you’ve moved your repository so that all the reference hints in the .csproj file are wrong?  It’d be nice to be able to use the info in the packages.config to automatically resync the .csproj file.

Here’s one brute-force way to do this (from within the Package Manager console in VS):

Read the rest of this entry

Follow

Get every new post delivered to your Inbox.

Join 126 other followers