How do I conditionally compile an NSIS script based on commandline parameters?
Asked Answered
N

1

5

I'm trying to generalize a setup file by externally passing the version number. I want to be able to do this:

makensis myscript.nsi parameter=value

and then read the parameter within the script, so that using the same script I can generate differently versioned executables. I found this & this, but they seem to be for passing commandline parameters to the generated setup.exe. Is this possible, and how?

Nonscheduled answered 30/11, 2011 at 12:4 Comment(7)
Check out this answer https://mcmap.net/q/1495800/-nsis-installer-nameBlaseio
The linked answer does what you want. I'm not going to vote to close this question though since the title and goal of the question are very different from your.Serum
@DavidHall: How is it different? The installer name is an attribute you can only set at compile time! The goal is pretty much the same...Doggett
possible duplicate of NSIS Installer NameDoggett
@Doggett I'm not sure that someone searching for how to set compile time parameters in NSIS would find the other question - it doesn't mention any terms like "commandline". They are in the answer of course. I considered asking on meta actually for opinions on what to do since this question strikes me as better (or at least more widely useful than the other) yet it will be the one closed.Serum
@DavidHall: Yes, I agree this question is better.Doggett
This is one of those times where two questions aren't duplicates but can be answered the same way. If anyone wants to give an answer here, feel free.Cuneiform
S
8

You can add symbols to the globally defined list from the command line using the /D switch:

makensis /DMyVersion="1.0.1" install.nsi

Then you can use them using the ${} syntax:

!ifdef MyVersion
    StrCpy $Version "${MyInstallerName}"
!else
    StrCpy $Version "1.0.0"
!endif

Also of possible interest is the GetVersion plugin discussed in this SO question: NSIS - put EXE version into name of installer

Serum answered 30/11, 2011 at 19:36 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.