2

I have a TypeScript file that contains this line:

export const version = '0.0.1';

And I want access the value of version and import it to AppVersion in Setup section (iss file)

[Setup]
AppVersion={....}

How can I do it?

Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
whiteRice
  • 31
  • 5

1 Answers1

2

Similarly to Inno Setup: How to update AppVersion [Setup] value from Config.xml file, you can use PowerShell script from preprocessor to parse the version from the file using a regular expression:

#define RetrieveVersion(str FileName) \
  Local[0] = AddBackslash(GetEnv("TEMP")) + "version.txt", \
  Local[1] = \
    "-ExecutionPolicy Bypass -Command """ + \
    "$contents = Get-Content '" + FileName + "';" + \
    "$match = $contents | Select-String 'version\s*=\s*''(.*?)''';" + \
    "$version = $match.Matches.Groups[1].Value;" + \
    "Set-Content -Path '" + Local[0] + "' -Value $version;" + \
    """", \
  Exec("powershell.exe", Local[1], SourcePath, , SW_HIDE), \
  Local[2] = FileOpen(Local[0]), \
  Local[3] = FileRead(Local[2]), \
  FileClose(Local[2]), \
  DeleteFileNow(Local[0]), \
  Local[3]

[Setup]
AppVersion={#RetrieveVersion("C:\path\script.ts")}
Martin Prikryl
  • 188,800
  • 56
  • 490
  • 992
  • 1
    @whiteRice please accept it as answer if it worked for you so others know this is the answer that works + that shows appreciation for the answerer – K4M Aug 19 '20 at 05:28