You need to target multiple frameworks in your project;
- Right click on project name and click "Edit .cproj file"
- add ( s ) to target framework tag so it becomes
<TargetFrameworks>...</TargetFrameworks>
- specify your target frameworks (see docs for all versions):
<TargetFrameworks>net472;net48;netcoreapp2.0;netcoreapp2.1;netcoreapp2.2</TargetFrameworks>
- if your library will have any references, you need to specify manually all the references for each version:
<ItemGroup Condition=" '$(TargetFramework)' == 'net471' ">
<Reference Include="System.Net" />
</ItemGroup>
or specify reference for multiple versions:
<ItemGroup Condition=" '$(TargetFramework)' == 'netcoreapp2.0' || '$(TargetFramework)' == 'netcoreapp2.1' || '$(TargetFramework)' == 'netcoreapp2.2' ">
<PackageReference Include="Microsoft.AspNetCore.Mvc.TagHelpers" Version="1.0.0" />
</ItemGroup>
or specify package reference for all target frameworks:
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Localization" Version="1.0.0" />
</ItemGroup>
you can specify the min required version and the framework will install the latest compatible version. e.g. below we specify Localization package min version as 1.0.0 but when it will be installed on .Net Core 2.2 it will install the newest compatible version, for more details about versioning see the version ranges and wild chars
- last but not least; in you code you need to check for target framework specific cases where you need to use compatible code line with each version.
for example to get culture info you need to specify different code for different .Net Core versions:
#if NETCOREAPP1_0
var culture = new CultureInfo("en-US");
#else
var culture = CultureInfo.GetCultureInfo("en-US");
#endif
_logger.LogInformation($"{culture.Name}");
if you are using visual studio, you will see a dropdown navigation for all target frameworks, you can use it to switch between target frameworks and check your code compatibility.