Inno Setup is a great software installer creator. I use it with Visual Studio as a post-build step to package my software. This software is available as a NuGet package – Tools.InnoSetup.
Unfortunately some capabilities are not as clear as they should be. I needed to set the file path for an assembly that should be included in the installer. However, the path differed if it was a Release vs Debug build. Below is the Inno line if it is a Release build.
[Files] Source: "..\bin\Release\{#ShellPackageDLL}"; DestDir: "{app}"; Flags: ignoreversion;
After a couple hours of bread crumbs, I found the magic required to pass a command line variable into the Inno .iss
file. Be aware that if you insert a space between the /D
and the first letter of the name, Inno will generate an error. Below is the post-build step where I pass the name/value pair “BuildConfig” into Inno by prefixing the pair with a /D
.
"$(SolutionDir)packages\Tools.InnoSetup.6.2.0\tools\iscc.exe" /DBuildConfig="$(ConfigurationName)" "$(ProjectDir)InstallerConfig\Package.iss"
Visual Studio will replace $(ConfigurationName)
with the current build configuration name (Release or Debug, in my example). To use the new variable, I replaced the original Inno line with below.
[Files] Source: "..\bin\{#BuildConfig}\{#ShellPackageDLL}"; DestDir: "{app}"; Flags: ignoreversion;
You can also use the arguments to create constants to use in other places. In this case, ProjDir
and BuildConfiguration
are command line supplied values. Be careful about the somewhat unclear rules for when a command line parameter must be prefaced with a #
character and when it is not needed.
#define MyAppName "Mystery.exe" ; EXE explicit path. #define MyAppBuildPath ProjDir + "bin\" + BuildConfiguration + "\" + MyAppName
Alternatively…
You can also use the {param:ParamName|DefaultValue}
to provide similar functionality. Additionally, this method allows you to specify a default value if not supplied on the command line.