添加NuGet包时抛出异常问题咨询(Visual Studio 2017 Pro)
Hey there! Since you didn’t share the exact error message you’re getting when adding NuGet packages in Visual Studio 2017 Pro, I’ll walk you through the most common fixes that resolve most NuGet-related issues in this version. Let’s dive in:
清理NuGet缓存
Corrupted NuGet cache is one of the most frequent culprits. Here’s how to fix it:- Open Visual Studio, go to
Tools>NuGet Package Manager>Package Manager Settings - In the popup window, select
NuGet Package Manager>General, then click theClear All NuGet Cache(s)button - Restart Visual Studio and try installing the package again
- Open Visual Studio, go to
Verify NuGet source configuration
Invalid or blocked package sources often cause installation failures:- Go to
Package Manager Settings>Package Sources - Make sure the official
nuget.orgsource is enabled (check the box next to it) with the correct URL:https://api.nuget.org/v3/index.json - Temporarily disable any third-party sources to rule out conflicts, then retry the installation
- Go to
Repair your Visual Studio installation
Damaged VS components can break NuGet functionality:- Launch the Visual Studio Installer, find your VS2017 Pro instance, and click
Modify - Navigate to
Individual components, locateNuGet package manager—if it’s already checked, uncheck it, clickModify, then re-check it and run the modification again - Wait for the repair to finish, then restart VS
- Launch the Visual Studio Installer, find your VS2017 Pro instance, and click
Install packages via Package Manager Console
If the UI installation fails, try the command line approach:- Open
Tools>NuGet Package Manager>Package Manager Console - Run the command:
Install-Package [YourPackageName](replace[YourPackageName]with the actual package you want to install) - The console will output detailed error messages, which can help pinpoint the exact issue
- Open
Check project file permissions and integrity
Locked or corrupted project files might be the problem:- Close Visual Studio, navigate to your project folder, right-click it and select
Properties—ensure your user account hasRead/Writepermissions - Delete the
packagesfolder and the hidden.vsfolder in your project directory, then reopen the project and try restoring packages again
- Close Visual Studio, navigate to your project folder, right-click it and select
If none of these steps work, please share the exact error message or code you’re seeing—this will let me give you a more targeted solution!
内容的提问来源于stack exchange,提问作者Ankit Verma

