Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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.

like image 322
Lorenzo Isidori Avatar asked Nov 05 '25 06:11

Lorenzo Isidori


1 Answers

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

It is dangerous because:

  • libraries don't have the right trimming behaviour for netstandard facade packages
  • libraries may have odd behaviour when publishing with "-r", especially for netstandard<2.0 dependencies. (they'd end up copying the .NET Core 1.0/1.1 implementation(!) assemblies)
  • you may end up with different NuGet dependencies in the output (transitive dependencies)
  • Copy-to-output/publish-directory items may end up overwriting each other, it may even lead to build failures

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

like image 108
Martin Ullrich Avatar answered Nov 09 '25 10:11

Martin Ullrich



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!