【发布时间】:2019-08-20 10:02:57
【问题描述】:
我的 .Net Core Web API 中出现 System.IO.FileNotFoundException。所以我设置了下面的项目来演示这个问题。
我创建了一个名为 DemoLibrary 的.Net 标准库,并通过 NuGet 添加了 QRCoder 依赖项。
免责声明:选择 QRCoder 的原因是 Web API 默认不使用它。我不在我的项目中使用它。事实上,我得到了 EntityFrameworkCore 的这个例外。
我创建了一个没有其他依赖项的新 .Net Core Web API DemoWebAPI。
然后通过 Add Reference -> Browse -> DemoLibrary.dll 将 DemoLibrary 添加到 DemoWebAPI。
这是我的解决方案:
Calculate 类中的 DemoMethod 方法只是创建了 QRCodeGenerator 的对象。
public class Calculate
{
public static string DemoMethod()
{
QRCodeGenerator qrGenerator = new QRCodeGenerator();
return "";
}
}
而我在 DemoWebAPI 中的 ValuesController 只是调用了方法:
[HttpGet]
public ActionResult<IEnumerable<string>> Get()
{
return new string[] { "value1", "value2", DemoLibrary.Calculate.DemoMethod() };
}
现在,当我运行 DemoWebAPI 项目时,调用 DemoMethod 时出现以下异常:
System.IO.FileNotFoundException:'无法加载文件或程序集'QRCoder,版本 = 1.3.5.0,文化 = 中性,PublicKeyToken = null'。系统找不到指定的文件。'
我明白我必须将 QRCoder.dll 文件复制到某处。但我不明白该放在哪里。我已经尝试将其放入 DemoWebAPI 的 "bin/debug/netcoreapp2.2" 和 DemoLibrary 的 "bin/debug/netstandard2.0" 中。 p>
但我无法让它工作。
请求:请尽可能详细地发布您的答案,因为我是 .Net Core 的新手。
编辑: 我知道 NuGet 服务器。我已经阅读了诸如在 IIS 和 Azure 中托管 NuGet 服务器之类的主题。 DLL 引用背后的原因是我想在两个项目中使用我的 DLL,其中一个是 .net 核心 API,另一个是由 NMAKE 编译的 .net 框架类库。我找不到任何方法来恢复 .MAK 文件中的 NuGet 包。
【问题讨论】:
标签: asp.net-core .net-core asp.net-core-2.0 asp.net-core-webapi nuget-package