Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Running .NET Standard binaries on different frameworks

I understand targeting .NET Standard 2 means that the frameworks between .net core, mono and the full .net framework, but I'd like to understand what that means for the binaries created by the different frameworks.

So if I create a console program targeting .NET Standard 2 and compile using .NET Framework, can only the full .NET Framework run this file? If they can all run the files, how would I run the .NET Core .dll executable console using the full framework or Mono?

So basically are the binaries created by each framework (targeting .NET Standard) able to run using the other frameworks?

like image 492
Mladen Mihajlovic Avatar asked Feb 16 '18 07:02

Mladen Mihajlovic


People also ask

Is .NET Framework compatible with .NET standard?

NET Core tools for Visual Studio 2015 if you cannot upgrade to Visual Studio 2017 or a later version. . NET Framework doesn't support . NET Standard 2.1.

Can you have multiple .NET frameworks installed?

Microsoft designed the . NET Framework so that multiple versions of the framework can be installed and used at the same time. This means that there will be no conflict if multiple applications install different versions of the . NET framework on a single computer.

Is .NET standard cross-platform?

. NET Standard is platform-agnostic, it can run anywhere, on Windows, Mac, Linux and so on. PCLs can also run cross-platform, but they have a more limited reach. PCLs can only target a limited set of platforms.

Is .NET 4.8 Framework backwards compatible?

NET Framework 4.5 and later versions are backward-compatible with apps that were built with earlier versions of the . NET Framework. In other words, apps and components built with previous versions will work without modification on the . NET Framework 4.5 and later versions.


1 Answers

I believe the Comparison to Portable Class Libraries section probably says it best:

.NET Standard is the replacement for Portable Class Libraries (PCL).

.NET Standard is not itself a runtime it is a type forwarding mechanism for multiple different runtimes. Therefore, it is not possible to create anything but a non-executable class library in .NET Standard, just as was the case with PCLs.

This enables the class library to be consumed by executable assemblies that target specific runtimes (.NET Framework, .NET Core, Xamarin.iOS, Mono, etc).

It is helpful to think of this in terms of classes and interfaces. In pseudo-code, .NET Standard is an interface that .NET Framework and .NET Core implement.

public interface INetStandard
{
    // Only has API definitions
}

public class NetFramework : INetStandard
{
    // .NET Framework Runtime implemented here
}

public class NetCore : INetStandard
{
    // .NET Core Runtime implemented here
}

This makes it possible to use .NET Standard with either .NET Framework or .NET Core, but .NET Standard itself has no runtime, only a set of APIs that can be shared between runtimes. You can target any one of the three with your project, but you can't execute .NET Standard any more than you can instantiate an interface.

Unfortunately, you are not the first to have asked about this and unless Microsoft makes the documentation more clear that .NET Standard does not actually execute, you likely won't be the last.

like image 152
NightOwl888 Avatar answered Nov 10 '22 19:11

NightOwl888