跳到主要内容

发布

注意事项

不支持单文件发布

不支持裁剪,不支持AOT

概述

ThingsGateway 网关的发布过程包括编译解决方案和发布应用程序两个主要步骤。本文档详细介绍如何正确编译和发布 ThingsGateway 应用程序,包括不同发布模式、平台选择和优化配置。

发布前准备

在发布之前,请确保:

  1. 已安装 .NET 8.0 SDK
  2. 已安装 Visual Studio 2022 或更高版本
  3. 项目代码已提交到版本控制系统
  4. 已测试所有功能并确认正常工作
  5. 已备份生产环境的配置文件

编译解决方案

使用 Visual Studio 编译

  1. 打开 ThingsGateway 解决方案(ThingsGateway.slnx

  2. 在 Visual Studio 顶部工具栏中,选择配置为 Release

  3. 右键点击解决方案,选择"生成解决方案"(或按 Ctrl+Shift+B

编译选项说明
  • Debug:调试版本,包含调试信息,体积较大,性能较低
  • Release:发布版本,经过优化,体积较小,性能较高

使用命令行编译

# 编译整个解决方案
dotnet build ThingsGateway.slnx -c Release

发布版本

使用 Visual Studio 发布

  1. 右键点击 ThingsGateway.Server 项目

  2. 选择"发布"

  3. 选择发布配置:

    • 配置:Release
    • 目标运行时:win-x64(Windows)、linux-x64(Linux)、osx-x64(macOS)
    • 部署模式:依赖框架 或 独立
    • 生成单个文件:否
    • 裁剪程序集:否
  4. 点击"发布"按钮

使用命令行发布

依赖框架部署(FDD)

# Windows
dotnet publish ThingsGateway.Server/ThingsGateway.Server.csproj -r win-x64 --self-contained false -c Release

# Linux
dotnet publish ThingsGateway.Server/ThingsGateway.Server.csproj -r linux-x64 --self-contained false -c Release

独立部署(SCD)

# Windows x64
dotnet publish ThingsGateway.Server/ThingsGateway.Server.csproj -r win-x64 --self-contained true -c Release

# Linux x64
dotnet publish ThingsGateway.Server/ThingsGateway.Server.csproj -r linux-x64 --self-contained true -c Release

Docker 镜像发布

发布到文件夹后,根文件夹下有Dockerfile文件。

构建和运行 Docker 镜像

# 构建 Docker 镜像
docker build -t thingsgateway:latest .

# 运行容器
docker run -d -p 5000:80 --name thingsgateway thingsgateway:latest

# 查看容器日志
docker logs -f thingsgateway

# 停止容器
docker stop thingsgateway

# 删除容器
docker rm thingsgateway

多架构 Docker 镜像

# 构建多架构镜像(需要 buildx)
docker buildx create --use
docker buildx build --platform linux/amd64,linux/arm64 -t thingsgateway:latest --push .