Electron Builder支持NSIS格式输出构建产物。NSIS可以使用NSH来定制安装过程,以下为安装VC Redist示例:
!macro customHeader
;vc redist需要管理员权限
RequestExecutionLevel admin
!macroend
!macro customInstall
; install vc-redist if not installed
ReadRegStr $1 HKLM "SOFTWARE\WOW6432Node\Microsoft\VisualStudio\14.0\VC\Runtimes\x64" "Installed"
StrCmp $1 1 installed
;not installed, so run the installer
;这是在安装的过程中执行,所以需要打包的时候把安装包提前集成进来,或者从网络下载
ExecWait '"$INSTDIR\resources\VcRedist\2022\14.38.33135.0\x64\VC_redist.x64.exe" /install /quiet /norestart'
installed:
;we are done
!macroend
对应的electron-builder.json配置项
{
"nsis": {
"include": "vc-redist/install-vcredist.nsh"
}
}