代码之家  ›  专栏  ›  技术社区  ›  Lorenzo Isidori

具有多个目标框架的项目的dotnet publish sln失败

  •  0
  • Lorenzo Isidori  · 技术社区  · 6 年前

    我有很多项目的解决方案。一些目标框架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.0dll,因为我的应用程序仍然可以工作。

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

    1 回复  |  直到 5 年前
        1
  •  4
  •   Martin Ullrich    6 年前

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

    这是危险的,因为:

    • 使用“-r”发布时,库可能会有奇怪的行为,特别是对于netstandard<2.0相关性(他们最终会复制.NETCore1.0/1.1实现(!)组件)
    • 您可能会在输出中得到不同的NuGet依赖项(传递依赖项)