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:
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:
<Import Project="$(WixTargetsPath)" />
<Target Name="BeforeBuild">
<!-- Read the version from the to-be-installed .exe -->
<GetAssemblyIdentity AssemblyFiles="path.to.primary.exe">
<Output TaskParameter="Assemblies" ItemName="AsmInfo" />
</GetAssemblyIdentity>
<!-- Create the MSBuild property $(VersionNumber) -->
<CreateProperty Value="%(AsmInfo.Version)">
<Output TaskParameter="Value" PropertyName="VersionNumber" />
</CreateProperty>
<!-- Create the WiX preprocessor variable $(var.VersionNumber) -->
<CreateProperty Value="$(DefineConstants);VersionNumber=$(VersionNumber)">
<Output TaskParameter="Value" PropertyName="DefineConstants" />
</CreateProperty>
<!-- Update the MSBuild properties $(TargetName), etc. -->
<CreateProperty Value="$(SolutionName)-$(Platform)-$(VersionNumber)">
<Output TaskParameter="Value" PropertyName="TargetName" />
</CreateProperty>
<CreateProperty Value="$(TargetName)$(TargetExt)">
<Output TaskParameter="Value" PropertyName="TargetFileName" />
</CreateProperty>
<CreateProperty Value="$(TargetName)$(TargetPdbExt)">
<Output TaskParameter="Value" PropertyName="TargetPdbName" />
</CreateProperty>
<CreateProperty Value="$(TargetDir)$(TargetFileName)">
<Output TaskParameter="Value" PropertyName="TargetPath" />
</CreateProperty>
<CreateProperty Value="$(TargetPdbDir)$(TargetPdbName)">
<Output TaskParameter="Value" PropertyName="TargetPdbPath" />
</CreateProperty>
<!-- Update the MSBuild property from which candle.exe args are derived -->
<CreateProperty Value="
Configuration=$(ConfigurationName);
OutDir=$(OutDir);
Platform=$(PlatformName);
ProjectDir=$(ProjectDir);
ProjectExt=$(ProjectExt);
ProjectFileName=$(ProjectFileName);
ProjectName=$(ProjectName);
ProjectPath=$(ProjectPath);
TargetDir=$(TargetDir);
TargetExt=$(TargetExt);
TargetFileName=$(TargetFileName);
TargetName=$(TargetName);
TargetPath=$(TargetPath);
">
<Output TaskParameter="Value" PropertyName="ProjectDefineConstants" />
</CreateProperty>
</Target>
*.wxs
<Product Id="*" Version="$(var.VersionNumber)" ... >
...
</Product>
This is what I ended up with, and it works!
Setup.Version.proj
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<PropertyGroup>
<InstallerMajorVersion>55</InstallerMajorVersion>
<InstallerMinorVersion>66</InstallerMinorVersion>
<InstallerBuildVersion>$(BuildNumber)</InstallerBuildVersion>
<InstallerBuildVersion Condition="$(InstallerBuildVersion) == ''">0</InstallerBuildVersion>
</PropertyGroup>
</Project>
MyProject.Setup.wixproj
<?xml version="1.0" encoding="utf-8"?>
<Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<Import Project="Setup.Version.proj" />
<PropertyGroup>
<OutputName>MyProject_$(InstallerMajorVersion)_$(InstallerMinorVersion)_$(InstallerBuildVersion)</OutputName>
<OutputType>Package</OutputType>
<DefineConstants>InstallerMajorVersion=$(InstallerMajorVersion);InstallerMinorVersion=$(InstallerMinorVersion);InstallerBuildVersion=$(InstallerBuildVersion)</DefineConstants>
...
Defines.wxi
<?define MajorVersion="$(var.InstallerMajorVersion)" ?>
<?define MinorVersion="$(var.InstallerMinorVersion)" ?>
<?define BuildVersion="$(var.InstallerBuildVersion)" ?>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With