I try to add .NET Framework 4.5 my own dll to .NET Core Project but I can't. I also try to change something in project.json file but without result. I also try to make custom local Nuget source but it don't work for me. can anyone know right explanation how can I do this ?
-
The message doesn't refere to 4.5 at all. .NET Core and .NET Framework 4.5 are different target platforms. You can't "import" one into the other as if they were libraries. What it says is that you can't add a reference to any assembly except those packaged with .NET Core itself. You'll have to package your library in a Nuget package then add the package to your projectPanagiotis Kanavos– Panagiotis Kanavos2016-09-15 11:57:05 +00:00Commented Sep 15, 2016 at 11:57
-
Is Dea.Html another .NET Core library ?Panagiotis Kanavos– Panagiotis Kanavos2016-09-15 12:00:38 +00:00Commented Sep 15, 2016 at 12:00
1 Answer
Update
As of .NET Core 2.0, this can now be done: https://blogs.msdn.microsoft.com/dotnet/2017/08/14/announcing-net-core-2-0/#reference-net-framework-libraries-from-net-standard
You can't reference a .NET Framework 4.5 assembly in a .NET Core project, only other .NET Core assemblies.
If you want to use ASP.NET Core 1 and still be able to reference .NET "Full" assemblies, you have to create a ASP.NET application that targets the .NET Framework instead of .NET Core. You can do this by going to Create a new Project -> Visual C# -> Web -> ASP.NET Core Web Application (.NET Framework).
You can also change your project.json file to reference the full .NET Framework, like this:
"frameworks": {
"net461": { }
}
Also, if you're willing to write platform-specific code and use pre-compiler directives, you can target multiple frameworks on a single app.
To do that, simply add net461 to your existing app, alongside netcoreapp1.0. Note, though, that you'll have to specify your dependencies for each framework. So your project.json file will look something like this:
"frameworks": {
"netcoreapp1.0": {
"dependencies": {
"Microsoft.NETCore.App": { "type":"platform", "version": "1.0.0" }
},
"imports": "dnxcore50"
}
"net461": {
"dependencies": {"MyNet45Assembly"}
}
}
And then on your code you'll have to use pre-compiler directives to detect under which platform your app is running. For example:
#if NET461
using MyNet45Assembly.Types;
#endif
// ...
#if NET461
var v = new MyNet45AssemblyType();
#endif
