Question

I would like to extract the version number from this code:

<?xml version="1.0" encoding="UTF-8"?>
<Include>
  <?define ProductVersion = "1.0.0.0" ?>
</Include>

I want the output to be: 1.0.0.0, is it possible to do this?

Was it helpful?

Solution

If you are using Visual Studio to create the WIX based installer then you can define your ProductVersion variable in the .wixproj file.

  <Target Name="BeforeBuild">
    <PropertyGroup>
      <DefineConstants>ProductVersion=1.0</DefineConstants>
      ...
    </PropertyGroup>
  </Target>

This would be accessible from .wxs file by $(var.ProductVersion). Now you can use XPath to read the value of DefineConstants from your .wixproj file. This will get you ProductVersion = "1.0.0.0"

OTHER TIPS

You can access the processing instruction content using the processing-instruction() node filter. There is no semantic defined within a processing instruction, so you cannot directly query for the "attribute value".

You can use this XPath (1.0) query to fetch the value using string processing:

substring-before(substring-after(/Include/processing-instruction(), '"'), '"')
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top