I have a dotnet core project that targets 2 frameworks :
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>netcoreapp1.0;net45</TargetFramework>
</PropertyGroup>
</Project>
using dotnet build -c Release -f net45|netcoreapp1.0
I can build my class library for the desired framewok.
But I can't found how to do the same with the dotnet-pack
command. I fails with the followin error :
C:\Program Files\dotnet\sdk\1.0.0\Sdks\Microsoft.NET.Sdk\build\Microsoft.NET.TargetFrameworkInference.targets(84,5): error : Cannot infer TargetFrameworkIdentifier and/or TargetFrameworkVersion from TargetFramework='netcoreapp1.0'. They must be specified explicitly. [C:\Users\olduh\sly\sly\sly\sly.csproj]
Is there a way to multi target framework when building nuget package ?
thanks for your answers,
Olivier
To target multiple frameworks, change <TargetFramework> to plural <TargetFrameworks> and include monikers for different frameworks you want to target separated by ; . Here, we will support two more frameworks . NET Framework 4.0 & 4.6. So include net40 and net46 monikers respectively as shown below.
You specify the target framework in your project file using a target framework moniker (TFM). An app or library can target a version of . NET Standard. . NET Standard versions represent standardized sets of APIs across all . NET implementations.
To set target . NET runtime version to 6.0, enter <TargetFramework>net6. 0</TargetFramework> version in project's . csproj file directly.
For multi-targeting, use the plural TargetFrameworks
property to provide a list of frameworks. TargetFramework
(singular) only accepts a single framework. If you fix the missing s
on the property name, dotnet pack -c Release
should work as expected - without the need to specify any framework parameter.
You probably did not update the property when adding an additional framework. By specifying the -f
option, you have overwritten this property to make it work, but i guess that a dotnet build
will fail with the same error.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With