Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to Sync NuGet Packages Across Multiple Shared Projects & Solutions?

What is the proper technique for keeping NuGet packages in sync across multiple shared projects and solutions within Visual Studio? We share 200+ projects across multiple solutions. Each TRACK has a handful of solutions which have some or all of the track's projects. We also have several PLATFORM solutions which pull in multiple tracks as well as any number of the track's projects. Unfortunately, we have a few vendors that REGULARLY push out updates to their packages and developers inadvertently install / update packages while working in different solutions. We need to ensure the packages are updated regardless of what solution uses them.

Unfortunately, NuGet's site discusses how to perform the actual update, but not how to synchronize everything... http://docs.nuget.org/docs/start-here/Managing-NuGet-Packages-Using-The-Dialog#Updating_a_Package

like image 895
Ryan D'Baisse Avatar asked Mar 08 '14 23:03

Ryan D'Baisse


3 Answers

This isn't technically correct that you can't do this. You can use the built-in tools in Visual Studio 2010 / 2012 to do this for you.

In order to update packages in all the projects at the same time, you can launch the Manage NuGet Packages dialog at solution level.

So right-click the solution, then choose "Manage NuGet Packages for Solution". And presto! You're off and away!

Now, while it won't "sync" them automatically, it does allow you to see where you have duplicates and help you to move each of your projects to the proper versions of nuget packages you want to use.

Not a silver bullet, but it will help.

like image 128
chris smith Avatar answered Nov 23 '22 06:11

chris smith


There's no really good way to do this unfortunately.. What we do is run our own NuGet repository. When we want to force an update of a package, we delete the old version entirely, and upload the new one.

This doesn't guarantee that the developers pull the latest package of course, so we've made it part of our CI process to automatically pull all the NuGet packages into the solution prior to building, so if some package is updated and the developers haven't caught up, their next commit will fail the CI build, forcing them to go fix it.

It's kind of a workaround, but it's the best we've been able to come up with..

like image 21
XeroxDucati Avatar answered Nov 23 '22 05:11

XeroxDucati


It is possible to maintain all Nuget versions within a solution in a single .props file. However, this procedure requires some steps to be performed manually. I have seen this approach partially used in the dotnet/cli project on github:

  1. Create a new file with the extension .props, for example: Versions.props

  2. For each package in your solution (in all projects), create a property with the corresponding version (use of version ranges is possible)

<Project>
  <PropertyGroup>
    <log4netVersion>2.0.8</log4netVersion>
    <UnityVersion>5.9.*</UnityVersion>
  </PropertyGroup>
</Project>
  1. Import the .props file in every .cspoj file
<Import Project=".\version.props" />
  1. Replace version numbers in .cspoj files with the corresponding property form the .props file
<ItemGroup>
    <PackageReference Include="Unity" Version="$(UnityVersion)" />
    <PackageReference Include="log4net" Version="$(log4netVersion)" />   
</ItemGroup>

As described above, this procedure musst be done manually. Installing nuget packages with the nuget package manager will overwrite the version properties!

  1. Run dotnet restore on the solution to update all packages and dotnet list package to list all requested and resolved packages per project!

*enter image description here*

like image 43
wmorian Avatar answered Nov 23 '22 05:11

wmorian