InnoSetupのテキストファイルからアプリケーションのバージョンを読み取る

Aug 18 2020

この行を含むTypeScriptファイルがあります:

export const version = '0.0.1';

そして、の値にアクセスversionしてAppVersionSetupセクション(issファイル)にインポートしたい

[Setup]
AppVersion={....}

どうすればいいですか?

回答

2 MartinPrikryl Aug 18 2020 at 19:51

Inno Setup:Config.xmlファイルからAppVersion [Setup]値を更新する方法と同様に、プリプロセッサからPowerShellスクリプトを使用して、正規表現を使用してファイルからバージョンを解析できます。

#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")}