Project targeting multiple framework in .NET

Edit the .csproj file to support the target frameworks; for example change.

<TargetFramework>netcoreapp2.1</TargetFramework>
to:
<TargetFrameworks>netcoreapp2.1;net45</TargetFrameworks>

Make sure that you change the XML element changed from singular to plural (add the “s” to both the open and close tags).

Resources

https://docs.microsoft.com/en-us/nuget/create-packages/multiple-target-frameworks-project-file

Clarification on development framework in .NET

This always confuses me. Here is the summary;

  • .NET Framework – the original .NET, the one that ships on Windows and only on Windows; the current (and probably final) version of .NET Framework is 4.8
  • .NET Core – the evolution of .NET, that is not tied to the OS as much, with slightly different feature sets, and where most of the Microsoft .NET effort has been for the last few years; .NET Core 3.1 shipped recently
  • .NET Standard – an API definition (not implementation – akin to an interface) that allows a library to target a range of platforms in a single build, i.e. by targeting .NET Standard 2.0 a library can in theory run equivalently on .NET Core 3 and .NET Framework 4.6.2 (ish…) and others (Mono, Unity, etc), without needing to target each individually
  • .NET 5 – the next version of .NET Core; the naming deliberately emphasizes that there isn’t a two-pronged development future consisting of “Framework” and “Core”, but just one – this one – which isn’t “Core” in the “minimal” sense, but is in fact now a very rich and powerful runtime; .NET 4 was avoided to prevent versioning confusion between .NET 4.* and .NET Framework 4.* (and again, to emphasize that this is the future direction of .NET, including if you are currently on .NET Framework)

Sharing libraries between .Net Core and .Net Framework applications

I was trying to reference a DLL targeting FW 4.6 in a host application targeting .NET Core 2.1. I started getting this error;

This is where I started to wonder, What’s the difference? How they can co-exist? How the host application can use them?

Microsoft recommend to target .NET Standard 2.0 when building reusable libraries, unless you need to support an earlier version. Most general-purpose libraries should not need APIs outside of .NET Standard 2.0. .NET Standard 2.0 is supported by all modern platforms and is the recommended way to support multiple platforms with one target.

.NET Core 2.1 and later versions support .NET Standard 2.0 and earlier versions.

There will be no new .NET Standard versions after 2.1. For more information, see .NET 5 and .NET Standard later in this article.

.NET Standard libraries and Visual Studio
In order to build .NET Standard libraries in Visual Studio, make sure you have Visual Studio 2019 or Visual Studio 2017 version 15.3 or later installed on Windows, or Visual Studio for Mac version 7.1 or later installed on macOS.

Start from here

Read about .NET standard here

A good explanation about libraries

Resources