我有一个Visual Studio解决方案,并想通过NuGet在解决方案的单元测试项目中安装NUnit。即使主应用程序项目的其他NuGet软件包安装得很好,我也无法安装它。
最终,我决定用一个.NET Core类库项目创建另一个测试解决方案。除了创建项目时自动包含的空类Class1外,该项目是空的。使用“管理解决方案的NuGet软件包...”窗口,我尝试安装两个软件包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吗?
有人知道将Newtonsoft.Json安装到同一项目中时为什么不能安装NUnit吗?
这是一种不正常的行为,当升安装这两个包的NuGet Newtonsoft.Json
,NUnit
在网络核心3.1 ClassLibrary,它运作良好,并没有表现出任何错误。
因此,请尝试执行以下步骤来解决您的问题:
解
1)通过命令行清理所有的NuGet包缓存nuget locals all -clear
。
2)关闭VS实例,删除下的NuGet.Config文件C:\Users\xxx(User Name)\AppData\Roaming\NuGet\NuGet.Config
,重启VS,然后还原nuget包。
3)检查是否存在阻止nuget安装软件包的防火墙策略或其他代理设置。
希望它能对您有所帮助。
这完美地完成了窍门。谢谢。