Skip to content

Commit 5d3a540

Browse files
authored
Update Windows Installer page to include setup-only dependency example (#3357)
1 parent 8138062 commit 5d3a540

File tree

1 file changed

+65
-2
lines changed

1 file changed

+65
-2
lines changed

src/content/docs/distribute/windows-installer.mdx

Lines changed: 65 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -527,7 +527,7 @@ Supported hooks are:
527527
- `NSIS_HOOK_PREUNINSTALL`: Runs before removing any files, registry keys and shortcuts.
528528
- `NSIS_HOOK_POSTUNINSTALL`: Runs after files, registry keys and shortcuts have been removed.
529529

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:
531531

532532
```nsh
533533
!macro NSIS_HOOK_PREINSTALL
@@ -554,13 +554,74 @@ Then you must configure Tauri to use that hook file:
554554
"bundle": {
555555
"windows": {
556556
"nsis": {
557-
"installerHooks": "./windows/hooks.nsi"
557+
"installerHooks": "./windows/hooks.nsh"
558558
}
559559
}
560560
}
561561
}
562562
```
563563

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)
573+
ReadRegDWord $0 HKLM "SOFTWARE\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" "Installed"
574+
575+
${If} $0 == 1
576+
DetailPrint "Visual C++ Redistributable already installed"
577+
Goto vcredist_done
578+
${EndIf}
579+
580+
; Install from bundled MSI if not installed
581+
${If} ${FileExists} "$INSTDIR\resources\vc_redist.x64.msi"
582+
DetailPrint "Installing Visual C++ Redistributable..."
583+
; Copy to TEMP folder and then execute installer
584+
CopyFiles "$INSTDIR\resources\vc_redist.x64.msi" "$TEMP\vc_redist.x64.msi"
585+
ExecWait 'msiexec /i "$TEMP\vc_redist.x64.msi" /passive /norestart' $0
586+
587+
; 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+
564625
### Install Modes
565626

566627
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
651712
[NSIS configuration]: /reference/config/#nsisconfig
652713
[installMode]: /reference/config/#installmode
653714
[NSISInstallerMode]: /reference/config/#nsisinstallermode
715+
[where]: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/where
716+
[msiexec]: https://learn.microsoft.com/en-us/windows-server/administration/windows-commands/msiexec

0 commit comments

Comments
 (0)