3

我有很多项目的解决方案。一些目标框架netcoreapp2.1,一些其他目标框架netstandard2.0和一个项目有双目标框架

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

我想要一个带有单个命令的 win10 工件:

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

使用此命令,我在使用双目标框架构建项目时遇到此错误。这是错误:

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.

错误很明显。最后,我发现在输出目录中编译的 dll 似乎是 netstandard2.0 dll,因为我的应用程序仍然有效。

我不喜欢肮脏的东西,我该如何解决我的问题?

如果可能的话,我会避免调用 N 次“dotnet publish”命令。

4

1 回答 1

4

不要dotnet publish在解决方案上使用相同的输出目录。尤其是没有“-r”参数。

这很危险,因为:

  • 库对 netstandard 外观包没有正确的修剪行为
  • 使用“-r”发布时,库可能会有奇怪的行为,尤其是对于 netstandard<2.0 依赖项。(他们最终会复制 .NET Core 1.0/1.1 implementation(!) 程序集)
  • 您最终可能会在输出中得到不同的 NuGet 依赖项(传递依赖项)
  • 复制到输出/发布目录项可能最终会相互覆盖,甚至可能导致构建失败

为所有应用程序(控制台应用程序、Web 应用程序)项目单独调用它,或创建发布这些应用程序的 MSBuild 文件。

于 2018-10-07T09:38:46.357 回答