简体   繁体   中英

Is there a smart way to deal with package dependencies in NuGet?

We are developing a WPF application at work which has various "common" dependencies (Unity, Prism, etc.).

It's all fine when adding new projects and then setting up the NuGet package dependency per project but when it comes to upgrades, it's really painful as it means we have to go through each and every project, delete the old references and then refetch the latest packages from NuGet.

Today for instance, I was tasked with upgrading Prism from 5.0 to 6.0 (which has breaking changes anyway) and this meant, in addition to fixing all the namespace conflicts, etc. that I had to go through every project, delete the old references, add the new dependecies and rinse and repeat.

My question is, is there a smarter way to deal with this problem or is this the standard approach?

Many thanks in advance,

Update:

I am mostly concerned with "major" upgrades which don't show up on the package manager. Version 5.0 -> 6.0 upgrade would be treated as a major upgrade and hence, would not have an automatic update applied to it in the NuGet package manager.

I don't expect NuGet to be able to do this automatically for me since such upgrades may (and often do) include breaking changes but I would like to know if there's a way to do the major upgrades less painfully than deleting the references from the projects and the packages.config for every project and then re-adding them using NuGet. For a relatively large project, this is very time consuming and I was wondering if anyone had a better way of managing such dependencies.

If you use VS2013 like you say, you can manage ALL your NuGet packages by right-clicking on your Solution and selecting 'Manage NuGet Packages For Solution'. This brings up a dialog where you can view all packages installed for all projects in the solution and all packages that have updates available. When you do upgrade the packages, VS takes care of all the reference changes required. If the package has breaking changes, then you're still on the hook for fixing those.

Disclaimer: I've never worked on a WPF project/solution but for Web/Forms apps, NuGet packages are handled this way.

I can understand your pain because i had the similar problem like you, but there is no easy way. but certainly you need to break the process differently of your daily development and your dependency update roll-out.

for the project i worked on, I use the common repository path that shared among the solutions that you work on, and you need to delete all the solutions folder references in order to get a clean state.

For each solution you work on you need to modify the property group that point to the common target repository (i'm using relative path)

Once all the things setup, you can actually perform an update with a script(I'm using python run-time script)

you can actually look at setting up common nuget-packages-folder for reference updates for detail, but it seems like what you looking at for the automate process

I had a similar problem when trying to upgrade multiple packages with alpha channel issues in Xamarin Studio, which also does not have the niceties of VS 2015 NuGet manager. I ended up writing a very simple PowerShell script that I run multiple times a day.

#
# This script updates local ibGib NuGet packages for mobileGib Android app solution.
# For convenience in copy+paste in manager console:
# ../UpdateLocalNugetPackages.ps1

Update-Package commonGib
Update-Package ibGib
Update-Package languageGib.Biz
Etc.

I believe you could tailor your NuGet commands to fit your needs.

Also, just in case you aren't aware of it, you should definitely read the NuGet command line reference . I may be mistaken, but it sounds like your scenario is doable with the Update command.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM