在Inno Setup中从文本文件读取应用程序版本 [英] Read application version from a text file in Inno Setup

查看:383
本文介绍了在Inno Setup中从文本文件读取应用程序版本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个包含以下行的TypeScript文件:

I have a TypeScript file that contains this line:

export const version = '0.0.1';

我想访问version的值并将其导入Setup部分(iss文件)中的AppVersion

And I want access the value of version and import it to AppVersion in Setup section (iss file)

[Setup]
AppVersion={....}

我该怎么办?

推荐答案

类似于 Inno Setup:如何更新AppVersion [Setup]值通过Config.xml文件,您可以使用预处理器中的PowerShell脚本使用正则表达式从文件中解析版本:

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

这篇关于在Inno Setup中从文本文件读取应用程序版本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆