具有包含多个目标框架的项目的dotnet publish sln失败 [英] dotnet publish sln having projects with multiple target frameworks fails

查看:69
本文介绍了具有包含多个目标框架的项目的dotnet publish sln失败的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

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>

我想用一个命令为win10提供一个工件:

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.

错误已清除.最后,我发现该dll已在输出目录中编译,并且似乎是netstandard2.0 dll,因为我的应用程序仍然可以工作.

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?

如果可能的话,我会避免调用N次"dotnet publish"命令.

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

推荐答案

在解决方案上不要将 dotnet publish 与相同的输出目录一起使用.特别是不能使用"-r"参数.

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

这很危险,因为:

  • 对于netstandard门面包,图书馆的修剪行为不正确
  • 当使用"-r"发布时,
  • 库可能具有奇怪的行为,尤其是对于netstandard< 2.0依赖项.(它们最终将复制.NET Core 1.0/1.1实现(!)程序集)
  • 您最终可能在输出中获得不同的NuGet依赖项(传递依赖项)
  • 复制到输出/发布目录项可能最终被彼此覆盖,甚至可能导致构建失败
  • 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

为所有应用程序(控制台应用程序,Web应用程序)项目分别调用它,或创建一个发布这些应用程序的MSBuild文件.

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

这篇关于具有包含多个目标框架的项目的dotnet publish sln失败的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆