'Using a .net core dll with .net framework app?

I think i know the answer to this question but wanted to make sure. We are trying to dip our toe in .net core. We would like to code some of our dlls in .net core but we want to avoid having to push .net core runtime to every workstation. I know if you are doing a .net core exe you can embed the run time into the application so that you won't have to physically install .net core on each machine.

All the machines we are pushing to are windows machines with .net framework already installed. If we want to use be able to use .net core dlls then we would have to install the .net core runtime wouldn't we?

thanks....



Solution 1:[1]

Here is an example csproj file from a .net standard dll that we use that is consumed by .net core and .net framework applications. TargetFrameworks is used to specify the frameworks for use. Constants are defined for any framework specific code that may need to be executed. In our case we had specific instances where the code was slightly different for the framework vs core

<PropertyGroup>

   <TargetFrameworks>netstandard1.3;netstandard2.0;net452;net461;net471</TargetFrameworks>
    <GeneratePackageOnBuild>true</GeneratePackageOnBuild>
    <Copyright>...</Copyright>
    <Company>...</Company>
    <Authors>...</Authors>
    <Description>...</Description>
    <Version>1.0.20</Version>
  </PropertyGroup>

  <PropertyGroup Condition="'$(Configuration)'=='Debug'">
    <DefineConstants>TRACE;DEBUG;</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetFramework)'=='netstandard2.0'">
    <DefineConstants>NETSTANDARD2_0;</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetFramework)'=='netstandard1.3'">
    <DefineConstants>NETSTANDARD1_3;</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetFramework)'=='net471'">
    <DefineConstants>NET471;</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetFramework)'=='net461'">
    <DefineConstants>NET461;</DefineConstants>
  </PropertyGroup>

  <PropertyGroup Condition="'$(TargetFramework)'=='net452'">
    <DefineConstants>NET452;</DefineConstants>
  </PropertyGroup>

Solution 2:[2]

It looks like the answer to your question is no for .NET 5/6, if I'm correctly understanding Microsoft's documentation. It looks like the latest version you can use with .NET Framework is .NET Standard 2.0.

.NET Standard is a formal specification of .NET APIs that are available on multiple .NET implementations. The motivation behind .NET Standard was to establish greater uniformity in the .NET ecosystem. .NET 5 and later versions adopt a different approach to establishing uniformity that eliminates the need for .NET Standard in most scenarios. However, if you want to share code between .NET Framework and any other .NET implementation, such as .NET Core, your library should target .NET Standard 2.0. No new versions of .NET Standard will be released, but .NET 5, .NET 6, and all future versions will continue to support .NET Standard 2.1 and earlier.

If you're building reusable libraries that you plan to ship on NuGet, consider the trade-off between reach and available feature set. .NET Standard 2.0 is the latest version that's supported by .NET Framework, so it gives good reach with a fairly large feature set. We don't recommend targeting .NET Standard 1.x, as you'd limit the available feature set for a minimal increase in reach. If you don't need to support .NET Framework, you could go with .NET Standard 2.1 or .NET 5/6. We recommend you skip .NET Standard 2.1 and go straight to .NET 6. Most widely used libraries will multi-target for both .NET Standard 2.0 and .NET 5+. Supporting .NET Standard 2.0 gives you the most reach, while supporting .NET 5+ ensures you can leverage the latest platform features for customers that are already on .NET 5+.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 hawkstrider
Solution 2 Alex Riveron