Olivier Duhart
Olivier Duhart

Reputation: 437

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

Upvotes: 10

Views: 5041

Answers (1)

Martin Ullrich
Martin Ullrich

Reputation: 100543

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.

Upvotes: 12

Related Questions