简体   繁体   中英

.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. 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'

The code is simple and is just calling an async method in the .NET Core lib. A bit like:

return _dotNetCoreClass.MethodAsync();

I've tried upgrading the project so it uses ProjectReferences and not packages.config. I've installed the System.Runtime package (version 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.

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).

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.

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.

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:

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 . By accident this issue does not repro with Visual Studio 15.5 release. 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 .

For the moment, there is no way to fix your solution as 4.7.1 cannot support .Net Core.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM