簡體   English   中英

缺少對 NuGet 軟件包的引用。 Package 恢復或重新安裝包不起作用

[英]References to NuGet packages that are missing. Package Restore or re-installing packages does not work

在 Visual Studio 解決方案中,有幾個項目應該具有 MSTest.TestAdapter NuGet package 等。 從源代碼管理下載后,解決方案中的每個項目都顯示錯誤:“此項目引用了此計算機上缺少的 NuGet 包。使用 NuGet Package 恢復下載它們”

我曾嘗試使用 NuGet Package Manager 卸載並重新安裝受影響的 package,但無濟於事。 我也嘗試過“包還原”。

解決方案中的每個項目都包含一個packages.config文件,其內容如下:

<?xml version="1.0" encoding="utf-8"?>
<packages>
  <package id="MSTest.TestAdapter" version="2.1.2" targetFramework="net461" />
  <package id="NLog" version="4.7.7" targetFramework="net461" />
</packages>

使用 Visual Studio 2017。

如何解決這個問題?

進入csproj文件,然后刪除這兩行:

<Error Condition="!Exists('xxx\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props')" Text="$([System.String]::Format('$(ErrorText)', 'xx\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.props'))" />
<Error Condition="!Exists('xx\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets')" Text="$([System.String]::Format('$(ErrorText)', 'xx\packages\MSTest.TestAdapter.2.1.2\build\net45\MSTest.TestAdapter.targets'))" />

這兩行仍然基於您的源代碼控制,而不是您的新 VS 環境。 您應該刪除舊的錯誤路徑,然后根據您當前的 VS 環境安裝新路徑。

After that , enter Tools --> Nuget Package Manager --> Package Manager Console and then type this to reinstall all the nuget packages:

update-package -reinstall

暫無
暫無

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

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