Windows 安装程序
适用于 Windows 的 Tauri 应用可以使用 WiX Toolset v3 作为 Microsoft 安装程序(.msi
文件)分发,也可以使用 NSIS 作为安装可执行文件(-setup.exe
文件)分发。
¥Tauri applications for Windows are either distributed as Microsoft Installers (.msi
files) using the WiX Toolset v3
or as setup executables (-setup.exe
files) using NSIS.
请注意,.msi
安装程序只能在 Windows 上创建,因为交叉编译不起作用。NSIS 安装程序的交叉编译目前处于实验阶段。
¥Please note that .msi
installers can only be created on Windows as cross-compilation doesn’t work.
Cross-compilation for NSIS installers is currently experimental.
本指南提供有关安装程序可用自定义选项的信息。
¥This guide provides information about available customization options for the installer.
构建
¥Building
要构建你的应用并将其打包到 Windows 安装程序中,你可以使用 Tauri CLI 并在 Windows 计算机中运行 tauri build
命令:
¥To build and bundle your app into a Windows installer you can use the Tauri CLI and run the tauri build
command in a Windows computer:
npm run tauri build
yarn tauri build
pnpm tauri build
deno task tauri build
cargo tauri build
实验:在 Linux 和 macOS 上构建 Windows 应用
¥Experimental: Build Windows apps on Linux and macOS
使用 NSIS 时,可以在 Linux 和 macOS 主机上交叉编译 Windows 应用。请注意,这目前被认为是高度实验性的,可能不适用于每个系统或每个项目。因此,如果本地 VM 或 CI 解决方案(如 GitHub Actions)不适合你,则应仅将其用作最后的手段。
¥Cross compiling Windows apps on Linux and macOS hosts is possible when using NSIS. Note that this is currently considered highly experimental and may not work on every system or for every project. Therefore it should only be used as a last resort if local VMs or CI solutions like GitHub Actions don’t work for you.
:::note 注意
对交叉编译的 Windows 安装程序进行签名需要外部签名工具。有关更多信息,请参阅 签署文档。
¥Signing cross compiled Windows installers requires an external signing tool. See the signing documentation for more information.
:::
由于 Tauri 正式仅支持 MSVC Windows 目标,因此设置稍微复杂一些。
¥Since Tauri officially only supports the MSVC Windows target, the setup is a bit more involved.
安装 NSIS
¥Install NSIS
一些 Linux 发行版在其存储库中提供 NSIS,例如在 Ubuntu 上,你可以通过运行以下命令安装 NSIS:
¥Some Linux distributions have NSIS available in their repositories, for example on Ubuntu you can install NSIS by running this command:
sudo apt install nsis
但是在许多其他发行版上,你必须自己编译 NSIS 或手动下载发行版二进制包中未包含的存根和插件。例如,Fedora 仅提供二进制文件,而不提供存根和插件:
¥But on many other distributions you have to compile NSIS yourself or download Stubs and Plugins manually that weren’t included in the distro’s binary package. Fedora for example only provides the binary but not the Stubs and Plugins:
sudo dnf in mingw64-nsiswget https://github.com/tauri-apps/binary-releases/releases/download/nsis-3/nsis-3.zipunzip nsis-3.zipsudo cp nsis-3.08/Stubs/* /usr/share/nsis/Stubs/sudo cp -r nsis-3.08/Plugins/** /usr/share/nsis/Plugins/
在 macOS 上,你需要 [Homebrew] 来安装 NSIS:
¥On macOS you will need [Homebrew] to install NSIS:
brew install nsis
安装 LLVM 和 LLD 链接器
¥Install LLVM and the LLD Linker
由于默认的 Microsoft 链接器仅适用于 Windows,我们还需要安装一个新的链接器。要编译用于设置应用图标等的 Windows 资源文件,我们还需要 LLVM 项目一部分的 llvm-rc
二进制文件。
¥Since the default Microsoft linker only works on Windows we will also need to install a new linker.
To compile the Windows Resource file which is used for setting the app icon among other things
we will also need the llvm-rc
binary which is part of the LLVM project.
sudo apt install lld llvm
在 Linux 上,如果你添加了将编译 C/C++ 依赖作为其构建脚本一部分的依赖,则还需要安装 clang
包。默认的 Tauri 应用不需要这样做。
¥On Linux you also need to install the clang
package if you added dependencies that compile C/C++ dependencies as part of their build scripts.
Default Tauri apps should not require this.
brew install llvm
在 macOS 上,你还必须按照安装输出中的建议将 /opt/homebrew/opt/llvm/bin
添加到你的 $PATH
。
¥On macOS you also have to add /opt/homebrew/opt/llvm/bin
to your $PATH
as suggested in the install output.
安装 Windows Rust 目标
¥Install the Windows Rust target
假设你正在为 64 位 Windows 系统构建:
¥Assuming you’re building for 64-bit Windows systems:
rustup target add x86_64-pc-windows-msvc
安装 cargo-xwin
¥Install cargo-xwin
我们将使用 [cargo-xwin
] 作为 Tauri 的 “runner”,而不是手动设置 Windows SDK:
¥Instead of setting the Windows SDKs up manually we will use [cargo-xwin
] as Tauri’s “runner”:
cargo install --locked cargo-xwin
默认情况下,cargo-xwin
会将 Windows SDK 下载到项目本地文件夹中。如果你有多个项目并想共享这些文件,你可以将 XWIN_CACHE_DIR
环境变量设置为首选位置的路径。
¥By default cargo-xwin
will download the Windows SDKs into a project-local folder.
If you have multiple projects and want to share those files you can set the XWIN_CACHE_DIR
environment variable with a path to the preferred location.
构建应用
¥Building the App
现在它应该像将运行器和目标添加到 tauri build
命令一样简单:
¥Now it should be as simple as adding the runner and target to the tauri build
command:
npm run tauri build -- --runner cargo-xwin --target x86_64-pc-windows-msvc
yarn tauri build --runner cargo-xwin --target x86_64-pc-windows-msvc
pnpm tauri build --runner cargo-xwin --target x86_64-pc-windows-msvc
deno task tauri build --runner cargo-xwin --target x86_64-pc-windows-msvc
cargo tauri build --runner cargo-xwin --target x86_64-pc-windows-msvc
然后构建输出将在 target/x86_64-pc-windows-msvc/release/bundle/nsis/
中。
¥The build output will then be in target/x86_64-pc-windows-msvc/release/bundle/nsis/
.
为 32 位或 ARM 构建
¥Building for 32-bit or ARM
Tauri CLI 默认使用你机器的体系结构编译你的可执行文件。假设你正在 64 位机器上进行开发,CLI 将生成 64 位应用。
¥The Tauri CLI compiles your executable using your machine’s architecture by default. Assuming that you’re developing on a 64-bit machine, the CLI will produce 64-bit applications.
如果你需要支持 32 位机器,可以使用 --target
标志使用不同的 Rust 目标 编译你的应用:
¥If you need to support 32-bit machines, you can compile your application with a different Rust target
using the --target
flag:
npm run tauri build -- --target i686-pc-windows-msvc
yarn tauri build --target i686-pc-windows-msvc
pnpm tauri build --target i686-pc-windows-msvc
deno task tauri build --target i686-pc-windows-msvc
cargo tauri build --target i686-pc-windows-msvc
默认情况下,Rust 仅为你的机器目标安装工具链,因此你需要先安装 32 位 Windows 工具链:rustup target add i686-pc-windows-msvc
。
¥By default, Rust only installs toolchains for your machine’s target,
so you need to install the 32-bit Windows toolchain first: rustup target add i686-pc-windows-msvc
.
如果你需要为 ARM64 构建,则首先需要安装其他构建工具。为此,请打开 Visual Studio Installer
,单击 “修改”,然后在 “单个组件” 选项卡中安装 “C++ ARM64 构建工具”。在撰写本文时,VS2022 中的确切名称是 MSVC v143 - VS 2022 C++ ARM64 build tools (Latest)
。现在你可以使用 rustup target add aarch64-pc-windows-msvc
添加 rust 目标,然后使用上述方法编译你的应用:
¥If you need to build for ARM64 you first need to install additional build tools.
To do this, open Visual Studio Installer
, click on “Modify”, and in the “Individual Components” tab install the “C++ ARM64 build tools”.
At the time of writing, the exact name in VS2022 is MSVC v143 - VS 2022 C++ ARM64 build tools (Latest)
.\ Now you can add the rust target with rustup target add aarch64-pc-windows-msvc
and then use the above-mentioned method to compile your app:
npm run tauri build -- --target aarch64-pc-windows-msvc
yarn tauri build --target aarch64-pc-windows-msvc
pnpm tauri build --target aarch64-pc-windows-msvc
deno task tauri build --target aarch64-pc-windows-msvc
cargo tauri build --target aarch64-pc-windows-msvc
:::info 信息
请注意,NSIS 安装程序本身仍将通过模拟在 ARM 机器上运行 x86。应用本身将是原生 ARM64 二进制文件。
¥Note that the NSIS installer itself will still be x86 running on the ARM machine via emulation. The app itself will be a native ARM64 binary.
:::
支持 Windows 7
¥Supporting Windows 7
默认情况下,Microsoft Installer (.msi
) 不适用于 Windows 7,因为它需要下载未安装的 WebView2 引导程序(如果操作系统中未启用 TLS 1.2,则可能会失败)。Tauri 包含一个嵌入 WebView2 引导程序的选项(请参阅下面的 嵌入 WebView2 Bootstrapper 部分)。基于 NSIS 的安装程序(-setup.exe
)还支持 Windows 7 上的 downloadBootstrapper
模式。
¥By default, the Microsoft Installer (.msi
) does not work on Windows 7 because it needs to download the WebView2 bootstrapper if not installed
(which might fail if TLS 1.2 is not enabled in the operating system). Tauri includes an option to embed the WebView2 bootstrapper
(see the Embedding the WebView2 Bootstrapper section below).
The NSIS based installer (-setup.exe
) also supports the downloadBootstrapper
mode on Windows 7.
此外,要在 Windows 7 中使用通知 API,你需要启用 windows7-compat
Cargo 功能:
¥Additionally, to use the Notification API in Windows 7, you need to enable the windows7-compat
Cargo feature:
[dependencies]tauri-plugin-notification = { version = "2.0.0", features = [ "windows7-compat" ] }
FIPS 合规性
¥FIPS Compliance
如果你的系统要求 MSI 包符合 FIPS 要求,你可以在运行 tauri build
之前将 TAURI_FIPS_COMPLIANT
环境变量设置为 true
。在 PowerShell 中,你可以像这样为当前终端会话设置它:
¥If your system requires the MSI bundle to be FIPS compliant you can set the TAURI_FIPS_COMPLIANT
environment variable to true
before running tauri build
. In PowerShell you can set it for the current terminal session like this:
$env:TAURI_FIPS_COMPLIANT="true"
WebView2 安装选项
¥WebView2 Installation Options
安装程序默认下载 WebView2 引导程序,如果未安装运行时,则执行它。或者,你可以嵌入引导程序、嵌入离线安装程序或使用固定的 WebView2 运行时版本。请参阅下表以比较这些方法:
¥The installers by default download the WebView2 bootstrapper and executes it if the runtime is not installed. Alternatively, you can embed the bootstrapper, embed the offline installer, or use a fixed WebView2 runtime version. See the following table for a comparison between these methods:
安装方法 | 需要互联网连接? | 附加安装程序大小 | 注释 |
---|---|---|---|
downloadBootstrapper | 是 | 0MB | Default 导致安装程序大小较小,但不建议通过 .msi 文件进行 Windows 7 部署。 |
embedBootstrapper | 是 | ~1.8MB | Windows 7 上对 .msi 安装程序的支持更好。 |
offlineInstaller | 否 | ~127MB | 嵌入 WebView2 安装程序。建议用于离线环境。 |
fixedVersion | 否 | ~180MB | 嵌入固定的 WebView2 版本。 |
skip | 否 | 0MB | ⚠️ 不推荐 不将 WebView2 作为 Windows 安装程序的一部分安装。 |
:::info 信息
在 Windows 10(2018 年 4 月发行版或更高版本)和 Windows 11 上,WebView2 运行时作为操作系统的一部分分发。
¥On Windows 10 (April 2018 release or later) and Windows 11, the WebView2 runtime is distributed as part of the operating system.
:::
已下载的引导程序
¥Downloaded Bootstrapper
这是构建 Windows 安装程序的默认设置。它下载引导程序并运行它。需要互联网连接,但安装程序大小会更小。如果你要通过 .msi
安装程序分发到 Windows 7,则不建议这样做。
¥This is the default setting for building the Windows Installer. It downloads the bootstrapper and runs it.
Requires an internet connection but results in a smaller installer size.
This is not recommended if you’re going to be distributing to Windows 7 via .msi
installers.
{ "bundle": { "windows": { "webviewInstallMode": { "type": "downloadBootstrapper" } } }}
嵌入式引导程序
¥Embedded Bootstrapper
要嵌入 WebView2 Bootstrapper,请将 webviewInstallMode 设置为 embedBootstrapper
。这会使安装程序大小增加约 1.8MB,但会增加与 Windows 7 系统的兼容性。
¥To embed the WebView2 Bootstrapper, set the webviewInstallMode to embedBootstrapper
.
This increases the installer size by around 1.8MB, but increases compatibility with Windows 7 systems.
{ "bundle": { "windows": { "webviewInstallMode": { "type": "embedBootstrapper" } } }}
离线安装程序
¥Offline Installer
要嵌入 WebView2 Bootstrapper,请将 webviewInstallMode 设置为 offlineInstaller
。这会使安装程序大小增加约 127MB,但即使没有互联网连接也可以安装你的应用。
¥To embed the WebView2 Bootstrapper, set the webviewInstallMode to offlineInstaller
.
This increases the installer size by around 127MB, but allows your application to be installed even if an internet connection is not available.
{ "bundle": { "windows": { "webviewInstallMode": { "type": "offlineInstaller" } } }}
固定版本
¥Fixed Version
使用系统提供的运行时对于安全性非常有用,因为 Webview 漏洞补丁由 Windows 管理。如果你想控制每个应用上的 WebView2 分发(自己管理发布补丁或在互联网连接可能不可用的环境中分发应用),Tauri 可以为你打包运行时文件。
¥Using the runtime provided by the system is great for security as the webview vulnerability patches are managed by Windows. If you want to control the WebView2 distribution on each of your applications (either to manage the release patches yourself or distribute applications on environments where an internet connection might not be available) Tauri can bundle the runtime files for you.
:::caution 提醒
分发固定的 WebView2 运行时版本会使 Windows 安装程序增加约 180MB。
¥Distributing a fixed WebView2 Runtime version increases the Windows Installer by around 180MB.
:::
-
从 Microsoft 网站 下载 WebView2 固定版本运行时。在此示例中,下载的文件名为
Microsoft.WebView2.FixedVersionRuntime.128.0.2739.42.x64.cab
¥Download the WebView2 fixed version runtime from Microsoft’s website. In this example, the downloaded filename is
Microsoft.WebView2.FixedVersionRuntime.128.0.2739.42.x64.cab
-
将文件解压到核心文件夹:
¥Extract the file to the core folder:
Expand .\Microsoft.WebView2.FixedVersionRuntime.128.0.2739.42.x64.cab -F:* ./src-tauri
-
在
tauri.conf.json
中配置 WebView2 运行时路径:¥Configure the WebView2 runtime path in
tauri.conf.json
:
{ "bundle": { "windows": { "webviewInstallMode": { "type": "fixedRuntime", "path": "./Microsoft.WebView2.FixedVersionRuntime.98.0.1108.50.x64/" } } }}
-
运行
tauri build
以使用固定的 WebView2 运行时生成 Windows 安装程序。¥Run
tauri build
to produce the Windows Installer with the fixed WebView2 runtime.
跳过安装
¥Skipping Installation
你可以通过将 webviewInstallMode 设置为 skip
从安装程序中删除 WebView2 运行时下载检查。如果用户未安装运行时,则你的应用将无法运行。
¥You can remove the WebView2 Runtime download check from the installer by setting webviewInstallMode to skip
.
Your application WILL NOT work if the user does not have the runtime installed.
:::warning 警告
如果用户未安装运行时且不会尝试安装,则你的应用将无法运行。
¥Your application WILL NOT work if the user does not have the runtime installed and won’t attempt to install it.
:::
{ "bundle": { "windows": { "webviewInstallMode": { "type": "skip" } } }}
自定义 WiX 安装程序
¥Customizing the WiX Installer
有关 macOS 分发选项和配置的更多信息,请参阅 WiX 配置。
¥See the WiX configuration for the complete list of customization options.
安装程序模板
¥Installer Template
.msi
Windows Installer 包是使用 WiX Toolset v3 构建的。目前,除了预定义的 configurations 之外,你还可以使用自定义 WiX 源代码(具有 .wxs
文件扩展名的 XML 文件)或通过 WiX 片段来更改它。
¥The .msi
Windows Installer package is built using the WiX Toolset v3.
Currently, apart from pre-defined configurations, you can change it by using a custom WiX source code
(an XML file with a .wxs
file extension) or through WiX fragments.
使用自定义 WiX 文件替换安装程序代码
¥Replacing the Installer Code with a Custom WiX File
Tauri 定义的 Windows 安装程序 XML 配置为适用于基于简单 WebView 的应用的常见用例(你可以在 此处 中找到它)。它使用 handlebars,因此 Tauri CLI 可以根据你的 tauri.conf.json
定义标记你的安装程序。如果你需要完全不同的安装程序,可以在 tauri.bundle.windows.wix.template
上配置自定义模板文件。
¥The Windows Installer XML defined by Tauri is configured to work for the common use case
of simple webview-based applications (you can find it here).
It uses handlebars so the Tauri CLI can brand your installer according to your tauri.conf.json
definition.
If you need a completely different installer, a custom template file can be configured on tauri.bundle.windows.wix.template
.
使用 WiX 片段扩展安装程序
¥Extending the Installer with WiX Fragments
WiX 片段 是一个容器,你可以在其中配置 WiX 提供的几乎所有内容。在此示例中,我们将定义一个写入两个注册表项的片段:
¥A WiX fragment is a container where you can configure almost everything offered by WiX. In this example, we will define a fragment that writes two registry entries:
<?xml version="1.0" encoding="utf-8"?><Wix xmlns="http://schemas.microsoft.com/wix/2006/wi"> <Fragment> <!-- these registry entries should be installed to the target user's machine --> <DirectoryRef Id="TARGETDIR"> <!-- groups together the registry entries to be installed --> <!-- Note the unique `Id` we provide here --> <Component Id="MyFragmentRegistryEntries" Guid="*"> <!-- the registry key will be under HKEY_CURRENT_USER\Software\MyCompany\MyApplicationName --> <!-- Tauri uses the second portion of the bundle identifier as the `MyCompany` name (e.g. `tauri-apps` in `com.tauri-apps.test`) --> <RegistryKey Root="HKCU" Key="Software\MyCompany\MyApplicationName" Action="createAndRemoveOnUninstall" > <!-- values to persist on the registry --> <RegistryValue Type="integer" Name="SomeIntegerValue" Value="1" KeyPath="yes" /> <RegistryValue Type="string" Value="Default Value" /> </RegistryKey> </Component> </DirectoryRef> </Fragment></Wix>
将带有 .wxs
扩展名的片段文件保存在 src-tauri/windows/fragments
文件夹中,并在 tauri.conf.json
上引用它:
¥Save the fragment file with the .wxs
extension in the src-tauri/windows/fragments
folder and reference it on tauri.conf.json
:
{ "bundle": { "windows": { "wix": { "fragmentPaths": ["./windows/fragments/registry.wxs"], "componentRefs": ["MyFragmentRegistryEntries"] } } }}
请注意,ComponentGroup
、Component
、FeatureGroup
、Feature
和 Merge
元素 ID 必须分别在 componentGroupRefs
、componentRefs
、featureGroupRefs
、featureRefs
和 mergeRefs
上的 tauri.conf.json
的 wix
对象上引用才能包含在安装程序中。
¥Note that ComponentGroup
, Component
, FeatureGroup
, Feature
and Merge
element ids must be referenced on the wix
object
of tauri.conf.json
on the componentGroupRefs
, componentRefs
, featureGroupRefs
, featureRefs
and mergeRefs
respectively to be included in the installer.
国际化
¥Internationalization
WiX 安装程序默认使用 en-US
语言构建。可以使用 tauri.bundle.windows.wix.language
属性配置国际化 (i18n),定义 Tauri 应针对哪些语言构建安装程序。你可以在 Microsoft 网站 上的 Language-Culture 列中找到要使用的语言名称。
¥The WiX Installer is built using the en-US
language by default.
Internationalization (i18n) can be configured using the tauri.bundle.windows.wix.language
property,
defining the languages Tauri should build an installer against.
You can find the language names to use in the Language-Culture column on Microsoft’s website.
编译 WiX 单一语言的安装程序
¥Compiling a WiX Installer for a Single Language
要创建针对特定语言的单个安装程序,请将 language
值设置为字符串:
¥To create a single installer targeting a specific language, set the language
value to a string:
{ "bundle": { "windows": { "wix": { "language": "fr-FR" } } }}
为列表中的每种语言编译 WiX 安装程序
¥Compiling a WiX Installer for Each Language in a List
要编译针对语言列表的安装程序,请使用数组。将为每种语言创建一个特定的安装程序,并以语言密钥作为后缀:
¥To compile an installer targeting a list of languages, use an array. A specific installer for each language will be created, with the language key as a suffix:
{ "bundle": { "windows": { "wix": { "language": ["en-US", "pt-BR", "fr-FR"] } } }}
为每种语言配置 WiX 安装程序字符串
¥Configuring the WiX Installer Strings for Each Language
可以为每种语言定义一个配置对象来配置本地化字符串:
¥A configuration object can be defined for each language to configure localization strings:
{ "bundle": { "windows": { "wix": { "language": { "en-US": null, "pt-BR": { "localePath": "./wix/locales/pt-BR.wxl" } } } } }}
localePath
属性定义语言文件的路径,即配置语言文化的 XML:
¥The localePath
property defines the path to a language file, a XML configuring the language culture:
<WixLocalization Culture="en-US" xmlns="http://schemas.microsoft.com/wix/2006/localization"> <String Id="LaunchApp"> Launch MyApplicationName </String> <String Id="DowngradeErrorMessage"> A newer version of MyApplicationName is already installed. </String> <String Id="PathEnvVarFeature"> Add the install location of the MyApplicationName executable to the PATH system environment variable. This allows the MyApplicationName executable to be called from any location. </String> <String Id="InstallAppFeature"> Installs MyApplicationName. </String></WixLocalization>
:::note 注意
WixLocalization
元素的 Culture
字段必须与配置的语言匹配。
¥The WixLocalization
element’s Culture
field must match the configured language.
:::
目前,Tauri 引用以下语言环境字符串:LaunchApp
、DowngradeErrorMessage
、PathEnvVarFeature
和 InstallAppFeature
。你可以定义自己的字符串并使用 "!(loc.TheStringId)"
在自定义模板或片段上引用它们。有关更多信息,请参阅 WiX 本地化文档。
¥Currently, Tauri references the following locale strings: LaunchApp
, DowngradeErrorMessage
, PathEnvVarFeature
and InstallAppFeature
.
You can define your own strings and reference them on your custom template or fragments with "!(loc.TheStringId)"
.
See the WiX localization documentation for more information.
自定义 NSIS 安装程序
¥Customizing the NSIS Installer
有关 macOS 分发选项和配置的更多信息,请参阅 NSIS 配置。
¥See the NSIS configuration for the complete list of customization options.
安装程序模板
¥Installer Template
Tauri 定义的 NSIS 安装程序的 .nsi
脚本配置为适用于基于简单 webview 的应用的常见用例(你可以在 此处 中找到它)。它使用 handlebars,因此 Tauri CLI 可以根据你的 tauri.conf.json
定义标记你的安装程序。如果你需要完全不同的安装程序,可以在 tauri.bundle.windows.nsis.template
上配置自定义模板文件。
¥The NSIS Installer’s .nsi
script defined by Tauri is configured to work for the common use case
of simple webview-based applications (you can find it here).
It uses handlebars so the Tauri CLI can brand your installer according to your tauri.conf.json
definition.
If you need a completely different installer, a custom template file can be configured on tauri.bundle.windows.nsis.template
.
扩展安装程序
¥Extending the Installer
如果你只需要扩展一些安装步骤,你可能能够使用安装程序钩子,而不是替换整个安装程序模板。
¥If you only need to extend some installation steps you might be able to use installer hooks instead of replacing the entire installer template.
支持的钩子有:
¥Supported hooks are:
-
NSIS_HOOK_PREINSTALL
:在复制文件、设置注册表项值和创建快捷方式之前运行。¥
NSIS_HOOK_PREINSTALL
: Runs before copying files, setting registry key values and creating shortcuts. -
NSIS_HOOK_POSTINSTALL
:在安装程序完成复制所有文件、设置注册表项和创建快捷方式后运行。¥
NSIS_HOOK_POSTINSTALL
: Runs after the installer has finished copying all files, setting the registry keys and created shortcuts. -
NSIS_HOOK_PREUNINSTALL
:在删除任何文件、注册表项和快捷方式之前运行。¥
NSIS_HOOK_PREUNINSTALL
: Runs before removing any files, registry keys and shortcuts. -
NSIS_HOOK_POSTUNINSTALL
:在文件、注册表项和快捷方式被删除后运行。¥
NSIS_HOOK_POSTUNINSTALL
: Runs after files, registry keys and shortcuts have been removed.
例如,在 src-tauri/windows
文件夹中创建一个 hooks.nsi
文件并定义所需的钩子:
¥For example, create a hooks.nsi
file in the src-tauri/windows
folder and define the hooks you need:
!macro NSIS_HOOK_PREINSTALL MessageBox MB_OK "PreInstall"!macroend
!macro NSIS_HOOK_POSTINSTALL MessageBox MB_OK "PostInstall"!macroend
!macro NSIS_HOOK_PREUNINSTALL MessageBox MB_OK "PreUnInstall"!macroend
!macro NSIS_HOOK_POSTUNINSTALL MessageBox MB_OK "PostUninstall"!macroend
然后你必须配置 Tauri 以使用该钩子文件:
¥Then you must configure Tauri to use that hook file:
{ "bundle": { "windows": { "nsis": { "installerHooks": "./windows/hooks.nsi" } } }}
安装模式
¥Install Modes
默认情况下,安装程序将仅为当前用户安装你的应用。此选项的优点是安装程序不需要管理员权限即可运行,但应用安装在 %LOCALAPPDATA%
文件夹中而不是 C:/Program Files
中。
¥By default the installer will install your application for the current user only.
The advantage of this option is that the installer does not require Administrator privileges to run,
but the app is installed in the %LOCALAPPDATA%
folder instead of C:/Program Files
.
如果你希望你的应用安装在整个系统范围内可用(这需要管理员权限),你可以将 installMode 设置为 perMachine
:
¥If you prefer your app installation to be available system-wide (which requires Administrator privileges)
you can set installMode to perMachine
:
{ "bundle": { "windows": { "nsis": { "installMode": "perMachine" } } }}
或者,你可以通过将 installMode 设置为 both
让用户选择是仅为当前用户安装应用还是全系统安装应用。请注意,安装程序需要管理员权限才能执行。
¥Alternatively you can let the user choose whether the app should be installed for the current user only or system-wide
by setting the installMode to both
.
Note that the installer will require Administrator privileges to execute.
有关更多信息,请参阅 NSISInstallerMode。
¥See NSISInstallerMode for more information.
国际化
¥Internationalization
NSIS 安装程序是一个多语言安装程序,这意味着你始终有一个包含所有选定翻译的安装程序。
¥The NSIS Installer is a multi-language installer, which means you always have a single installer which contains all the selected translations.
你可以使用 tauri.bundle.windows.nsis.languages
属性指定要包含哪些语言。NSIS 支持的语言列表在 NSIS GitHub 项目 中可用。需要几个 Tauri 特定翻译,因此如果你看到未翻译的文本,请随时在 Tauri 的主要存储库 中打开功能请求。你还可以提供 自定义翻译文件。
¥You can specify which languages to include using the tauri.bundle.windows.nsis.languages
property.
A list of languages supported by NSIS is available in the NSIS GitHub project.
There are a few Tauri-specific translations required, so if you see untranslated texts feel free to open a feature request in Tauri’s main repo.
You can also provide custom translation files.
默认情况下,操作系统默认语言用于确定安装程序语言。你还可以配置安装程序以在渲染安装程序内容之前显示语言选择器:
¥By default the operating system default language is used to determine the installer language. You can also configure the installer to display a language selector before the installer contents are rendered:
{ "bundle": { "windows": { "nsis": { "displayLanguageSelector": true } } }}
最低 Webview2 版本
¥Minimum Webview2 version
如果你的应用需要仅在较新的 Webview2 版本中可用的功能(例如自定义 URI 方案),你可以指示 Windows 安装程序验证当前 Webview2 版本,并在其与目标版本不匹配时运行 Webview2 引导程序。
¥If your app requires features only available in newer Webview2 versions (such as custom URI schemes), you can instruct the Windows installer to verify the current Webview2 version and run the Webview2 bootstrapper if it does not match the target version.
{ "bundle": { "windows": { "nsis": { "minimumWebview2Version": "110.0.1531.0" } } }}
Tauri 中文网 - 粤ICP备13048890号