.net-coredotnet-clitarget-framework

dotnet publish sln having projects with multiple target frameworks fails


I have a solution with many projects. Some target frameworknetcoreapp2.1, some other target framework netstandard2.0 and one project has a double target framework

<TargetFrameworks>netstandard2.0;net471</TargetFrameworks>

I'd want to have a artifact for win10 with a single command:

dotnet publish MySolution.sln -c Release -o "targetFolder" -r win10-x64

With this command I have this error while building the project with double target framework. Here's the errors:

C:\Program Files\dotnet\sdk\2.1.402\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.CrossTargeting.targets(31,5) error : The 'Publish' target is not supported without specifying a target framework. The current project targets multiple frameworks, please specify the framework for the published application.

The error is clear. At the end I find that dll compiled in the output directory and it seems like it is a netstandard2.0 dll because my application still works.

I don't like dirty things so, how can I solve my problem?

I would avoid to call N times the "dotnet publish" command if possible.


Solution

  • Don't use dotnet publish with the same output directory on a solution. Especially not with the "-r" argument.

    It is dangerous because:

    Call it individually for all application (console app, web app) projects or create an MSBuild file that publishes these applications.