安装Moq 4.8.2包时遇NUnit元数据错误,求解决方法
Let’s work through this issue step by step—this error usually stems from a corrupted local NuGet package source or cached metadata. Here are actionable fixes to get you back on track:
Verify and repair your local NuGet source
The error points to a problem retrieving NUnit 3.10.1 metadata from your localD:\devops\MMS_SVN_7_MAY_2018\packagessource. First, check if the NUnit.3.10.1 package in that directory is corrupted:- Navigate to the packages folder and delete the entire
NUnit.3.10.1directory (or any related.nupkg/.nuspecfiles for that version). - Run the install command again in Package Manager Console:
PM> Install-Package Moq -Version 4.8.2
- Navigate to the packages folder and delete the entire
Clear NuGet’s local cache
Corrupted cached metadata can cause this issue too. Clear all NuGet caches using either method:- Command Line: Open a terminal and run:
nuget locals all -clear - Visual Studio UI: Go to
Tools > NuGet Package Manager > Package Manager Settings, then selectClear All NuGet Cachesunder theNuGet Package Managersection.
- Command Line: Open a terminal and run:
Temporarily switch to the official NuGet source
Your local source might be missing or have invalid package data. Try disabling it temporarily and using the official NuGet Gallery:- List your current package sources in Package Manager Console:
PM> Get-PackageSource - Disable your local source (replace
[Local Source Name]with the actual name from the list):PM> Disable-PackageSource -Name "[Local Source Name]" - Install Moq again, which will pull packages from the official source:
PM> Install-Package Moq -Version 4.8.2 - You can re-enable your local source afterward if needed.
- List your current package sources in Package Manager Console:
Manually install NUnit 3.10.1 first
If the issue persists, install the problematic NUnit version directly before adding Moq:- Run this command in Package Manager Console:
PM> Install-Package NUnit -Version 3.10.1 - Once NUnit installs successfully, run the Moq install command again.
- Run this command in Package Manager Console:
Check permissions and source path
Ensure your user account has read access to theD:\devops\MMS_SVN_7_MAY_2018\packagesdirectory. A permissions issue could prevent NuGet from reading the package metadata correctly.
内容的提问来源于stack exchange,提问作者renu pawar

