C:\Program Files\OpenSSL-Win64)此方式打包的 exe 具有以下特性:
cd D:\code\steam\client-tauri
# 执行带 devtools 的打包脚本
.\build-devtools.ps1
注意:此方式主要用于调试,生产部署建议使用方式二。
生产环境打包生成纯净版 exe,无开发者工具:
cd D:\code\steam\client-tauri
# 生产环境打包
.\build-prod.ps1
使用 standalone-build.ps1 生成单个可执行文件:
cd D:\code\steam\client-tauri
# 生成单个 exe
.\standalone-build.ps1
此脚本生成单个可执行文件 steamSH_standalone.exe,不包含 WebView2 bootstrapper。
| 产物 | 路径 | 大小 | 说明 |
|---|---|---|---|
| 带 devtools 的 exe | src-tauri/target/release/steamSH.exe |
~21 MB | 静态链接版,带开发者工具 |
| 生产版 exe | src-tauri/target/release/bundle/msi/steamSH_0.1.0_x64_en-US.msi |
~11 MB | 纯净版,无开发者工具 |
| standalone exe | steamSH_standalone.exe |
~21 MB | 单文件版,无需 DLL |
| NSIS 安装包 | src-tauri/target/release/bundle/nsis/steamSH_0.1.0_x64-setup.exe |
- | 需要手动修复 NSIS 配置 |
打包后双击运行 exe,按钮和功能:
F12 键打开开发者工具Ctrl+Shift+I 打开开发者工具# 复制 devtools 版本到 dist-devtools 目录
Copy-Item "src-tauri\target\release\steamSH.exe" "dist-devtools\steamSH.exe"
# 复制 standalone 版本
Copy-Item "steamSH_standalone.exe" "dist-portable\steamSH.exe"
devtools 版本部署目录应包含以下文件:
dist-devtools/
├── steamSH.exe # 主程序(带开发者工具)
├── vc_redist.x64.exe # VC++ 运行库(可选)
├── README.md # 使用说明
dist-devtools 文件夹拷贝到目标电脑steamSH.exe 运行打包后的 exe 具有以下调试功能:
键盘快捷键:
F12:打开开发者工具Ctrl+Shift+I:打开开发者工具Ctrl+Shift+J:打开开发者工具并聚焦到控制台右键菜单:
通过页面按钮(如果有):
console.log() 输出的日志如果应用启动失败,可以运行诊断工具:
diagnose.bat
诊断工具会检查:
| 依赖 | 必须 | 说明 |
|---|---|---|
| Windows 10/11 或 Server 2016+ | 是 | 操作系统 |
| WebView2 运行时 | 是 | 程序会自动提示安装 |
| VC++ 2015-2022 Redistributable | 否 | 大多数系统已安装 |
原因:OpenSSL 未正确静态链接。
解决方案:
确保静态库存在:
C:\Program Files\OpenSSL-Win64\lib\VC\x64\MT\libcrypto_static.lib
使用打包脚本自动设置环境变量:
.\build-devtools.ps1 # 或
.\build-prod.ps1
检查方法:
# 使用 dumpbin 检查依赖
dumpbin /dependents "src-tauri\target\release\steamSH.exe"
静态链接成功的 exe 不应包含 libcrypto 或 libssl DLL 依赖。
| 特性 | devtools 版本 | 普通版本 |
|---|---|---|
| 右键菜单 | 有 | 无 |
| F12 打开控制台 | 支持 | 不支持 |
| Console 日志 | 可查看 | 不可查看 |
| 文件大小 | 相同 | 相同 |
| 运行性能 | 相同 | 相同 |
错误:系统找不到指定的文件
解决方案:
src-tauri/icons/icon.ico 存在src-tauri/license.txt 存在diagnose.bat 诊断logs 目录下的日志文件Rust 的 openssl crate 默认动态链接系统 OpenSSL,生成的 exe 依赖外部 DLL 文件:
libcrypto-3-x64.dlllibssl-3-x64.dll服务器系统通常没有预装这些 DLL,导致程序无法运行。
打包脚本 build-devtools.ps1 和 build-prod.ps1 会自动:
[dependencies]
# OpenSSL 静态链接配置
# 设置环境变量后自动使用静态库
openssl = "0.10"
添加了 devtools 打包支持
build-devtools.ps1 脚本TAURI_DEVTOOLS=1 环境变量启用开发者工具tauri.conf.json 添加 devtools 配置创建了 OpenSSL 静态链接环境脚本
scripts/set-openssl-static-env.ps1 自动配置静态链接环境更新了打包指南
禁用了虚拟机/服务器环境检测(security.rs)
添加了启动错误对话框(main.rs)
配置了 OpenSSL 静态链接
C:\Program Files\OpenSSL-Win64\lib\VC\x64\MT 目录下的静态库OPENSSL_STATIC=1 环境变量更新了 tauri.conf.json
$ErrorActionPreference = "Stop"
[Console]::OutputEncoding = [System.Text.Encoding]::UTF8
Set-Location $PSScriptRoot
# 与 build-prod 一致:静态链接 OpenSSL
. (Join-Path $PSScriptRoot "scripts\set-openssl-static-env.ps1")
$env:DEFAULT_BACKEND_API_URL = "http://125.122.32.114:9000"
# 启用 devtools(右键菜单、检查按钮)
$env:TAURI_DEVTOOLS = "1"
Write-Host "========================================" -ForegroundColor Cyan
Write-Host "打包 SteamSH (带开发者工具)" -ForegroundColor Cyan
Write-Host "API 地址: $env:DEFAULT_BACKEND_API_URL" -ForegroundColor Cyan
Write-Host "DevTools: 已启用 (右键菜单 + 检查按钮)" -ForegroundColor Cyan
Write-Host "========================================" -ForegroundColor Cyan
npm run tauri build
Write-Host ""
Write-Host "打包完成!" -ForegroundColor Green
Write-Host "带 devtools 的 exe 位于: src-tauri\target\release\steamSH.exe"
Write-Host ""
Write-Host "提示:复制 exe 到其他电脑后,其他电脑需要安装 WebView2 运行时" -ForegroundColor Yellow
最后更新:2026-04-04