Search code examples
nsis

makensis does not seem to work with /D command line option


I have made a NSIS script with the contents to pack my executables to one single file. It works fine. Was playing around with few command line options and of course planning to sign the uninstaller.

Here is the snippet of the script and I dont understand why this does not work.

Function .onInit

!ifdef GEN_ONLY_UNINSTALLER
WriteUninstaller "out\uninst.exe"
Quit
!endif

FunctionEnd

When using this command line option:

makensis /DGEN_ONLY_UNINSTALLER /V0 _Release_only_uninst.nsi

It does not write the uninstaller and quit. What am I missing here? Where should the WriteUninstaller go? I suspect I am not calling it in right place. :)


Solution

  • You are only doing half the job, you need to execute the generated installer for the WriteUninstaller call to be executed.

    To get a uninstaller you can sign you must:

    1. Run makensis on a uninstaller specific .nsi
    2. The same .nsi executes makensis /Dmysymbol with !system on itself (Compare exit code with 0)
    3. Use !system to execute the installer generated in step 2 (WriteUninstaller will now write the uninstaller)
    4. !delfile installer generated in step 2

    Roughly something like this:

    !ifdef STEP2
    Function .onInit
    WriteUninstaller "out\uninst.exe"
    Quit
    FunctionEnd
    Outfile "$%temp%\genun.exe"
    Section
    SectionEnd
    !else
    !system '"makensis" /DSTEP2 "${__FILE__}"' = 0
    !system '"$%temp%\genun.exe" /S'
    !delfile "$%temp%\genun.exe"
    !endif
    

    This script will fail with an error since the initial makensis instance will not generate a valid installer, this is usually not a problem because this code can be added to the script that creates the real installer... (The full script would generate the uninstaller, sign it, generate the installer and then sign that)