简体   繁体   English

在NSIS安装程序中包含文件,但不一定安装它们吗?

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

Trying to build out a custom NSIS installer from scratch. 尝试从头开始构建自定义NSIS安装程序。

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. 我看到了一个File命令,其中包含要安装的文件,但是我很难弄清楚如何有选择地安装文件。 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. 我的用例是,我想为.NET Core x86应用程序,.NET Core x64应用程序和.NET 4.6.1 AnyCpu应用程序创建一个安装程序。

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. 我想我已经弄清楚了如何确定文件应该去哪里...但是在64位计算机上,我不想安装32位文件,对于32位,则反之亦然操作系统。

The File command suggests an output. File命令建议输出。 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 NSIS提供了几种检查条件的方法,例如StrCmpIntCmp ,但是最简单的方法可能是使用LogicLib

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: 如果您不需要用户选择,则可以根据某些条件执行所需的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

If you want the user to be able to choose you can put the File commands in different sections: 如果希望用户能够选择,可以将“ 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