3

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....

5
  • Just try it. There are many duplicate questions anyway but it's faster to just create one solution with two projects and try to reference one from the other Commented Jul 10, 2018 at 15:48
  • 1
    In any case, if you want your code to be reusable you should create .NET Standard libriaries. A Full or Core library will expect to find Full or Core versions of the BCL classes. A Standard library will use the classes provided by the executable's runtime Commented Jul 10, 2018 at 15:50
  • To consume the dll's with non core applications you will need to use .net standard and multi target your dll, it will build the libraries for each framework type you specify into the package. Commented Jul 10, 2018 at 19:34
  • 1
    You can't, a .netcore assembly targets runtime assemblies that are not available in the desktop version of the framework. It is a pretty fundamentally different runtime, completely different CLR version for example, not so easy to see from the docs. Targeting .netstandard is a way to switch gradually, but beware that a lot of classes will be missing. Commented Jul 10, 2018 at 19:53
  • .NET Standard is good option for targeting both .NET Core and .NET Framework. It certainly is limited at the moment but is improving. Please find compatibility version here Commented Jul 13, 2018 at 10:01

2 Answers 2

1

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+.

Sign up to request clarification or add additional context in comments.

Comments

-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>

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.