Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

dotnet pack targeting multiple frameworks

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

like image 253
Olivier Duhart Avatar asked May 03 '17 14:05

Olivier Duhart


People also ask

How do I target multiple net frameworks?

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.

What is TFM in dotnet?

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.

How do I change my target framework to .NET 6?

To set target . NET runtime version to 6.0, enter <TargetFramework>net6. 0</TargetFramework> version in project's . csproj file directly.


1 Answers

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.

like image 178
Martin Ullrich Avatar answered Oct 11 '22 20:10

Martin Ullrich