簡體   English   中英

NuGet package 因“無法加載文件或程序集”而中斷

[英]NuGet package breaks with "Could not load file or assembly"

我有 NuGet package (.Net Standard 2.0),它通過 PackageReference 引用了Newtonsoft.Json v13.0.1 (所謂的新方法)。 打包時一切看起來都很好。 在 VSIX 項目中安裝表明Newtonsoft也將被下載並成功構建。 當 VSIX 項目 (.Net Full 4.8) 運行並且使用 Newtonsoft 的方法中斷並顯示消息Could not load file or assembly 'Newtonsoft.JSON, Version=13.0.0.0, ...' or one of its dependencies. The system cannot find the file specified. Could not load file or assembly 'Newtonsoft.JSON, Version=13.0.0.0, ...' or one of its dependencies. The system cannot find the file specified.

我嘗試了不同的方法(都沒有用):

  • 手動將Newtonsoft.Json.dll復制到下載的 package 中的 libs 文件夾中。
  • 強制在 VSIX 項目中安裝Newtonsoft.JSON

可以在此處找到 NuGet 項目,在此處找到 VSIX 項目。

有任何想法嗎?

更新:

我已經從Newtonsoft更改為System.Text.Json進行嘗試,但錯誤沒有改變。

所以從錯誤消息來看,問題是NuGet package,相關文件或依賴項無法找到/加載。 所以原因應該是具體的NuGet package不存在,或者不在具體的文件夾/目錄,或者沒有指出路徑。 或者同一個NuGet包有幾個不同版本混合使用。

由於不確定您的項目/解決方案結構,我假設您有一個基於 .net 標准的項目,並將其打包到 NuGet package 中。您還將它安裝在 VSIX 項目中,並且在此 VSIX 項目中,您使用了 Newtonsoft 的方法.json NuGet package 在您的 .net 標准項目中引用。

您可以嘗試的第一件事是手動復制正確版本的 Newtonsoft.Json.dll(通常在C:\Users\[user name]\.nuget\packages\newtonsoft.json\13.0.1\lib\... )到你的 VSIX 項目文件夾。 VSIX 項目文件夾目錄應該是這樣XXXX\XXXX\[your project folder name]\bin\Debug(or Release, depend on which mode you are using)

其他建議:

Go 到工具 > 選項 > NuGet Package 管理器 > 常規 > 單擊並選中Allow NuGet to download missing packagesAutomatically check for missing packages during build in Visual Studio ,然后單擊Clear All NuGet Cache(s)按鈕 > 確定。 之后重建並重新運行您的 VSIX 項目。

如果以上不起作用,能否請您與我分享一些步驟來重現您的問題並進一步檢查:)

暫無
暫無

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

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