美文网首页
NSIS 打包流程及注意事项

NSIS 打包流程及注意事项

作者: 哈哈笑321 | 来源:发表于2018-08-30 17:32 被阅读0次

    制作流程

    1. 安装nsis.exe,例如安装到:D:\Program Files (x86)\NSIS注意:将此路径添加到系统的环境变量Path中
    2. 编辑配置文件 setup_x64.nsi,将此文件放到要打包的文件夹中。
      示例:
    ;--------------------------------
    
    Unicode true
    ShowInstDetails show
    
    !ifdef VERSION
    !else
      !define VERSION 2.0.0.0 git commit 00000000
    !endif
    
    ; The name of the installer
    !define APPNAME "Client"
    !define BinaryNAME "${APPNAME}.exe"
    !define COMPANYNAME "myCompany"
    !define DESCRIPTION "This is ${APPNAME}"
    !define StartupProgram "$INSTDIR\${APPNAME}.exe"
    !define StartMenu_Folder "$SMPROGRAMS\${COMPANYNAME}\${APPNAME}"
    !define UserGuide "$INSTDIR\guideline.pdf"
    
    Name "${COMPANYNAME}'s ${APPNAME}64 ${VERSION} ${GIT}"
    
    ;Name and file
    OutFile "${APPNAME}64Setup ${VERSION}(git_${GIT}_${AUTHOR}_${TIME}).exe"
    InstallDir "$PROGRAMFILES64\${COMPANYNAME}\${APPNAME}"
    ; Request application privileges for Windows Vista
    ; RequestExecutionLevel admin
    
    VIProductVersion ${VERSION}
    VIAddVersionKey ProductName "${APPNAME}"
    VIAddVersionKey CompanyName "${COMPANYNAME}"
    VIAddVersionKey LegalCopyright "http://www.myCompany.com.cn/"
    VIAddVersionKey FileVersion ${Version}
    VIAddVersionKey FileDescription ""
    VIAddVersionKey ProductVersion ${Version}
    VIAddVersionKey InternalName "${COMPANYNAME} Launcher"
    
    DirText "This will install myCompany Corp's ${APPNAME} 64Bits software to your computer. Please close ${APPNAME} software and keep default install directory.$\r$\n${VERSION}, Git: ${GIT}, Author: ${AUTHOR}, Time: ${TIME}"
    
    ;--------------------------------
    ; Pages
    Page components
    Page directory
    Page instfiles
    
    UninstPage uninstConfirm
    UninstPage instfiles
    
    ;--------------------------------
    ; The stuff to install
    
    ; SilentInstall silent
    ; SilentUninstall silent
    
    Section "${APPNAME}64 (required)"
        SectionIn RO
    
        ExecWait "taskkill /f /im ${BinaryNAME}"
    
        ; Set output path to the installation directory.
        SetOutPath $INSTDIR
        WriteUninstaller "uninstall.exe"
    
        ; Put file there
        ; File /r /x "log" /x "${APPNAME}.log" /x "${APPNAME}.exe.log" /x "dump" "dist"
        File /r /x setup_x64.nsi *.*
    
        ; CreateDirectory $INSTDIR\dist
        ; SetOutPath $INSTDIR\dist
        ; File thunderdog.json.origin settings_webthreed.json version
    
        ; write reg info
        SetRegView 64
        WriteRegStr HKLM "Software\myCompany\TrPanorama" "InstalledPath" "${StartupProgram}"
    
        ; desktop
        CreateShortcut "$DESKTOP\${APPNAME}.lnk" "${StartupProgram}"
    
        ; shortcuts
        CreateDirectory "${StartMenu_Folder}"
        CreateShortcut "${StartMenu_Folder}\${APPNAME}_uninstall.lnk" "$INSTDIR\uninstall.exe" "" "$INSTDIR\uninstall.exe" 0
        CreateShortcut "${StartMenu_Folder}\${APPNAME}_startup.lnk" "${StartupProgram}" ""
        SetAutoClose True
    SectionEnd
    
    ;--------------------------------
    ; Uninstaller
    Section "Uninstall"
        ExecWait "taskkill /f /im ${BinaryNAME}"
    
        ; Desktop
        Delete "$DESKTOP\${APPNAME}.lnk"
    
        ; Remove files and uninstaller
        Delete $INSTDIR\*.*
    
        ; Remove shortcuts, if any
        Delete "${StartMenu_Folder}\*.*"
    
        ; Remove directories used
        ; Delete "$INSTDIR\dist\log\*.*"
        ; Delete "$INSTDIR\dist\*.*"
        ; RMDir /r "$INSTDIR\dist\log"
        ; RMDir /r "$INSTDIR\dist"
        RMDir /r "$INSTDIR"
    
        ; delete reg info
        DeleteRegKey HKLM "software\myCompany"
    
        ExecWait '"schtasks.exe" /f /delete /tn ${APPNAME}'
        SetAutoClose True
    SectionEnd
    
    1. 打开命令行,切换到待打包的文件夹路径。
    2. 运行 makensis.exe /DVERSION=2.0.0.0 /DGIT=55f0948d /DAUTHOR=%git_user_name% /DTIME=%timestamp% setup_x64.nsi

    VERSION: 版本号
    GIT: 对应的Git版本号
    AUTHOR: 作者
    TIME: 日期,例如:201808081810,必须12位数字,替换%timestamp%。

    如果失败,请重启一下电脑。

    运行结果如下: nsis.PNG

    遇到问题

    1. File命令的参数,需要移除的文件放在前面,/x AAA,包含的文件放在末尾。
    • File /r /x log ; 会报错,没有包含要添加的文件
    • File /r /x log *.* ; 正常
    1. 写注册表
      在windows 10 x64系统中,计划在 \HKEY_LOCAL_MACHINE\SOFTWARE\Company\Client下面添加值,使用

    WriteRegStr HKLM "Software\Company\Client" "InstalledPath" "data"

    被写到了:\HKEY_LOCAL_MACHINE\SOFTWARE\WOW6432Node下面,解答来自https://stackoverflow.com/questions/11150238/writing-registry-value-in-a-64-bit-system

    SetRegView64 ; 64位系统
    WriteRegDWORD HKLM "SOFTWARE\" "VersionNo"0
    SetRegView32 ; 32位系统
    WriteRegStr HKLM "SOFTWARE\" "VersionNo" "11"

    相关文章

      网友评论

          本文标题:NSIS 打包流程及注意事项

          本文链接:https://www.haomeiwen.com/subject/hxkdwftx.html