xmlwindowsinno-setup

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


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.


Solution

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

    For a similar question, see Read application version from a text file in Inno Setup.


    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?