简体   繁体   English

有没有一种聪明的方法来处理NuGet中的包依赖?

[英]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.). 我们正在开发一个具有各种“共同”依赖关系(Unity,Prism等)的WPF应用程序。

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. 在添加新项目然后为每个项目设置NuGet包依赖项时都很好,但是当涉及到升级时,它真的很痛苦,因为这意味着我们必须遍历每个项目,删除旧的引用然后重新获取最新的包来自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. 例如,今天我的任务是将Prism从5.0升级到6.0(无论如何都有破坏性更改),这意味着除了修复我必须通过每个项目的所有命名空间冲突等之外,删除旧的引用,添加新的依赖性并冲洗并重复。

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. 版本5.0 - > 6.0升级将被视为主要升级,因此,在NuGet包管理器中不会对其应用自动更新。

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. 我不认为NuGet能够自动为我做这个,因为这样的升级可能(并且经常)包括重大改变但我想知道是否有一种方法来进行主要升级比从删除引用更少痛苦每个项目的项目和packages.config,然后使用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'. 如果您使用VS2013,则可以通过右键单击解决方案并选择“管理解决方案的NuGet包”来管理所有NuGet包。 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. 当您升级软件包时,VS会处理所需的所有参考更改。 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. 免责声明:我从未参与WPF项目/解决方案,但对于Web / Forms应用程序,NuGet包以这种方式处理。

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) 完成所有设置后,您可以使用脚本实际执行更新(我使用的是python运行时脚本)

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 你可以实际看一下设置常见的nuget-packages-folder以获取详细信息的参考更新 ,但它看起来就像你在寻找自动化过程一样

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. 尝试在Xamarin Studio中升级多个包含alpha通道问题的软件包时,我遇到了类似的问题,这也没有VS 2015 NuGet管理器的细节。 I ended up writing a very simple PowerShell script that I run multiple times a day. 我最终编写了一个非常简单的PowerShell脚本 ,我每天运行多次。

#
# 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. 我相信你可以定制你的NuGet命令以满足你的需求。

Also, just in case you aren't aware of it, you should definitely read the NuGet command line reference . 此外,如果您不了解它,您一定要阅读NuGet命令行参考 I may be mistaken, but it sounds like your scenario is doable with the Update command. 我可能会弄错,但听起来你的场景可以使用Update命令。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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