简体   繁体   English

.NET 4.7.1项目不能使用.NET Core 2.0库

[英].NET 4.7.1 project can't use .NET Core 2.0 library

I've searched a lot and can't find a solution to my problem (I've seen similar runtime issues but not build). 我搜索了很多,找不到我的问题的解决方案(我已经看到类似的运行时问题,但没有构建)。

I have a .NET 4.7.1 project (class lib) that references a .NET Core project/library. 我有一个.NET 4.7.1项目(类lib),它引用了.NET Core项目/库。 When I try to build I get the following build error: 当我尝试构建时,我得到以下构建错误:

'System.Runtime, Version=4.2.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' which has a higher version than referenced assembly 'System.Runtime' with identity 'System.Runtime, Version=4.1.2.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a' 'System.Runtime,Version = 4.2.0.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a',其版本高于引用的程序集'System.Runtime',其标识为'System.Runtime,Version = 4.1.2.0,Culture = neutral,PublicKeyToken = b03f5f7f11d50a3a”

The code is simple and is just calling an async method in the .NET Core lib. 代码很简单,只是在.NET Core lib中调用异步方法。 A bit like: 有一点像:

return _dotNetCoreClass.MethodAsync();

I've tried upgrading the project so it uses ProjectReferences and not packages.config. 我已经尝试升级项目,因此它使用ProjectReferences而不是packages.config。 I've installed the System.Runtime package (version 4.3.0). 我已经安装了System.Runtime包(版本4.3.0)。 I've updated my project file to include the below: 我已更新我的项目文件以包含以下内容:

<AutoGenerateBindingRedirects>true</AutoGenerateBindingRedirects> <GenerateBindingRedirectsOutputType>true</GenerateBindingRedirectsOutputType>

I've also installed the latest NETStandard.Librabry package but I can't get rid of the build error. 我还安装了最新的NETStandard.Librabry包但我无法摆脱构建错误。

I thought it was important to post the solution I found and to highlight where my understanding went wrong (thanks to @jeroen-mostert and @hans-passant for steering me in the right direction). 我认为发布我找到的解决方案很重要,并强调我的理解出错了(感谢@ jeroen-mostert和@ hans-passant指导我正确的方向)。

Not all of the .NET Core 2.0 framework is supported by .NET 4.7.1 and so some of the code we were using was not supported and hence raised a build error in application referencing the .NET Core library. 并非所有.NET Core 2.0框架都受.NET 4.7.1支持,因此我们使用的一些代码不受支持,因此在引用.NET Core库的应用程序中引发了构建错误。

Changing the .NET Core library to use .NET Standard 2.0 (which is fine because our other .NET Core applications that will also use the library are supported by .NET Standard) and then removing and re-adding the references in the application using it solved our problems and the application now builds. 更改.NET Core库以使用.NET Standard 2.0(这很好,因为我们的其他.NET Core应用程序也将使用该库由.NET Standard支持),然后使用它删除并重新添加应用程序中的引用解决了我们的问题,现在应用程序构建。

There is an issue tracked on git hub regarding the .Net Core SDK at the moment, as stated at the official .Net framework 4.7.1 disucssion: 目前正在git hub上跟踪关于.Net Core SDK的问题,如官方.Net框架4.7.1所述:

It turns out there is an issue with .NET Core SDK, the issue is being tracked on GitHub, https://github.com/dotnet/sdk/issues/1738 . 事实证明.NET Core SDK存在问题,该问题正在GitHub上进行跟踪, https://github.com/dotnet/sdk/issues/1738 By accident this issue does not repro with Visual Studio 15.5 release. 这个问题不会在Visual Studio 15.5版本中重现。 If anybody would like to see if there is any workaround before the SDK issue is fixed, feel free to file an issue on https://github.com/aspnet/Mvc/issues . 如果有人想在修复SDK问题之前查看是否有任何解决方法,请随时在https://github.com/aspnet/Mvc/issues上提交问题。

For the moment, there is no way to fix your solution as 4.7.1 cannot support .Net Core. 目前,无法修复您的解决方案,因为4.7.1无法支持.Net Core。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 C# 项目需要 .NET 4.7.1 但我无法安装 - C# project wants .NET 4.7.1 but I can't install it ASP.NET Core项目无法引用具有简化的csproj格式的.NET 4.7.2类库 - .NET 4.7.2 Class Library with simplified csproj format can't be referenced by ASP.NET Core project 无法将 Entity Framework Core 迁移添加到 .NET 标准 2.0 项目 - Can't add Entity Framework Core migrations to .NET Standard 2.0 project 如何在.net 2.0项目中使用.net 3.0类? - How can I use .net 3.0 class in .net 2.0 project? 从 .NET Core 2.1 降级到 .NET 4.7.1 时如何使用 IApplicationBuilder 和 IServiceCollection? - How to use IApplicationBuilder and IServiceCollection when downgrading from .NET Core 2.1 to .NET 4.7.1? 无法将依赖项添加到.NET核心项目 - Can't add dependencies to a .NET core project 尽管我具有.NET core 2.2,但如何打开.NET core 2.0 mvc项目? - How can I open a .NET core 2.0 mvc project despite that I have .NET core 2.2? 如何在 .NET Core 2.0 中包含一个库 - How to include a library in .NET Core 2.0 读取.NET Core 2.0库中的配置设置 - Reading configuration settings in .NET Core 2.0 library .net 标准 2.0 库中的 EF Core DbContext - EF Core DbContext in .net standard 2.0 library
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM