Search code examples
nsis

How do you embed files (.exe .txt etc) into an NSIS installer to create one large .EXE installer package?


I have a few files that I want my NSIS installer to extract and install. These are .exe file (my main app), .txt Readme, License files, .ICO graphics file.

I want to embed these into the complied NSIS installer to give the user one large install file. What are the commands to embed files into the installer and commands to tell NSIS to extract the embedded files? I've looked at some documentation but all I could find was the mention of zipping them, - I think NSIS has a 7unzipper inside it (?)

I want to extract the embedded files all into my $INSTDIR

This is the order of my pages in NSIS

  !insertmacro MUI_PAGE_WELCOME
  !insertmacro MUI_PAGE_LICENSE "${NSISDIR}\Docs\Modern UI\License.txt"
  !insertmacro MUI_PAGE_DIRECTORY
  !insertmacro MUI_PAGE_INSTFILES
  !insertmacro MUI_PAGE_FINISH

  !insertmacro MUI_UNPAGE_WELCOME
  !insertmacro MUI_UNPAGE_CONFIRM
  !insertmacro MUI_UNPAGE_INSTFILES
  !insertmacro MUI_UNPAGE_FINISH

Solution

  • Example1.nsi shows you how to use the File instruction.

    A very minimal installer looks like this:

    Name "Test"
    OutFile "TestInstaller.exe"
    InstallDir "$Desktop\Test" ; Default install directory
    
    Page Directory ; Let the user choose the $InstDir
    Page InstFiles ; Sections are executed on this page
    
    Section
    SetOutPath $InstDir ; Create and set output path
    File "c:\myinstallerfiles\MyFile.txt" ; Extract MyFile.txt to $InstDir
    SectionEnd
    

    The File instruction compresses a file from your local machine into the installer and when the user runs the installer the file is extracted to the directory set by SetOutPath.