Inno Setup:如何从Config.xml文件更新AppVersion [Setup]值 [英] Inno Setup: How to update AppVersion [Setup] value from Config.xml file

查看:218
本文介绍了Inno Setup:如何从Config.xml文件更新AppVersion [Setup]值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在编译时通过解析Version标记从config.xml文件更新[Setup]部分中的AppVersion值.

I want to update AppVersion value in [Setup] section at compile time from config.xml file by parsing Version tag.

Config.xml文件具有以下配置:

<?xml version="1.0" encoding="utf-8"?>
<Configuration> 
  <Version>1.0.1</Version>
</Configuration>

我的应用程序正在使用config.xml文件获取应用程序版本.我也想在Inno Setup安装程序版本中使用相同的版本.

My application is using config.xml file for application version. I also want to use the same version in Inno Setup installer version.

我是Inno Setup脚本开发的新手.如果有人为我提供正确的方法,那将非常有帮助.

I am new in Inno Setup script development. It would be very helpful if someone provide me right approach.

推荐答案

您可以使用简单的PowerShell代码,例如:

You can use a simple PowerShell code like:

$version = ([xml](Get-Content 'config.xml')).Configuration.Version
Set-Content -Path 'version.txt' -Value $version

并使用 Inno Setup预处理器运行它:

#define RetrieveVersion(str FileName) \
  Local[0] = AddBackslash(GetEnv("TEMP")) + "version.txt", \
  Local[1] = \
    "-ExecutionPolicy Bypass -Command """ + \
    "$version = ([xml](Get-Content '" + FileName + "')).Configuration.Version; " + \
    "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\config.xml")}


有关类似问题,请参见从Inno Setup中的文本文件中读取应用程序版本.

尽管我假设应用程序编译器实际上将config.xml用于应用程序可执行版本.在这种情况下,您可以更轻松地从.exe中检索版本.

Though I assume that the application compiler actually uses the config.xml for the application executable version. If that's the case, you can retrieve the version from the .exe more easily.

请参见如何根据我的应用程序版本自动设置Inno Setup安装程序的版本?

这篇关于Inno Setup:如何从Config.xml文件更新AppVersion [Setup]值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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