Inno Setup: How to update AppVersion [Setup] value from Config.xml file

喜欢而已 提交于 2020-05-12 07:22:33

问题


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

Config.xml file has below configuration:

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

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

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


回答1:


You can use a simple PowerShell code like:

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

And run it using Inno Setup preprocessor:

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

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.

See How do I automatically set the version of my Inno Setup installer according to my application version?



来源:https://stackoverflow.com/questions/46929344/inno-setup-how-to-update-appversion-setup-value-from-config-xml-file

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