从类库项目托管ASP.NET CORE 2

时间:2018-09-25 12:04:04

标签: c# asp.net-core

我需要从类库项目(目标4.7.2)中的一个类创建ASP.NET CORE 2.1 Web API。

我添加了对Microsoft.AspNetCore和Microsoft.AspNetCore.Mvc.Core的引用。

以下呼叫引发异常:

 CreateWebHostBuilder().Build().Run();      
  

无法加载文件或程序集“ System.Runtime.InteropServices.RuntimeInformation,版本= 4.0.2.0,区域性=中性,PublicKeyToken = b03f5f7f11d50a3a”或其依赖项之一。系统找不到指定的文件。

输出窗口:

Exception thrown: 'System.IO.FileNotFoundException' in Microsoft.Extensions.DependencyInjection.dll
An exception of type 'System.IO.FileNotFoundException' occurred in Microsoft.Extensions.DependencyInjection.dll but was not handled in user code
Could not load file or assembly 'System.Runtime.InteropServices.RuntimeInformation, Version=4.0.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' or one of its dependencies. The system cannot find the file specified.

我尝试手动添加System.Runtime.InteropServices.RuntimeInformation参考,但没有成功。

我在这里想念东西吗?

1 个答案:

答案 0 :(得分:1)

如果您已将引用添加为nuget pakage,则可以尝试在csproj中添加此属性组:

<PropertyGroup>
<CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies> </PropertyGroup>

此属性将在输出目录中复制nuget dll,而不是使用nuget内存缓存中的dll。 如果您的解决方案中有很多项目引用了同一软件包的不同版本(也有相关的依赖项),则可以为您提供帮助。

如果已将引用作为简单的“引用”添加到已知dll,则应确认该dll在输出目录中。还要验证该dll的版本。如果不同,并且dll参考引用了严格的版本,则可能是一个问题。

相关问题