【问题标题】:Is it possible to publish a stand alone c# application to Linux?是否可以将独立的 c# 应用程序发布到 Linux?
【发布时间】:2019-09-11 23:52:58
【问题描述】:

我正在尝试将我制作的 C# .net 核心控制台应用程序发布到运行 Centos 7 64 位的 Linux 机器上。目前,我正在使用命令:dotnet publish -c release -r contos.7-x64 发布应用程序。不幸的是,以这种方式发布似乎需要在目标机器上安装 .net core。是否可以在我不需要在我发布到的机器上安装任何东西的情况下执行此操作?

【问题讨论】:

  • “似乎以这种方式发布需要在我尝试发布到的机器上安装核心” - 你为什么得出这个结论?
  • 您是否使用了正确的 ID (see the the list of IDs)。 Centos 列在 linux-x64 id 下,你试过用吗?
  • 我测试了将一个简单的控制台应用程序发布 (dotnet publish -c release -r linux-x64) 到没有安装 .NET Core 的 Ubuntu 机器上,它工作得很好。我不明白为什么 Centos 会有所不同。

标签: c# linux .net-core centos


【解决方案1】:

在 .NET Core 2.2 中,您可以使用此命令 dotnet publish -r centos.7-x64 -c Release --self-contained 创建一个独立的应用程序(即不需要在主机上安装 .NET Core 运行时)。它会产生可执行文件和大量依赖项。

在 .NET Core 3 中,您可以将所有依赖项压缩到单个文件 dotnet publish -r centos.7-x64 -c Release /p:PublishSingleFile=true。您还可以添加标志/p:PublishTrimmed=true 以将可执行文件大小减少tree trimming

更多详情请见herehere

【讨论】:

    【解决方案2】:

    我发现问题在于项目没有编译到核心 2。而是项目正在编译到版本 1。进行此更改后,已发布的项目能够在 Centos 上运行。

    【讨论】:

      猜你喜欢
      • 2012-01-29
      • 1970-01-01
      • 1970-01-01
      • 2020-05-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-02-23
      • 1970-01-01
      相关资源
      最近更新 更多