Leia a versão do aplicativo a partir de um arquivo de texto no Inno Setup

Aug 18 2020

Eu tenho um arquivo TypeScript que contém esta linha:

export const version = '0.0.1';

E eu quero acessar o valor de versione importá-lo AppVersionna Setupseção (arquivo iss)

[Setup]
AppVersion={....}

Como eu posso fazer isso?

Respostas

2 MartinPrikryl Aug 18 2020 at 19:51

De maneira semelhante ao Inno Setup: como atualizar o valor AppVersion [Setup] do arquivo Config.xml , você pode usar o script PowerShell do pré-processador para analisar a versão do arquivo usando uma expressão regular:

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