簡體   English   中英

在NSIS安裝程序中包含文件,但不一定安裝它們嗎?

[英]Include files in NSIS installer, but don't necessarily install them?

嘗試從頭開始構建自定義NSIS安裝程序。

我看到了一個File命令,其中包含要安裝的文件,但是我很難弄清楚如何有選擇地安裝文件。 我的用例是,我想為.NET Core x86應用程序,.NET Core x64應用程序和.NET 4.6.1 AnyCpu應用程序創建一個安裝程序。

我想我已經弄清楚了如何確定文件應該去哪里...但是在64位計算機上,我不想安裝32位文件,對於32位,則反之亦然操作系統。

File命令建議輸出。 如何將所有三個項目的目錄都包含在安裝程序中,但實際上只為系統安裝適當的文件?

NSIS提供了幾種檢查條件的方法,例如StrCmpIntCmp ,但是最簡單的方法可能是使用LogicLib

例:

!include "LogicLib.nsh"
!include "x64.nsh"

Section
  ${If} ${RunningX64}
      File "that_64bit_file"
  ${Else}
      File "that_32bit_file"
  ${EndIf}
SectionEnd

有兩種方法可以有條件地安裝文件。 如果您不需要用戶選擇,則可以根據某些條件執行所需的File命令:

!include "LogicLib.nsh"
!include "x64.nsh"

Section
  SetOutPath $InstDir
  ${If} ${RunningX64}
      File "myfiles\amd64\app.exe"
  ${Else}
      File "myfiles\x86\app.exe"
  ${EndIf}
SectionEnd

如果希望用戶能夠選擇,可以將“ File命令放在不同的部分中:

!include "LogicLib.nsh"
!include "x64.nsh"
!include "Sections.nsh"

Page Components
Page Directory
Page InstFiles

Section /o "Native 32-bit" SID_x86
  SetOutPath $InstDir
  File "myfiles\x86\app.exe"
SectionEnd

Section /o "Native 64-bit" SID_AMD64
  SetOutPath $InstDir
  File "myfiles\amd64\app.exe"
SectionEnd

Section "AnyCPU" SID_AnyCPU
  SetOutPath $InstDir
  File "myfiles\anycpu\app.exe"
SectionEnd

Var CPUCurrSel

Function .onInit
  StrCpy $CPUCurrSel ${SID_AnyCPU} ; The default
  ${If} ${RunningX64}
    !insertmacro RemoveSection ${SID_x86}
  ${Else}
    !insertmacro RemoveSection ${SID_AMD64}
  ${EndIf}
FunctionEnd

Function .onSelChange
  !insertmacro StartRadioButtons $CPUCurrSel
    !insertmacro RadioButton ${SID_x86}
    !insertmacro RadioButton ${SID_AMD64}
    !insertmacro RadioButton ${SID_AnyCPU}
  !insertmacro EndRadioButtons
FunctionEnd

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM