0

I'm using InnoSetup 6 (Windows 10, Visual Studio Code and WSL as my shell) to create an installer. This ISCC compiler is called from from an automated script. That script is in charge of setting environment variables holding the generated installer version and generated installer name. Both of them are intented to be used for the InnoSetup installer compiler (iscc.exe) called by the script. I'm using envvars because I do not want to mess my ISS file with hard-wired versions numbers.

I thought using environment variables was possible in Innosetup, as per this question here on StackOverflow (Can one use environment variables in Inno Setup scripts?).

Unfortunately, Innosetup complains with "The [Setup] section must include an AppVersion or AppVerName directive.". Like if the GetEnv() yield an empty string.

I tried calling ISCC from the command line manually like this :

export JFROG_DEFAULTGROUPS_VERSION=1.0.0-1 && [path..]\iscc.exe myiss.iss

Or even exporting the environment variable using export :

export JFROG_DEFAULTGROUPS_VERSION=1.0.0-1

, then checking the environment variable was actually set and starting the compiler : env [path..]\iscc.exe myiss.iss

In this case, env yield the following :

JFROG_DEFAULTGROUPS_VERSION=1.0.0-1
SHELL=/bin/bash
PATH=[...]
[...]

This makes me think the environment is set, as per my shell (WSL). But both didn't give any better result.

My ISS file is as follow :

#define MyInstName "MyApp"
#define MyInstVersion GetEnv("JFROG_DEFAULTGROUPS_VERSION")

[Setup]
AppName={#MyInstName}
AppVersion={#MyInstVersion}

DefaultGroupName={#MyInstName}
OutputBaseFilename=MyApp_{#MyInstVersion}_setup
AppendDefaultDirName=no
DefaultDirName={commonpf}

[Components]
Name: default_groups_conf; Description: Default Groups Configuration; Types: full


[Run]

[Code]
function InitializeSetup(): Boolean;
begin
    if not ('{#MyInstVersion}' = '') then begin
        MsgBox('MyInstVersion Env Var not set.', mbInformation, MB_OK);
        Abort;
    end;
end;

What is wrong with this ? How to properly catch environment variables in [Setup] and [Code] sections ?

SCO
  • 1,832
  • 1
  • 24
  • 45
  • Compiling your script fails on the very first line with *"Undeclared identifier: "MyApp"."* And rightly. – Let's assume that it's just a mistake, while you were sanitizing your script. And the actual script is more like `#define MyInstName "MyApp"`. The script then does what it should. It works nicely, when I compile it from a batch file with these lines: 1) `set JFROG_DEFAULTGROUPS_VERSION=2.1.4` 2) `ISCC.exe Example1.iss` – What is `export`? There's no export command in Windows batch file, nor PowerShell. Are you using some *nix shell on Windows? – Martin Prikryl Aug 29 '20 at 12:59
  • This does not look like an Inno Setup question. It's more likely that you actually do not set the environment variables correctly. – Martin Prikryl Aug 29 '20 at 13:00
  • @MartinPrikryl, thank you ! I fixed the sample code, it indeed was a sanitizing error. Yes, my shall is WSL. Listing the environment variable (env command) from the terminal just before calling ISCC successfully shows the environment variable, so looks like it is set correctly (as per WSL), but maybe not understood by InnoSetup for any reason. Just tried from a Windows Command Line Interpreter : works flawlessly. Tagging this issue with WSL instead of Inno Setup. Thank you ! – SCO Aug 29 '20 at 16:37
  • @MartinPrikryl, thanks for pointing me into the right direction. I read this : https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/ and made things clearer ! – SCO Aug 29 '20 at 16:51

2 Answers2

0

As per https://devblogs.microsoft.com/commandline/share-environment-vars-between-wsl-and-windows/, it turns out :

  • Windows environment vars are not made available in the WSL shell

  • I run Windows 10 [version 10.0.17134.1488], which is post 17063, so, I need to expose to WSL the Windows environment variables by exporting a WSLENV whose value is a combination of the envvar to expose, plus a flag (see link) :

    export JFROG_DEFAULTGROUPS_VERSION=1.0.0-1 export WSLENV=JFROG_DEFAULTGROUPS_VERSION/w

Then, the JFROG_DEFAULTGROUPS_VERSION envvar can be read by ISCC.

Conclusion : caution with WSL1 and environment variables.

SCO
  • 1,832
  • 1
  • 24
  • 45
0

I have achieved this using following steps. Please note that I have executed iscc using git-bash shell. In git-bash shell, I define environment variable and expose them using "export <ENV_VAR>" command so that iscc can get it's value

1. In .iss file, I have added following environment variables using #define

    #define XXXAppVersion GetEnv('XXX_VERSION')
    #define YYYRootDir GetEnv('YYY_ROOR_DIR')

2. use these in `[Setup]` section of .iss file

    AppVersion={#XXXAppVersion} 
    OutputDir={#YYYRootDir}/bin

3. After these changes, open git-bash shell and define these environment variables as follows

export XXX_VERSION="4.0.0.1"
export YYY_ROOT_DIR="C:\YYY_Home"

4. then execute following iscc using .iss file as follows in same shell which executes successfully. 

    iscc.exe "<.iss file>"
Dharman
  • 30,962
  • 25
  • 85
  • 135
BND
  • 51
  • 12