从简单到完整,Liam平平带你一步步制作完美安装包, 万事开头难。
第一课:制作一个安装包,运行后将安装包中文件安装到指定位置。
一、 下载安装NSIS
官方下载地址:https://nsis.sourceforge.io/Download
二、编写脚本
- 新建一个脚本文件, 如:test1.nsi
; The name of the installer Name "HelloLiam" ; The file to write OutFile "hello_liam_setup.exe" ; Request application privileges for Windows Vista RequestExecutionLevel user ; Build Unicode installer Unicode True ; The default installation directory InstallDir $PROGRAMFILES64\HelloLiam ;Request application privileges for Windows Vista RequestExecutionLevel admin ;-------------------------------- ; Pages Page directory Page instfiles ;-------------------------------- ; The stuff to install Section "" ;No components page, name is not important ; Set output path to the installation directory. SetOutPath $INSTDIR ; Put file there ;File HelloLiam.exe ;add a file. File /r "InstallFiles\*.*" SectionEnd ; end the section
- 准备需要打包的文件,示例放在脚本同目录的InstallFiles文件夹下
需要打包的文件:
- 编辑脚本:推荐使用VS Code安装代码高亮插件。
三、 运行脚本生成安装包
- 打开NSIS软件
- 打开示例test1.nsi
- 生成exe安装包
四、测试安装
- 直接点击测试安装,或手动运行exe安装包
- 路径选择界面:
- 安装完成界面
- 安装后的效果
End
欢迎查看后期教程:
- 创建快捷方式。
- 创建卸载程序。
- 界面美化。
- 判断是否正在运行。
- 判断并安装VC运行库。