圆窗
Tauri apps 的 MSIX 包装工具 - 创建 Windows Store 即时捆绑,并有多存档支持.
特征
- MSIX 包装 - 创建存储准备的MSIX软件包
- 多结构支持 - 为x64和arm64建造一捆
- tauri.conf.json (法语) 一体化 - 自动读取应用程序名称、版本、图标和资源
- 代码签名 - 支持PFX证书和Windows证书商店
- 资源索引 - 可选
resources.pri创造合格资产 - 窗口扩展 - 共享目标、文件协会、协议处理器、启动任务、背景菜单、背景任务、应用程序执行外号、App服务、Toast激活、自动播放、打印任务设置、缩略图/预览处理器
先决条件
- 锈 有 Windows 目标
- Windows SDK (用于签名)
# Install Rust targets for multiarch builds
rustup target add x86_64-pc-windows-msvc
rustup target add aarch64-pc-windows-msvc
捆绑 msixbundle-cli
在 Windows(x64和arm64)上 msixbundle-cli 二进制自动被运出 optionalDependencies 侧车(@choochmeque/msixbundle-cli-win32)——不需要单独安装.
如果您在 macOS 或 Linux (例如交叉编译) 上, 或者您安装了 --omit=optional (无)/ --no-optional (pnpm/yarn),建设命令会回到任何 msixbundle-cli 交给你了 PATH 并提示 cargo install msixbundle-cli 如果它不见了.
安装
# One-time setup (use @latest to ensure newest version)
npx @choochmeque/tauri-windows-bundle@latest init
# Or install as dev dependency
npm install -D @choochmeque/tauri-windows-bundle
提示 : 使用
@latest以 npx 绕过缓存版本 :npx @choochmeque/tauri-windows-bundle@latest --version
使用量
初始化
npx @choochmeque/tauri-windows-bundle init
这就产生了:
src-tauri/gen/windows/bundle.config.json- MSIX组合src-tauri/gen/windows/AppxManifest.xml.template- 突出模板src-tauri/gen/windows/Assets/- 图标(从src-tauri/icons/或占位符)- 添加数
@choochmeque/tauri-windows-bundle作为依赖性 - 添加数
tauri:windows:build脚本到 package.json
说明: 如果 Tauri 图标存在于 src-tauri/icons/,自动复制。 宽瓦(310x150)由以正方形图标为中心而产生.
特定窗口图标 : 设定 bundle.icon 内 tauri.windows.conf.json (或 tauri.conf.json指向不同的文件夹,以及 init 将由此获得资产来源。 例如,与
// tauri.windows.conf.json
{ "bundle": { "icon": ["icons/windows/32x32.png", "icons/windows/icon.ico"] } }
init 用途 src-tauri/icons/windows/ (第一个目录的父目录) .png 条目,已解决 src-tauri/作为资产来源。 在该文件夹内,它寻找由MSIX命名的文件 Tauri通过 tauri icon数字 :
- 直接副本 :
StoreLogo.png, (中文(简体) ),Square44x44Logo.png, (中文(简体) ),Square150x150Logo.png(每个缺失的文件成为占位符). - 宽瓦 (
Wide310x150Logo.png)是从找到的第一个平方图标生成的:Square150x150Logo.png→Square142x142Logo.png→icon.png→128x128.png。 。 。 . - 备选案文来源(当
--scale编号 :--target-size编号 :--unplated编号 :--light-unplated已设定 :icon.png→Square310x310Logo.png→128x128.png。 。 。 .
若为 bundle.icon 没有 .png 条目,默认值 src-tauri/icons/ 已使用.
图标变体( 可选)
将一面或多面旗帜传给 init 还生成后缀资产变体 Windows 用于 DPI 缩放、任务栏/启动图标和主题意识牌:
npx @choochmeque/tauri-windows-bundle init --all-variants
| 旗帜 | 生成的文件 |
|---|---|
--scale | <asset>.scale-100/125/150/200/400.png 用于 StoreLogo,平方44x44Logo,平方150x150Logo |
--target-size | Square44x44Logo.targetsize-16/20/24/30/32/36/40/48/60/64/72/80/96/256.png (任务栏,启动列表,跳出列表) |
--unplated | Square44x44Logo.targetsize-N_altform-unplated.png (透明背景) |
--light-unplated | Square44x44Logo.targetsize-N_altform-lightunplated.png (轻主题) |
--all-variants | 以上所有情况 |
变体来源于找到的最高分辨率 Tauri 图标, 依此顺序 : src-tauri/icons/icon.png → Square310x310Logo.png → 128x128.png如果不存在,则用警告跳过变量生成.
传出任何变种旗也翻转 resourceIndex.enabled 改为 true 在生成时 bundle.config.json,因为Windows只通过一个 resources.pri 文件构建于 --makepri。 。 。 .
配置
编辑 src-tauri/gen/windows/bundle.config.json数字 :
{
"publisher": "CN=YourCompany",
"publisherDisplayName": "Your Company Name",
"capabilities": {
"general": ["internetClient"]
},
"signing": {
"pfx": null,
"pfxPassword": null
},
"resourceIndex": {
"enabled": false,
"keepConfig": false
}
}
executableName (可选的) 当生成错误时, 将 exe 文件名 。 没有它,名字就决定从 mainBinaryName 在touri.conf.json, 然后第一个 [[bin]] (次数) [package]src-touri/cargo.toml中的名称,并仅作为产品名称的最后手段.
publisher 财务报告和审定财务报表 publisherDisplayName 可选在 bundle.config.json。如果省略, publisher 倒计时 bundle.publisher 从 tauri.conf.json 或者说 tauri.windows.conf.json如果 publisherDisplayName ,默认为已解决 publisher 数值.
能力 在构建时验证。 支持三种类型:
{
"capabilities": {
"general": ["internetClient", "internetClientServer", "privateNetworkClientServer"],
"device": ["webcam", "microphone", "location", "bluetooth"],
"restricted": ["broadFileSystemAccess", "allowElevation"]
}
}
general- 标准能力<Capability>(中文(简体) )device- 设备接入(<DeviceCapability>(中文(简体) )restricted- 需要储存批准(<rescap:Capability>(中文(简体) )
说明: runFullTrust 总是自动添加( Tauri apps 需要).
resourceIndex.enabled 生成 resources.pri 通过 msixbundle-cli --makepri 在包装之前。 在使用合格资产时启用此功能( 例如, 比例表特定标志例如 Square44x44Logo.scale-200.png) (中文(简体) ).
resourceIndex.keepConfig 继续生成 priconfig.xml 每个 AppxContent 调试目录 .
自动读取自 Tauri.conf.json / Tauri.windows.conf.json:
displayName←productNameversion←version(自动转换为4个部分:1.0.0→1.0.0.0(中文(简体) )description←bundle.shortDescriptionpublisher←bundle.publisher(没有被捆绑时倒回. config.json)icons←bundle.iconresources←bundle.resources(阵列条目保持其布局;领导)../地图到_up_/和绝对根到_root_/,匹配 Tauri 的位置resolveResource()查看运行时间 )externalBin←bundle.externalBin(旁车在前身旁边摆出)-<target-triple>后缀已剥去; 缺少一条已宣布的侧车失效 )signing←bundle.windows.certificateThumbprint
特定平台配置 : 数值 tauri.windows.conf.json 覆盖 tauri.conf.json 使用 JSON 合并补丁(RFC 7396)中定义 Windows 特定设置 identifier, (中文(简体) ), productName,或 bundle.publisher 分别.
构建
# Build x64 only (default, uses cargo, release mode)
pnpm tauri:windows:build
# Build multiarch bundle (x64 + arm64)
pnpm tauri:windows:build --arch x64,arm64
# Debug build (release is default)
pnpm tauri:windows:build --debug
# Use different build runner (pnpm, npm, yarn, bun, etc.)
pnpm tauri:windows:build --runner pnpm
pnpm tauri:windows:build --runner npm
# Re-derive Assets/ from bundle.icon (overwrites manual edits in
# src-tauri/gen/windows/Assets/). Variant flags configured at init are
# replayed from bundle.config.json's `assets.variants`.
pnpm tauri:windows:build --regenerate-assets
默认 build 复制任何内容 src-tauri/gen/windows/Assets/ 手工编辑的平板木板图标 横跨建筑 过 --regenerate-assets 从图标文件夹中刷新此目录 bundle.icon (相同的逻辑) init (a) 使用.
产出
target/msix/
├── MyApp_x64.msix
├── MyApp_arm64.msix # if --arch x64,arm64
└── MyApp.msixbundle # combined bundle
CLI 参考
npx @choochmeque/tauri-windows-bundle init [options]
-p, --path <path> Path to Tauri project
--scale Generate .scale-100/125/150/200/400 PNG variants
--target-size Generate .targetsize-16/20/24/30/32/36/40/48/60/64/72/80/96/256 PNG variants for Square44x44Logo
--unplated Generate _altform-unplated targetsize variants
--light-unplated Generate _altform-lightunplated targetsize variants
--all-variants Shortcut for all four variant families above
npx @choochmeque/tauri-windows-bundle build [options]
--arch <archs> Architectures (comma-separated: x64,arm64) [default: x64]
--debug Build in debug mode (release is default)
--min-windows <ver> Minimum Windows version [default: 10.0.17763.0]
--runner <runner> Build runner (cargo, pnpm, npm, yarn, bun) [default: cargo]
--verbose Show full build output instead of spinner
--regenerate-assets Regenerate gen/windows/Assets/ from bundle.icon
(overwrites manual edits)
npx @choochmeque/tauri-windows-bundle extension list
-p, --path <path> Path to Tauri project
npx @choochmeque/tauri-windows-bundle extension add <type>
<type> Extension type (see below)
-p, --path <path> Path to Tauri project
npx @choochmeque/tauri-windows-bundle extension remove <type> [name]
<type> Extension type (see below)
[name] Extension identifier (required for most types)
-p, --path <path> Path to Tauri project
Extension types:
file-association Associate file types with your app
protocol Register URL protocol handlers (myapp://)
share-target Receive shared content from other apps
startup-task Run app on Windows login
context-menu Add right-click menu items in Explorer
background-task Run tasks when app is not in foreground
app-execution-alias Run app from command line (e.g., myapp)
app-service Allow other apps to call into your app
toast-activation Handle toast notification clicks
autoplay Launch when media/device is inserted
print-task-settings Custom print settings UI
thumbnail-handler Custom file thumbnails in Explorer
preview-handler Custom file previews in Explorer
窗口扩展
文件关联
npx @choochmeque/tauri-windows-bundle extension add file-association
# Prompts for: name, extensions, description
或者,在 tauri.conf.json 根据标准
bundle.fileAssociations 键,并在构建时自动取出 :
{
"bundle": {
"fileAssociations": [
{ "ext": ["ics"], "name": "iCalendar", "description": "iCalendar event file" },
],
},
}
bundle.config.json 条目在顶部合并,在名称相撞时获胜,所以
已存在的仅Windows的覆盖继续工作.
协议处理器
npx @choochmeque/tauri-windows-bundle extension add protocol
# Prompts for: protocol name, display name
共享目标
# Enable
npx @choochmeque/tauri-windows-bundle extension add share-target
# Disable
npx @choochmeque/tauri-windows-bundle extension remove share-target
启动任务
在 Windows 启动时自动运行您的应用程序 .
# Enable
npx @choochmeque/tauri-windows-bundle extension add startup-task
# Disable
npx @choochmeque/tauri-windows-bundle extension remove startup-task
背景菜单
在 Windows 浏览器中添加右键菜单项 .
npx @choochmeque/tauri-windows-bundle extension add context-menu
# Prompts for: menu name, file types, display name
背景任务
应用程序不在前景时运行任务 .
npx @choochmeque/tauri-windows-bundle extension add background-task
# Prompts for: task name, type (timer/systemEvent/pushNotification)
列表扩展
npx @choochmeque/tauri-windows-bundle extension list
应用程序执行别名
从命令行运行您的应用( 例如 ), myapp 而不是整个路径.
npx @choochmeque/tauri-windows-bundle extension add app-execution-alias
# Prompts for: alias name
应用服务
允许其他应用程序调用您的应用程序 .
npx @choochmeque/tauri-windows-bundle extension add app-service
# Prompts for: service name
敬酒活动
处理土司通知点击和行动,包括应用程序退出后从行动中心启动的冷启动.
# Enable
npx @choochmeque/tauri-windows-bundle extension add toast-activation
# Prompts for: CLSID (leave empty to auto-generate from app identifier)
# Disable
npx @choochmeque/tauri-windows-bundle extension remove toast-activation
表示两个 com:Extension Category="windows.comServer" (所以Windows知道在激活时要发射的exe)和 desktop:Extension Category="windows.toastNotificationActivation" (将土司点击CLSID).
自动播放
插入媒体或设备时启动您的应用程序 .
npx @choochmeque/tauri-windows-bundle extension add autoplay
# Prompts for: verb, action display name, event type (content/device)
打印任务设置
添加自定义打印设置 UI.
# Enable
npx @choochmeque/tauri-windows-bundle extension add print-task-settings
# Disable
npx @choochmeque/tauri-windows-bundle extension remove print-task-settings
缩略图处理器
在 Explorer 为您的文件类型提供自定义缩略图 .
npx @choochmeque/tauri-windows-bundle extension add thumbnail-handler
# Prompts for: CLSID, file types
预览处理器
在 Explorer 中提供自定义文件预览 .
npx @choochmeque/tauri-windows-bundle extension add preview-handler
# Prompts for: CLSID, file types
列表扩展
npx @choochmeque/tauri-windows-bundle extension list
删除扩展
npx @choochmeque/tauri-windows-bundle extension remove file-association myfiles
npx @choochmeque/tauri-windows-bundle extension remove protocol myapp
npx @choochmeque/tauri-windows-bundle extension remove context-menu open-with-myapp
npx @choochmeque/tauri-windows-bundle extension remove background-task sync-task
npx @choochmeque/tauri-windows-bundle extension remove app-execution-alias myapp
npx @choochmeque/tauri-windows-bundle extension remove app-service com.myapp.service
npx @choochmeque/tauri-windows-bundle extension remove autoplay open
代码签名
备选案文1:PFX证书
{
"signing": {
"pfx": "path/to/certificate.pfx",
"pfxPassword": null
}
}
通过环境变量设置密码 :
export MSIX_PFX_PASSWORD=your-password
选项2: Windows 证书存储
使用从 tauri.conf.json数字 :
{
"bundle": {
"windows": {
"certificateThumbprint": "ABC123..."
}
}
}
GitHub 动作
自动化MSIX构建的示例工作流程.
说明: 运行
npx @choochmeque/tauri-windows-bundle@latest init本地端首先生成所需的配置文件,然后将其输入您的仓库.
name: Build Windows MSIX
on:
push:
tags:
- 'v*'
workflow_dispatch:
jobs:
build:
runs-on: windows-latest
steps:
- uses: actions/checkout@v4
- name: Setup pnpm
uses: pnpm/action-setup@v4
- name: Setup Node.js
uses: actions/setup-node@v4
with:
node-version: '20'
cache: 'pnpm'
- name: Setup Rust
uses: dtolnay/rust-toolchain@stable
with:
targets: x86_64-pc-windows-msvc, aarch64-pc-windows-msvc
# Caches the cargo registry and build artifacts; cuts warm build times
# to a fraction of the cold ones.
- name: Cache Rust
uses: Swatinem/rust-cache@v2
with:
workspaces: src-tauri
- name: Install dependencies
run: pnpm install
# On Windows runners the @choochmeque/msixbundle-cli-win32 sidecar is
# installed automatically via optionalDependencies. On non-Windows runners
# (or with --no-optional) install it explicitly:
# - run: cargo install msixbundle-cli
- name: Build MSIX bundle
run: pnpm tauri:windows:build --arch x64,arm64 --runner pnpm
- name: Upload artifacts
uses: actions/upload-artifact@v4
with:
name: msix-bundle
path: src-tauri/target/msix/*.msixbundle
输出将在 src-tauri/target/msix/YourApp.msixbundle。 。 。 .