Warm tip: This article is reproduced from stackoverflow.com, please click
.net-core nuget nunit visual-studio

Cannot Install NUnit NuGet package but other NuGet packages install fine

发布于 2020-04-13 10:07:47

I have a Visual Studio solution and was trying to install NUnit in the unit test project of the solution via NuGet. I could not get it to install, even though other NuGet packages for the main application project installed fine.

Eventually I decided to create another test solution with a single .NET Core class library project. The project is empty apart from the empty class, Class1, included automatically when the project was created. Using the "Manage NuGet Packages for Solution..." window I tried to install two packages, Newtonsoft.Json and NUnit. Newtonsoft.Json installed, NUnit didn't.

This is the output when I installed 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 ==========

This is the very different output when I attempted to install 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 ==========

This is using Visual Studio 2019 (version 16.4.3). The project target framework is .NET Core 3.1 and the output type is Class Library.

I note the NUnit page on NuGet.org says it supports .NET Core. I was also able to download the NUnit package manually by browsing to the URL given in the output above, https://www.nuget.org/api/v2/package/NUnit/3.12.0

Does anyone have any idea why I can't install NUnit when I can install Newtonsoft.Json into the same project?

Questioner
Simon Tewsi
Viewed
185
Perry Qian-MSFT 2020-02-04 14:27

Does anyone have any idea why I can't install NUnit when I can install Newtonsoft.Json into the same project?

This is an abnormal behavior and when l install the two nuget packages Newtonsoft.Json, NUnit in a Net Core 3.1 ClassLibrary, it works well and did not show any errors.

So please try these steps to troubleshoot your issue:

Solution

1) Clean all the NuGet package cache by the command line: nuget locals all -clear.

2) close the VS Instance, delete NuGet.Config file under C:\Users\xxx(User Name)\AppData\Roaming\NuGet\NuGet.Config, restart VS and then restore nuget packages.

3) check if there is a firewall policy or other proxy settings that block the nuget installation package.

Hope it could help you.