简体   繁体   中英

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

Trying to build out a custom NSIS installer from scratch.

I see a File command for including files you want to be installed, but I'm having difficulty figuring out how to selectively install files. My use case is, I want to create a single installer for my .NET Core x86 application, my .NET Core x64 application, and my .NET 4.6.1 AnyCpu application.

I think I've figured out how to determine where the files should go... but on a 64-bit machine, I don't want to install the 32-bit files, and vice-versa for the for the 32-bit OS.

The File command suggests an output. How do I include the directories for all three projects into the installer, but only actually install the proper files for the system?

NSIS offers several ways to check conditions, for example StrCmp or IntCmp , but the easiest is probably using the LogicLib library

Example:

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

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

There are two ways to conditionally install files. If you don't need to let the user choose you can just execute the desired File commands depending on some condition:

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

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

If you want the user to be able to choose you can put the File commands in different sections:

!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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM