2
votes

I need to have the MSI output file name include the full version of the output EXE in the \bin folder. Something like MyFile_x.x.x.x.msi

This works great inside the .WXS file for the installer to get the full version and display it in the installer. But the problem is you can't use bind.FileVersion. within the project file

  <?define ProductVersion=!(bind.FileVersion.$(var.Zygo.MetroProXP.UI.TargetFileName)) ?>

The recommended solution is to use the GetAssemblyIdentiy method to redefine the output file name like this.

   <GetAssemblyIdentity AssemblyFiles="$(OutDir)MyFile.exe">
      <Output TaskParameter="Assemblies" ItemName="ProductAssembly" />
    </GetAssemblyIdentity>
    <CreateProperty Value="$(OutputName)%(ProductAssembly.Version)">
      <Output TaskParameter="Value" PropertyName="TargetName" />
    </CreateProperty>

The issue for me is that the version returned is only Major.Minor.Build and I need the full version Major.Minor.Build.Release. That is because the GetAssemblyIdentity returns the AssemblyVersion NOT the AssemblyFileVersion. which does have the 4th portion of the version number define. Does anyone know how I can get the full version for renaming the MSI file?

2

2 Answers

4
votes

I was able to get this to work using an Inline Task.

<UsingTask TaskName="GetFileVersionTask"
     TaskFactory="CodeTaskFactory"
     AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
  <ParameterGroup>
    <AssemblyPath ParameterType="System.String" Required="true" />
    <VersionNumber ParameterType="System.String" Output="true" />
  </ParameterGroup>
  <Task>
    <Using Namespace="System.Diagnostics" />
    <Code Type="Fragment" Language="cs">
      <![CDATA[this.VersionNumber = FileVersionInfo.GetVersionInfo(this.AssemblyPath).FileVersion;]]>
    </Code>
  </Task>
</UsingTask>

Then just changed the Output Directory

<Target Name="BeforeBuild">
  <GetFileVersionTask AssemblyPath="$(OutDir)MyEXEFile.exe">
    <Output TaskParameter="VersionNumber" PropertyName="VersionNumber" />
  </GetFileVersionTask>
  <CreateProperty Value="$(OutputName)$(VersionNumber)">
    <Output TaskParameter="Value" PropertyName="TargetName" />
  </CreateProperty>
  <CreateProperty Value="$(TargetName)$(TargetExt)">
    <Output TaskParameter="Value" PropertyName="TargetFileName" />
  </CreateProperty>
  <CreateProperty Value="$(TargetDir)$(TargetFileName)">
    <Output TaskParameter="Value" PropertyName="TargetPath" />
  </CreateProperty>
</Target>
0
votes

FWIW, I recall some chatter about adding more binder variables. The idea was accepted with the concern of slowing WiX down reading a bunch of stuff most people will never use.

MSBuild has a concept called Property Functions. You could probably come up with an expression that gets the version # of a file and append it to the output name.

Just an FYI. Realize that you'll be forced to do Major Upgrades if you change the MSI file name.