Read application version from a text file in Inno Setup

时光总嘲笑我的痴心妄想 提交于 2020-08-26 05:32:34

问题


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?


回答1:


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


来源:https://stackoverflow.com/questions/63464800/read-application-version-from-a-text-file-in-inno-setup

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!