簡體   English   中英

無法安裝 NUnit NuGet 包,但其他 NuGet 包安裝正常

[英]Cannot Install NUnit NuGet package but other NuGet packages install fine

我有一個 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?

當我可以將 Newtonsoft.Json 安裝到同一個項目中時,有沒有人知道為什么我不能安裝 NUnit?

這是一種異常行為,當我在 Net Core 3.1 ClassLibrary 中安裝兩個 nuget 包Newtonsoft.JsonNUnit時,它運行良好並且沒有顯示任何錯誤。

因此,請嘗試以下步驟來解決您的問題:

解決方案

1)通過命令行清除所有 NuGet 包緩存: nuget locals all -clear

2)關閉VS實例,刪除C:\\Users\\xxx(User Name)\\AppData\\Roaming\\NuGet\\NuGet.Config ,重啟VS,然后恢復nuget包。

3)檢查是否有防火牆策略或其他代理設置阻止nuget安裝包。

希望能幫到你。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM