【发布时间】:2020-05-19 02:32:10
【问题描述】:
我有一个 Visual Studio 解决方案,并试图通过 NuGet 在解决方案的单元测试项目中安装 NUnit。即使主应用程序项目的其他 NuGet 包安装正常,我也无法安装它。
最终,我决定使用单个 .NET Core 类库项目创建另一个测试解决方案。除了创建项目时自动包含的空类 Class1 之外,该项目是空的。使用“Manage NuGet Packages for Solution...”窗口,我尝试安装两个包,Newtonsoft.Json 和 NUnit。安装了 Newtonsoft.Json,NUnit 没有。
这是我安装 Newtonsoft.Json 时的输出:
Restoring packages for C:\Temp\Test\Test\Test.csproj...
Installing NuGet package Newtonsoft.Json 12.0.3.
Committing restore...
Writing assets file to disk. Path: C:\Temp\Test\Test\obj\project.assets.json
Successfully installed 'Newtonsoft.Json 12.0.3' to Test
Executing nuget actions took 718.62 ms
Time Elapsed: 00:00:00.7711055
========== Finished ==========
Time Elapsed: 00:00:00.0382855
========== Finished ==========
这是我尝试安装 NUnit 时非常不同的输出:
Restoring packages for C:\Temp\Test\Test\Test.csproj...
GET https://www.nuget.org/api/v2/FindPackagesById()?id='NUnit'&semVerLevel=2.0.0
OK https://www.nuget.org/api/v2/FindPackagesById()?id='NUnit'&semVerLevel=2.0.0 1028ms
GET https://www.nuget.org/api/v2/package/NUnit/3.12.0
GET https://www.nuget.org/api/v2/package/NUnit/3.12.0
GET https://www.nuget.org/api/v2/package/NUnit/3.12.0
GET https://www.nuget.org/api/v2/FindPackagesById()?id='NUnit'&semVerLevel=2.0.0
OK https://www.nuget.org/api/v2/FindPackagesById()?id='NUnit'&semVerLevel=2.0.0 273ms
CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='NUnit'&semVerLevel=2.0.0
CACHE https://www.nuget.org/api/v2/FindPackagesById()?id='NUnit'&semVerLevel=2.0.0
The feed 'nuget.org [https://www.nuget.org/api/v2/]' lists package 'NUnit.3.12.0' but multiple attempts to download the nupkg have failed. The feed is either invalid or required packages were removed while the current operation was in progress. Verify the package exists on the feed and try again.
Unable to find package 'NUnit.3.12.0'.
Time Elapsed: 00:00:04.7743652
========== Finished ==========
这是使用 Visual Studio 2019(版本 16.4.3)。项目目标框架为.NET Core 3.1,输出类型为类库。
我注意到 NuGet.org 上的 NUnit 页面说它支持 .NET Core。通过浏览到上面输出中给出的 URL,我还能够手动下载 NUnit 包,https://www.nuget.org/api/v2/package/NUnit/3.12.0
当我可以将 Newtonsoft.Json 安装到同一个项目中时,有人知道为什么我不能安装 NUnit 吗?
【问题讨论】:
-
尝试清除 NuGet 缓存。 docs.microsoft.com/en-us/nuget/consume-packages/…
-
按照说明清除所有缓存。结果还是一样。
-
您在创建新项目然后安装
NUnit时是否遇到同样的错误?请尝试删除C:\Users\xxxx\AppData\Roaming\NuGet\NuGet.Config下的NuGet.Config文件,然后重新打开VS,恢复nuget包。 -
@PerryQian-MSFT 清除所有 NuGet 缓存,关闭 VS,删除 NuGet.Config,然后重新打开 VS 并重建解决方案就可以了。您想写下您的评论作为答案吗?如果是这样,我会接受的。
标签: visual-studio .net-core nuget nunit