Reputation: 501
I've been bashing my head trying to create a new project that's entirely .NET Core, a project that is runnable in different environments, but I need to add as references a lot of my previous projects that work in strict .NET Framework (4.5).
So far what I've been able to do was add the .NET 461 framework to project json,
"frameworks": {
"netcoreapp1.0": {
"imports": [
"dotnet5.6",
"portable-net45+win8"
],
"dependencies": {
"Microsoft.NETCore.App": {
"version": "1.0.1",
"type": "platform"
},
"Niloosoft.Hunter.ServicesDataAPI": {
"target": "project"
}
}
},
"net461": { }
}
It succeeded in restoring packages and I even managed to add .NET framework references, but I can't seem to use them properly and I get this error.
So, my question is, is it currently possible to use my .NET Framework references without swapping the expected framework (as I want interoperability) with the following:
> #if NET45
//specific code for .NET 4.5
> #
Something to take note of, my projects are not supported by .NETCoreApp, so, I do need the .NET Framework I'm afraid, I just need to know if what I'm trying to do is possible.
Upvotes: 4
Views: 2377
Reputation: 64278
No, you can't run libraries that target .NET 4.5 only in .NET Core. You can only use libraries which target netstandard1.x
or netcoreapp1.x
(as well as older libraries which target dnxcore5.0
, dotnet5.x
(which was deprecated in favor of netstandard1.x
and dnx being abandoned in favor of dotnet cli).
However you may be able to use PCL which target .NET 4.5 and Windows Phone 8.x or Windows 8.x, because their API surface is much smaller and only has APIs that work on both Windows 8.x/Windows Phone 8.x and on .NET 4.5+ (which means: It uses System.Runtime
, which .NET Core is based on).
If your libraries aren't PCL with .NET 4.5+Win8 or higher, then you'll have to look for replacement libraries and use #if
directives or target net451/net461
only and run against mono, no .NET Core then.
Upvotes: 6