In my Defines.wxi I have:
<?define MajorVersion="1" ?>
<?define MinorVersion="08" ?>
<?define BuildVersion="11" ?>
In my MyProject.Setup.wixproj I have:
<OutputName>MyProject</OutputName>
<OutputType>Package</OutputType>
Is it possible to include the version variables in the filename somehow, so that my file can be named MyProject.1.08.11.msi?
This didn't work (no such variable is defined):
<OutputName>MyProject-$(MajorVersion)</OutputName>
<OutputType>Package</OutputType>
This didn't work (no such variable is defined):
<Target Name="AfterBuild" Condition="'$(Configuration)' == 'Release'">
<Copy SourceFiles="$(OutputPath)$(OutputName).msi" DestinationFiles="C:\$(OutputName)-$(MajorVersion).msi" />
</Target>
It seems very clear to me that $(MajorVersion) is not the correct way of fetching the definition from the Defines.wxi file. What is?
Update
I tried to put this in MyProject.Setup.wixproj:
<InstallerMajorVersion>7</InstallerMajorVersion>
<InstallerMinorVersion>7</InstallerMinorVersion>
<InstallerBuildNumber>7</InstallerBuildNumber>
...
<PropertyGroup Condition=" '$(Configuration)|$(Platform)' == 'Release|x86' ">
<OutputPath>bin\$(Configuration)\</OutputPath>
<IntermediateOutputPath>obj\$(Configuration)\</IntermediateOutputPath>
<DefineConstants>PrebuildPath=..\..\obj\prebuild\web\;InstallerMajorVersion=$(InstallerMajorVersion);InstallerMinorVersion=$(InstallerMinorVersion);InstallerBuildNumber=$(InstallerBuildNumber)</DefineConstants>
</PropertyGroup>
And this in Defines.wxi:
<?define MajorVersion="$(var.InstallerMajorVersion)" ?>
<?define MinorVersion="$(var.InstallerMinorVersion)" ?>
<?define BuildVersion="$(var.InstallerBuildNumber)" ?>
<?define Revision="0" ?>
<?define VersionNumber="$(var.InstallerMajorVersion).$(var.InstallerMinorVersion).$(var.InstallerBuildNumber)" ?>
Didn't work either. Got these error messages:
- The Product/@Version attribute's value, '..', is not a valid version. Legal version values should look like 'x.x.x.x' where x is an integer from 0 to 65534.
- The Product/@Version attribute was not found; it is required.
One way would be to define the variables in your MSBuild script, and have it update Defines.wxi at build time, as in this example.
In your MSBuild script, you could define the version properties as follows:
Then running the UpdateWixVars target will update the version numbers in Defines.wxi with the version numbers specified in your MSBuild project.
Note that I could not find an actual compiled dll with this custom build task, so I had to create it by:
Add the reference to the build task like so:
It is not possible to read the .wxi file from the .wixproj file. So you have to use another way to specify the version. I can give an example where I read the version from a assembly included in the installer, and use that version to rename the msi;
Open the .wixproj file in an editor and add a
ReadVersion
target:This reads the version from
bin\program.exe
, displays it for debugging purposes, and changes the TargetName, TargetFileName and TargetPath.After the line containing
<Import Project="$(WixTargetsPath)" />
, add the following to inject this target into the build process:You can accomplish this seamlessly by implementing these two answers:
AfterBuild
task to rename the WIX-built MSI: https://stackoverflow.com/a/10716409/374198The other answers are much too complex!
PS: If you want to drop the fourth digit, following semantic versioning, you can do it like this:
This will create an MSI named, for example,
MyProject-1.2.3.x64.msi
. See this answer for more.This is what I ended up with, and it works!
Setup.Version.proj
MyProject.Setup.wixproj
Defines.wxi
In your .wixproj file. Add the following section just before the
</Project>
tag.This works for me.
This common task should be simplified in future versions of WiX!
This solution combines @Wimmel's and this post. It draws the version from a target .exe, and otherwise does not store version numbers in files; it doesn't rename the output file in post-build. But, it is necessary to update the property ProjectDefineConstants, from which the candle arguments are derived (in wix.targets). Otherwise, updating only the TargetPath property does not change the inputs to candle.exe.
*.wixproj:
*.wxs