Reputation: 41
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?
Upvotes: 3
Views: 942
Reputation: 202272
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")}
Upvotes: 2