简体   繁体   中英

Mixing .Net Framework app with .Net Core library

In a Visual Studio solution, I need to have a desktop winforms application project (.Net framework 4.0) depending on a .Net Core library project. I can't migrate the application to .Net core yet, but I need functionalities from .Net core (ie Microsoft.EntityFrameworkCore). That's why I created a new project as a dependency.

It seems to cause a problem at build time:

Reference to type 'Object' claims it is defined in 'System.Runtime', but it could not be found

Idem with DateTime , Enum , Decimal , ...

As if object wasn't the same in both project. I tried to use Microsoft.Windows.Compatibility but it doesn't seem to be a solution.

Is there a way to have both projects build and run together?

EDIT 1

I tried with a .Net standard project instead of .Net core, but in this case I can't even add a reference from .Net framework app to .Net standard library.

Project "Std.csproj" targets "netstandard2.0", it can't be referenced by a project that targets ".NetFramework,Version=v4.0"

EDIT 2

I still get the same error with my dependency in .Net core 2.0 and my app in .Net Framework 4.6:

Project "Std.csproj" targets "netstandard2.0", it can't be referenced by a project that targets ".NetFramework,Version=v4.6"

EDIT 3

I finally got rid of the error with .Net Framework 4.6.1. But, according to required configuration for this framework, it means I can't deploy to Windows XP anymore. To study...

As my goal is to migrate gradually to .Net Core, any advice is welcome.

The .net version must be at least 4.6 in order to be able to reference a .net standard project or nuget package. Extra cavat only from visual studio 2017 or newer you'll be able to reference this. Visual studio 2015 will not work.

I need to have a [...] .Net framework 4.0 depending on a .Net Core library project.

Is there a way to have both projects build and run together?

No

Sorry. That's not the way it works. You cannot directly reference a .NET Framework assembly from .NET Core or the other way round a .NET Core assembly from .NET Framework.

(I have a slight deja vu, I will try to find the duplicate on this).

What you can do is create a shared assembly in .NET Standard that both can reference, but in this case it would not actually help you, because you would need a higher .NET Framework version to be able to use .NET Standard 2.0.

What would work is creating a connection between your assemblies that is not a direct assembly binding via reference. One could call the other via REST over HTTP or via memory mapped files or in any other way that you would use to have two otherwise incompatible technologies communicate.

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