簡體   English   中英

為什么 nuget dll 顯示在 Visual Studio 2019 的項目根目錄中?

[英]Why the nuget dll shows in project root in Visual Studio 2019?

我的解決方案中有一個 SDK 項目。 我需要添加一個 NuGet package(“customLib.net”),它提供了查找文件之間差異的功能。

如果您創建一個簡單的.Net Framework 4.7.2控制台應用程序並將此 NuGet 添加到其中,那么它將自動下載它以及所有依賴項,包括“customLib.redist.windows.x64”。 據我了解,“customLib.net.dll”是 .net 的 API 和“customLib.dll” (來自“customLib.redist.Z0F4137ED1502B5045D6083AA258B5C42”包本身是引擎,編譯為win-x64包) package 存儲在SolutionFolder/packages中。 還有一個package.config文件,其中包含所有必需的參考資料。 一切都按預期工作。

But if to add the same NuGet package to SDK (Class Library) project, which has the same target: .Net Framework 4.7.2 , it should also download the NuGet package along with all dependencies. 它確實如此。 但它不會將包存儲在SolutionFolder/packages文件夾中,並且沒有任何package.config文件。 它將它們存儲在 C 驅動器上的全局 NuGet 存儲中。 問題是,當我啟動應用程序時,它會在運行時引發異常

"Unable to load DLL 'customLib': The specified module could not be found.". 

而這個 dll 在 output 文件夾中不存在。 I solved this issue by downloading the "customLib.redist.windows.x64" NuGet package to the project, despite the fact that "customLib.net" already has a reference to this package. 這對我來說有點奇怪,這里有幾個問題:

  1. 為什么,如果“customLib.net”依賴於“customLib.redist.windows.x64” ,它不會將依賴的 dll 復制到 Z78E6221F6393D1356681DB398F14CEDZ 文件夾? 同時,控制台應用程序復制這兩個庫。
  2. Why after downloading "customLib.redist.windows.x64" NuGet the "customLib.dll" file shows in my project root in Visual Studio with full path to "C:\Users\MyUsr\.nuget\packages\customLib.redist.windows .x64\1.0.1\runtimes\win-x64"?

根據描述,我可以假設您擁有 .NET 標准控制台應用程序,但您將.Net core class 庫添加到其中。 這就是您面臨此類問題的原因。

因為在.NET核心庫項目中,沒有package.config文件,直接在csproj文件中添加了引用。 以及下載到用戶目錄的包,而不是包文件夾。

因此,您需要將 .NET 標准 class 庫添加到您的項目中,而不是添加 .Net 核心庫

要了解更多信息,請參閱.NET Core 和 .NET 標准 Class 庫項目類型之間的區別是什么?

暫無
暫無

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

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