Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

.net core app target .net framework 4.5.2 on Linux

I wanted to understand the dot net core support a bit more. My basic understanding was that if I wanted to run a .net app on Linux then it needs to be built .net core and targeted netcoreapp1.0 framework to guarantee this. 1) I assume the above assumption is correct?

2) When I was reading various articles online, such as this one about referencing exiting .net framework project within a .net core application (https://www.hanselman.com/blog/HowToReferenceAnExistingNETFrameworkProjectInAnASPNETCore10WebApp.aspx) If I did this, presumably the app would only run on Windows and not Linux?

3) In the following article: https://blogs.msdn.microsoft.com/cesardelatorre/2016/06/28/running-net-core-apps-on-multiple-frameworks-and-what-the-target-framework-monikers-tfms-are-about/ In context to running with .net run 4.5.2 option ( dotnet run -f NET452), it's mentioned:

If this app were running on the .NET Core Platform, let’s say on a Linux box or a Mac, this code won’t be executed, but the app would still be running on Linux or MacOS.

What's the distinction between running and not executing? If my initial understanding was correct, then by running with .net 4.5.2 option on Linux I wouldn't expect the app not to run at all.

Appreciate a few questions there but really wanted to understand .net core a bit more.

like image 271
Rubans Avatar asked Dec 23 '22 18:12

Rubans


1 Answers

There is a difference between .NET Core and ASP.NET Core and the articles you mentioned are about running ASP.NET Core "apps" on .NET Framework. Let my try to clarify this using a few declarative statements:

  • .NET Core is the cross-platform runtime.
  • ASP.NET Core is a set of libraries that until version 1.1.* can run on both .NET Framework and .NET Core.
  • This means you can create a .NET Framework application (=> e.g. net452) and use ASP.NET Corein this application.
  • The CLI tooling works for both projects targeting netcoreapp* and net* - but net* currently only works on windows.

This means that for netcoreapp1.*, you cannot reference arbitrary libraries that have been built for .NET Framework. If you change the target framework to say net452, you are no longer building a .net core application, but a .net framework application.

For ASP.NET Core 2.0 this is going to change. Again a few statements:

  • ASP.NET Core 2.0 is still a set of libraries but they can only be used on .NET Core 2.0 and not on .NET Framework
    • Do note that this is still under discussion at the time of writing: https://github.com/aspnet/Home/issues/2022
  • .NET Core 2.0 is able to freely reference libraries that have been built for .NET Framework up to version 4.6.1
    • However, some libraries may fail at run time if they try to use API methods that aren't available on .NET Core
like image 179
Martin Ullrich Avatar answered Jan 22 '23 15:01

Martin Ullrich