.net core app target .net framework 4.5.2 on Linux
Asked Answered
R

1

4

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.

Repute answered 9/5, 2017 at 16:17 Comment(2)
The quote actually talks about code where the Windows specific part is included in a conditional compilation statement #if NET452.Daubery
not every words of a blog post can be fully trusted. With official documentation like this, you don't need to waste too much time, learn.microsoft.com/en-us/dotnet/articles/standard/…Lecce
H
10

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
  • .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
Hypaethral answered 9/5, 2017 at 17:12 Comment(1)
This answered 6 questions I had immediately, after plenty of MSDN and Google inquiries. Much thanks! .NET Core for me it is ;)Orangutan

© 2022 - 2024 — McMap. All rights reserved.