4

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.

alex.z
  • 84
  • 7
Lorenzo Isidori
  • 1,809
  • 2
  • 20
  • 31

1 Answers1

5

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.

Martin Ullrich
  • 94,744
  • 25
  • 252
  • 217
  • 2
    I have to publish in the same directory. All those projects belong to the same application. What you are saying makes sense but i don't undestand your solution. Should I call N times "dotnet publish" with different params? What did I miss? – Lorenzo Isidori Oct 08 '18 at 09:20
  • If you only have one project (web app / console app), only do `dotnet publish` on the csproj file of that project, it will include all dependencies. – Martin Ullrich Oct 08 '18 at 11:06
  • Fine, but I have many projects. One of those is a console application and the others are class libraries. – Lorenzo Isidori Oct 08 '18 at 11:43
  • 2
    If the console application references those libraries, they will be included automatically. – Martin Ullrich Oct 09 '18 at 05:06