无法安装 NUnit NuGet 包,但其他 NuGet 包安装正常
Cannot Install NUnit NuGet package but other NuGet packages install fine
我有一个 Visual Studio 解决方案,并试图通过 NuGet 在该解决方案的单元测试项目中安装 NUnit。我无法安装它,即使主应用程序项目的其他 NuGet 包安装正常。
最终我决定使用单个 .NET Core class 库项目创建另一个测试解决方案。除了空的 class, Class1 之外,该项目是空的,在创建项目时自动包含。使用 "Manage NuGet Packages for Solution..." window 我尝试安装两个包,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,输出类型是Class Library.
我注意到 NuGet.org 上的 NUnit 页面说它支持 .NET Core。我还可以通过浏览到上面输出中给出的 URL https://www.nuget.org/api/v2/package/NUnit/3.12.0
来手动下载 NUnit 包
有人知道为什么我可以将 Newtonsoft.Json 安装到同一个项目中却无法安装 NUnit 吗?
Does anyone have any idea why I can't install NUnit when I can install
Newtonsoft.Json into the same project?
这是一个异常行为,当我在 Net Core 3.1 ClassLibrary 中安装两个 nuget 包 Newtonsoft.Json
、NUnit
时,它运行良好并且没有显示任何错误。
因此,请尝试以下步骤来解决您的问题:
解决方案
1) 通过命令行清除所有 NuGet 包缓存:nuget locals all -clear
.
2)关闭VS实例,删除C:\Users\xxx(User Name)\AppData\Roaming\NuGet\NuGet.Config
下的NuGet.Config文件,重启VS,然后恢复nuget包。
3)检查是否有防火墙策略或其他代理设置阻止了nuget安装包。
希望对您有所帮助。
我有一个 Visual Studio 解决方案,并试图通过 NuGet 在该解决方案的单元测试项目中安装 NUnit。我无法安装它,即使主应用程序项目的其他 NuGet 包安装正常。
最终我决定使用单个 .NET Core class 库项目创建另一个测试解决方案。除了空的 class, Class1 之外,该项目是空的,在创建项目时自动包含。使用 "Manage NuGet Packages for Solution..." window 我尝试安装两个包,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,输出类型是Class Library.
我注意到 NuGet.org 上的 NUnit 页面说它支持 .NET Core。我还可以通过浏览到上面输出中给出的 URL https://www.nuget.org/api/v2/package/NUnit/3.12.0
来手动下载 NUnit 包有人知道为什么我可以将 Newtonsoft.Json 安装到同一个项目中却无法安装 NUnit 吗?
Does anyone have any idea why I can't install NUnit when I can install Newtonsoft.Json into the same project?
这是一个异常行为,当我在 Net Core 3.1 ClassLibrary 中安装两个 nuget 包 Newtonsoft.Json
、NUnit
时,它运行良好并且没有显示任何错误。
因此,请尝试以下步骤来解决您的问题:
解决方案
1) 通过命令行清除所有 NuGet 包缓存:nuget locals all -clear
.
2)关闭VS实例,删除C:\Users\xxx(User Name)\AppData\Roaming\NuGet\NuGet.Config
下的NuGet.Config文件,重启VS,然后恢复nuget包。
3)检查是否有防火墙策略或其他代理设置阻止了nuget安装包。
希望对您有所帮助。