我确实有一个 ASP.NET MVC Core 应用程序,并且想在我的项目中添加一个类库。 我通过“添加引用”>“浏览”> 选择 DLL 将其添加到我的项目中。
我将其添加到代码中,例如
using PagarMe; // works good on code
我能够编译并运行该应用程序。但是,当用户转到引用该库的页面时,我收到以下错误:
FileNotFoundException: Could not load file or assembly 'PagarMe.Pcl, Version=2.0.6372.16631, Culture=neutral, PublicKeyToken=null'. The system cannot find the file specified.
我已经做了什么。
- 我检查了输出 bin 文件夹,Dll 文件就在那里。
- 这两个 DLL 都是使用“任何 CPU”配置编译的。
- 我尝试了 PCL 和非 PCL 版本。
- 应用目标框架:.NETCoreApp 1.1
- 默认类库目标框架:.Net Framework 4.5。
- 可移植 (PCL) 类库目标框架:.Net Framework 4.5 和 ASP.Net Core 1.0
如何才能在我的核心应用程序中使用类库或 PCL 库?
最佳答案
在 .NET Core 中,您不再使用可移植类库,但您的目标是 .NET Standard Library 的正确版本。 。某些 PCL 或共享类可能会使用一些不受支持的 引用。
要解决此问题,请尝试以下方法之一:
<强>1。重新构建您的类库以针对 .NET Standard。例如,.NET Standard 1.6 受 .NET Core 1.0 和 .NET Framework 4.6.1 支持。
.NET Standard can be thought of as the next generation of Portable Class Libraries (PCL). The .NET Standard improves on the experience of creating portable libraries by curating a standard BCL and establishing greater uniformity across .NET runtimes as a result. A library that targets .NET Standard is a PCL or a ".NET Standard-based PCL". Existing PCLs are "profile-based PCLs". (Taken from the documentation)
<强>2。将您的应用程序定位到 .NET Framework。 您可以构建一个 ASP.NET Core 应用程序来针对完整的 .NET Framework 而不仅仅是 .NET Core。这为您提供了 ASP.NET Core 的优势,而不受 .NET Core 的限制。
ASP.NET Core != .NET Core
关于c# - 添加类库程序集后出现 FileNotFoundException,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/44499572/