问题描述
export const version = '0.0.1';
我想访问version
的值并将其导入到AppVersion
部分(iss文件)中的Setup
[Setup]
AppVersion={....}
我该怎么办?
解决方法
类似于Inno Setup: How to update AppVersion [Setup] value from Config.xml file,您可以使用预处理器中的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")}