Nuget 包還原異常解決方案
Intro
有時候 nuget 包會還原異常,查看引用好多包都帶着感嘆號
Solution
打開 Package Manager Console ,選擇有問題的項目 Project, 在 Package Manager Console 執行以下命令:
Update-Package -Reinstall
或者
Update-Package -Reinstall -Safe
這樣就會重新安裝包,並且有更新的還會安裝更新,相對來說下面這種方式更好一些,避免出現更新之後有不兼容的類庫導致代碼編譯失敗。
原文:
Note you can force package restore to execute by running the following commands in the nuget package manager console
Update-Package -Reinstall
Forces re-installation of everything in the solution.
Update-Package -Reinstall -ProjectName myProj
Forces re-installation of everything in the myProj project.
Note: This is the nuclear option. When using this command you may not get the same versions of the packages you have installed and that could be lead to issues. This is less likely to occur at a project level as opposed to the solution level.
You can use the -safe commandline parameter option to constrain upgrades to newer versions with the same Major and Minor version component. This option was added later and resolves some of the issues mentioned in the comments.
Update-Package -Reinstall -Safe