mirror of
https://github.com/tauri-apps/tauri-docs.git
synced 2026-01-31 00:35:16 +01:00
Update Windows Installer page to include setup-only dependency example (#3357)
This commit is contained in:
@@ -527,7 +527,7 @@ Supported hooks are:
|
||||
- `NSIS_HOOK_PREUNINSTALL`: Runs before removing any files, registry keys and shortcuts.
|
||||
- `NSIS_HOOK_POSTUNINSTALL`: Runs after files, registry keys and shortcuts have been removed.
|
||||
|
||||
For example, create a `hooks.nsi` file in the `src-tauri/windows` folder and define the hooks you need:
|
||||
For example, create a `hooks.nsh` file in the `src-tauri/windows` folder and define the hooks you need:
|
||||
|
||||
```nsh
|
||||
!macro NSIS_HOOK_PREINSTALL
|
||||
@@ -554,13 +554,74 @@ Then you must configure Tauri to use that hook file:
|
||||
"bundle": {
|
||||
"windows": {
|
||||
"nsis": {
|
||||
"installerHooks": "./windows/hooks.nsi"
|
||||
"installerHooks": "./windows/hooks.nsh"
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
#### Installing Dependencies with Hooks
|
||||
|
||||
You can use installer hooks to automatically install system dependencies that your application requires. This is particularly useful for runtime dependencies like Visual C++ Redistributables, DirectX, OpenSSL or other system libraries that may not be present on all Windows systems.
|
||||
|
||||
**MSI Installer Example (Visual C++ Redistributable):**
|
||||
|
||||
```nsh
|
||||
!macro NSIS_HOOK_POSTINSTALL
|
||||
; Check if Visual C++ 2019 Redistributable is installed (via Windows Registry)
|
||||
ReadRegDWord $0 HKLM "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" "Installed"
|
||||
|
||||
${If} $0 == 1
|
||||
DetailPrint "Visual C++ Redistributable already installed"
|
||||
Goto vcredist_done
|
||||
${EndIf}
|
||||
|
||||
; Install from bundled MSI if not installed
|
||||
${If} ${FileExists} "$INSTDIR\resources\vc_redist.x64.msi"
|
||||
DetailPrint "Installing Visual C++ Redistributable..."
|
||||
; Copy to TEMP folder and then execute installer
|
||||
CopyFiles "$INSTDIR\resources\vc_redist.x64.msi" "$TEMP\vc_redist.x64.msi"
|
||||
ExecWait 'msiexec /i "$TEMP\vc_redist.x64.msi" /passive /norestart' $0
|
||||
|
||||
; Check wether installation process exited successfully (code 0) or not
|
||||
${If} $0 == 0
|
||||
DetailPrint "Visual C++ Redistributable installed successfully"
|
||||
${Else}
|
||||
MessageBox MB_ICONEXCLAMATION "Visual C++ installation failed. Some features may not work."
|
||||
${EndIf}
|
||||
|
||||
; Clean up setup files from TEMP and your installed app
|
||||
Delete "$TEMP\vc_redist.x64.msi"
|
||||
Delete "$INSTDIR\resources\vc_redist.x64.msi"
|
||||
${EndIf}
|
||||
|
||||
vcredist_done:
|
||||
!macroend
|
||||
```
|
||||
|
||||
**Key considerations:**
|
||||
|
||||
- A good practice is to always check if the dependency is already installed using registry keys or file existence or via Windows [where] command.
|
||||
- Use `/passive`, `/quiet`, or `/silent` flags to avoid interrupting the installation flow. Check out [msiexec] options for `.msi` files, or the setup manual for app-specific flags
|
||||
- Include `/norestart` to prevent automatic system reboots during installation for setups that restarts user devices
|
||||
- Clean up temporary files and bundled installers to avoid bloating the application
|
||||
- Consider that dependencies might be shared with other applications when uninstalling
|
||||
- Provide meaningful error messages if installation fails
|
||||
|
||||
Ensure to bundle the dependency installers in your `src-tauri/resources` folder and add to `tauri.conf.json` so they get bundled, and can be accessed during installation from `$INSTDIR\resources\`:
|
||||
|
||||
```json title="tauri.conf.json"
|
||||
{
|
||||
"bundle": {
|
||||
"resources": [
|
||||
"resources/my-dependency.exe",
|
||||
"resources/another-one.msi
|
||||
]
|
||||
}
|
||||
}
|
||||
```
|
||||
|
||||
### Install Modes
|
||||
|
||||
By default the installer will install your application for the current user only.
|
||||
@@ -651,3 +712,5 @@ to verify the current Webview2 version and run the Webview2 bootstrapper if it d
|
||||
[NSIS configuration]: /reference/config/#nsisconfig
|
||||
[installMode]: /reference/config/#installmode
|
||||
[NSISInstallerMode]: /reference/config/#nsisinstallermode
|
||||
[where]: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/where
|
||||
[msiexec]: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/msiexec
|
||||
|
||||
Reference in New Issue
Block a user