Wix bootstrapper - Set version number in Bundle

1.3k Views Asked by At

I've got a Wix installer that uses a bootstrapper to launch my msi file. I've done this by calling a batch file as a post build event in my wix project. This then calls candle and light manually and passes various variables into the Bundle.wxs file. This all works and generates the exe which calls my msi file..

However, I now want to pass the msi BuildVersion into the bundle file. In the wxs file that creates the msi I am using the BuildVersion that I have setup in the BeforeBuild section, using the BuildVersion=%(AssemblyVersion.Version).

I cannot access this variable no matter what I try, in order to pass it to my build_bootstrapper.bat file. I can however pass in hardcoded values. I am currently setting up my own AssemblyVersionNumber enviornment variable as you can see below in the AfterBuild section:

<AssemblyVersionNumber Condition="'$(AssemblyVersionNumber)' == ''">$(BuildVersion)</AssemblyVersionNumber>

but it is empty by the time it gets to my script file (even though it's populated if hardcoded). I've tried everything.

Does anybody have any ideas of how I can get the %(AssemblyVersion.Version); to my command file from the post build step?

Thanks in advance

   <Target Name="BeforeBuild">
    <GetAssemblyIdentity AssemblyFiles="..\..\App\AppThing\bin\Release\AppThing.exe">
      <Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
    </GetAssemblyIdentity>
    <PropertyGroup>
      <DefineConstants>BuildVersion=%(AssemblyVersion.Version);</DefineConstants>
    </PropertyGroup>
  </Target>
  <Target Name="AfterBuild">
    <PropertyGroup>
      <DefineConstants>BuildVersion=%(AssemblyVersion.Version);</DefineConstants>
      <AssemblyVersionNumber Condition="'$(AssemblyVersionNumber)' == ''">$(BuildVersion)</AssemblyVersionNumber>
    </PropertyGroup>
  </Target>
  <PropertyGroup>
    <PreBuildEvent>$(ProjectDir)scripts\copy_services.bat $(SolutionDir) $(ProjectDir)</PreBuildEvent>
  </PropertyGroup>
  <Target Name="AfterClean">
    <Message Text="Cleaning wix files, TargetDir is: $(TargetDir)" Importance="High" ContinueOnError="true" />
    <CreateItem Include="$(TargetDir)\**\*.*">
      <Output TaskParameter="Include" ItemName="BinFilesDir" />
    </CreateItem>
    <Delete Files="@(BinFilesDir)" />
  </Target>      
  <PropertyGroup>
    <PostBuildEvent>$(ProjectDir)scripts\build_bootstrapper.bat $(ProjectDir) $(ConfigurationName) $(AssemblyVersionNumber)</PostBuildEvent>
  </PropertyGroup>
1

There are 1 best solutions below

3
On

$(BuildVersion) isn't set to anything.

You're setting define constants to "BuildVersion=%(AssemblyVersion.Version)" but never actually defining a MSBuild property called "BuildVersion" so the value of $(BuildVersion) is "".

Use %(AssemblyVersion.Version).

<AssemblyVersionNumber Condition="'$(AssemblyVersionNumber)' == ''">%(AssemblyVersion.Version)</AssemblyVersionNumber>