每次我在 Visual Studio 2017 中打开使用 Net.Core SDK 的解决方案时,它都会恢复包。即使我关闭解决方案并再次打开它,这种情况总是会发生。
为什么它不本地跟踪计算机上存在哪些 nuget 包?
我可以让它表现得更符合逻辑吗?首先在本地检查包是否存在,然后仅在找不到包时才恢复它?
最佳答案
Question: How to prevent nuget from redundantly restoring packages after opening solution in Visual Studio 2017
目前无法显式禁用自动恢复。检查以下线程以了解更多详细信息:
How do I disable restoring NuGet packages while starting the solution
The restore you are seeing there is Auto-Restore which will only run on SDK based projects. https://learn.microsoft.com/en-us/nuget/consume-packages/package-restore#automatic-restore-in-visual-studio
There is currently no way to disable auto-restore explicitly but you can disable restore itself. Note that this will disable all restore (on build/rebuild & solution right click restore)
此外,您不需要禁用它,请检查以下另一个原因:
Question: Can i make it to behave more logically and first to check it locally for the package presence and to restore it only if it can not be found?
nuget 现在所做的正是您想要它做的。检查:
Forcing restore from package sources :
By default, NuGet restore operations use packages from the global-packages and http-cache folders.
因此,打开解决方案时看到的恢复只是检查全局包中是否存在包,如果不存在,则 nuget start 恢复包。如果包存在,nuget不会执行恢复操作。而且检查时间很短,大约几十ms。您不必太担心。
希望这有帮助。
关于.net-core - 如何防止 nuget 在 Visual Studio 2017 中打开解决方案后冗余恢复包,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53495491/