无法安装NUnit NuGet软件包,但其他NuGet软件包也可以很好安装

问题描述 投票:0回答:1

我有一个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。通过浏览到上面输出https://www.nuget.org/api/v2/package/NUnit/3.12.0

中给出的URL,我还能够手动下载NUnit软件包。

有人能将Ne​​wtonsoft.Json安装到同一项目中,为什么我不能安装NUnit吗?

visual-studio .net-core nuget nunit
1个回答
0
投票

没有人知道为什么我可以在安装时无法安装NUnitNewtonsoft.Json进入了同一项目吗?

这是异常行为,当我在Net Core 3.1 ClassLibrary中安装两个nuget程序包Newtonsoft.JsonNUnit时,它运行良好,并且没有显示任何错误。

因此,请尝试执行以下步骤来解决您的问题:

解决方案>>

[1)

通过命令行nuget locals all -clear清理所有NuGet程序包缓存。

[2)关闭VS实例,删除C:\Users\xxx(User Name)\AppData\Roaming\NuGet\NuGet.Config下的NuGet.Config文件,重新启动VS,然后还原nuget程序包。

3)检查是否存在阻止nuget安装软件包的防火墙策略或其他代理设置。

希望它可以帮助您。

© www.soinside.com 2019 - 2024. All rights reserved.