You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardExpand all lines: src/content/docs/distribute/windows-installer.mdx
+65-2Lines changed: 65 additions & 2 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -527,7 +527,7 @@ Supported hooks are:
527
527
-`NSIS_HOOK_PREUNINSTALL`: Runs before removing any files, registry keys and shortcuts.
528
528
-`NSIS_HOOK_POSTUNINSTALL`: Runs after files, registry keys and shortcuts have been removed.
529
529
530
-
For example, create a `hooks.nsi` file in the `src-tauri/windows` folder and define the hooks you need:
530
+
For example, create a `hooks.nsh` file in the `src-tauri/windows` folder and define the hooks you need:
531
531
532
532
```nsh
533
533
!macro NSIS_HOOK_PREINSTALL
@@ -554,13 +554,74 @@ Then you must configure Tauri to use that hook file:
554
554
"bundle": {
555
555
"windows": {
556
556
"nsis": {
557
-
"installerHooks": "./windows/hooks.nsi"
557
+
"installerHooks": "./windows/hooks.nsh"
558
558
}
559
559
}
560
560
}
561
561
}
562
562
```
563
563
564
+
#### Installing Dependencies with Hooks
565
+
566
+
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.
567
+
568
+
**MSI Installer Example (Visual C++ Redistributable):**
569
+
570
+
```nsh
571
+
!macro NSIS_HOOK_POSTINSTALL
572
+
; Check if Visual C++ 2019 Redistributable is installed (via Windows Registry)
; Check wether installation process exited successfully (code 0) or not
588
+
${If} $0 == 0
589
+
DetailPrint "Visual C++ Redistributable installed successfully"
590
+
${Else}
591
+
MessageBox MB_ICONEXCLAMATION "Visual C++ installation failed. Some features may not work."
592
+
${EndIf}
593
+
594
+
; Clean up setup files from TEMP and your installed app
595
+
Delete "$TEMP\vc_redist.x64.msi"
596
+
Delete "$INSTDIR\resources\vc_redist.x64.msi"
597
+
${EndIf}
598
+
599
+
vcredist_done:
600
+
!macroend
601
+
```
602
+
603
+
**Key considerations:**
604
+
605
+
- A good practice is to always check if the dependency is already installed using registry keys or file existence or via Windows [where] command.
606
+
- 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
607
+
- Include `/norestart` to prevent automatic system reboots during installation for setups that restarts user devices
608
+
- Clean up temporary files and bundled installers to avoid bloating the application
609
+
- Consider that dependencies might be shared with other applications when uninstalling
610
+
- Provide meaningful error messages if installation fails
611
+
612
+
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\`:
613
+
614
+
```json title="tauri.conf.json"
615
+
{
616
+
"bundle": {
617
+
"resources": [
618
+
"resources/my-dependency.exe",
619
+
"resources/another-one.msi
620
+
]
621
+
}
622
+
}
623
+
```
624
+
564
625
### Install Modes
565
626
566
627
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
0 commit comments