Automatically increment and synchronize version for product and bootstrapper

10,706

Solution 1

Got it!!! I didn't realize you can declare Variables aka DefineConstants in a BeforeBuild Target.

Below is an example BeforeBuild Target that generates a variable BuildVersion

Bundle.wxs:

<Bundle Name="$(var.ProductName) Bootstrapper v$(var.BuildVersion)"
        Version="$(var.BuildVersion)"

Bootstrapper.wixproj:

  <Target Name="BeforeBuild">
    <GetAssemblyIdentity AssemblyFiles="..\MyApp\bin\$(Configuration)\MyApp.exe">
      <Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
    </GetAssemblyIdentity>
    <PropertyGroup>
      <DefineConstants>BuildVersion=%(AssemblyVersion.Version)</DefineConstants>
    </PropertyGroup>
  </Target>
  <!-- This is extra, not needed: Renames output file with version number -->
  <Target Name="AfterBuild">
    <GetAssemblyIdentity AssemblyFiles="..\MyApp\bin\$(Configuration)\MyApp.exe">
      <Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
    </GetAssemblyIdentity>
    <Copy SourceFiles=".\bin\$(Configuration)\$(OutputName).exe" DestinationFiles=".\bin\$(Configuration)\MyApp.%(AssemblyVersion.Version).exe" />
    <Delete Files=".\bin\$(Configuration)\$(OutputName).exe" />
  </Target>

Solution 2

This is what I would do:

  1. In my assembly I use auto versioning: AssemblyVersion("1.0.*")

  2. In the setup project reference the version using binding to the assembly: !(bind.fileVersion.MyAssembly.dll) (MyAssembly.dll is the File/@Id of the assembly)

  3. In the bundle using binding to the setup version: !(bind.packageVersion.Setup) (Setup is the project name as is referenced in the bundle project.)
Share:
10,706
Brock Hensley
Author by

Brock Hensley

Computer whisperer; Programmer for life; Systems Administrator for hire. Hard-earned valuable experience in IT versed in Linux and Windows, web hosting, design and programming. Detail oriented, creative in problem solving and experienced in designing custom solutions working with clients and executives of all levels and backgrounds. Passionate about new technologies, surmounting unique challenges and accomplishing goals. Programming C#, C++, .NET, PowerShell, WebAPI, MVC, MVVM, WPF, HTML, CSS, jQuery, jQueryUI, Telerik, Kendo, Knockout, TSQL, PHP, Perl, Bash, VIM, VB, BASIC Operating Systems Windows Server (2000-2016), Linux (Red Hat, CentOS, OpenSuSe, Debian, Slackware, FreeBSD, etc.) Web Servers IIS (6-10), Apache (1.3-2.4) Database Servers Microsoft SQL Server (2000-2016), MySQL (3.23-5.6) Hardware Dell PowerEdge Blade Servers, WatchGuard Firewalls, Cisco Routers, KVM/IPMI Microsoft Technologies Active Directory, Clustering, Load Balancing, Application Request Routing, Hyper-V, SharePoint, Exchange, Office Other NESSUS, Snort, McAfee, Symantec, Backup for Workgroups, Continuous Data Protection, Photoshop, AutoCAD, Mechanical Desktop, Maya, Lightwave, 3D Studio Max AWARDS/CERTIFICATES MCITP - Windows Server 2008, Server Administrator (646) MCTS - Microsoft SQL Server 2008, Implementation and Maintenance (432) MCTS - Windows Server 2008 Network Infrastructure, Configuring (642) MCTS - System Center Virtual Machine Manager 2008, Configuring (403) MCTS - Windows Server Virtualization, Configuration (652) MCTS - Windows Server 2008 Active Directory, Configuration (640) MCTS - Microsoft Server 2003 Hosting, Configuration and Management (501) MCTS - Microsoft Windows Vista, Configuration (620) MCP - Installing, Configuring, and Administering Microsoft Windows XP Professional (270) Security+ Certified

Updated on July 27, 2022

Comments

  • Brock Hensley
    Brock Hensley almost 2 years

    I'm trying to implement automatic versioning so that when I build my Bootstrapper, both the MyApp and Bootstrapper versions are automatically incremented and synchronized. Otherwise you end up with duplicate bootstrap entries in the add/remove programs for each installation attempt with matching versions.

    When I build the bootstrapper, an AfterBuild target uses GetAssemblyIdentity to get the automatically generated version of MyApp successfully, and the bootstrapper output file is properly named with the incremented version number e.g. MyApp.1.0.5123.1352.exe

    But, when I install this Bootstrapper, the version that shows in add/remove programs is always 1.0.0.0.

    I've tried using bindings in the Bootstrapper Bundle Version field but I can't get it to read the MyApp version.

    Using !(bind.packageVersion.MyApp) results in never incrementing 1.0.0.0.
    Using !(bind.assemblyName.MyApp) results in build errors (Unresolved bind-time variable).
    Using !(bind.FileVersion.filAAF013CA9B89B07C81031AE69884BF11) results in build errors (Unresolved bind-time variable). <-- Makes sense as the FileID exists in the Setup project, and this is the Bootstrapper project.

    What can I do to get my Bootstrapper Bundle to have the same version as the MyApp it is packaging?

    =====MyApp\AssemblyInfo.cs=====

    [assembly: AssemblyVersion("1.0.*")] 
    [assembly: AssemblyFileVersion("1.0.*")] 
    

    =====Setup.wixproj=====

    <Target Name="BeforeBuild">
      <PropertyGroup>
        <LinkerBaseInputPaths>..\MyApp\bin\$(Configuration)\</LinkerBaseInputPaths>
      </PropertyGroup>
      <HeatDirectory OutputFile="MyApp_Files.wxs" Directory="..\MyApp\bin\$(Configuration)\" DirectoryRefId="INSTALLLOCATION" ComponentGroupName="MyApp_Project" SuppressCom="true" SuppressFragments="true" SuppressRegistry="true" SuppressRootDirectory="true" AutoGenerateGuids="false" GenerateGuidsNow="true" ToolPath="$(WixToolPath)" Condition="'%(ProjectReference.PackageThisProject)'=='True'" />
    </Target>
    

    =====Bootstrapper.wixproj=====

    <Target Name="AfterBuild">
        <GetAssemblyIdentity AssemblyFiles="..\MyApp\bin\$(Configuration)\MyApp.exe">
            <Output TaskParameter="Assemblies" ItemName="AssemblyVersion" />
        </GetAssemblyIdentity>
        <Copy SourceFiles=".\bin\$(Configuration)\$(OutputName).exe" DestinationFiles=".\bin\$(Configuration)\MyApp.%(AssemblyVersion.Version).exe" />
        <Delete Files=".\bin\$(Configuration)\$(OutputName).exe" />
    </Target>
    

    =====Bootstrapper\Bundle.wxs=====

    <Bundle Name="$(var.ProductName) Bootstrapper v!(bind.packageVersion.MyApp)" 
            Version="!(bind.packageVersion.MyApp)"
    
  • Brock Hensley
    Brock Hensley over 10 years
    I set Setup\Product.wxs Version to !(bind.fileVersion.MyFileID) and Bootstrapper\Bundle.wxs Version to !(bind.packageVersion.Setup) and I get error Unresolved bind-time variable !(bind.packageVersion.Setup)
  • Neil
    Neil over 10 years
    Have you referenced the Setup project in the Bundle project?
  • Brock Hensley
    Brock Hensley over 10 years
    Yes <ProjectReference Include="..\Setup\Setup.wixproj"><Name>Setup</Name>
  • Neil
    Neil over 10 years
    Odd, I do this all the time. Can you check your solution configuration and make sure the bundle project depends on setup and also that they are both the same platform (mine are all x86).
  • Brock Hensley
    Brock Hensley over 10 years
    Bootstrapper & Setup platform: x86 (nothing else in dropdown). Solution Project Dependencies > 'Bootstrapper' project Depends on: [x] BootstrapperCustom [x] Setup. I am using latest WiX 3.7 and VS2k12.
  • Neil
    Neil over 10 years
    Here is a complete example show this working dl.dropboxusercontent.com/u/4752262/BurnVersion.zip
  • Omri Gazitt
    Omri Gazitt over 10 years
    Hmmm... when I try this I get "Undefined preprocessor variable '$(var.BuildVersion)'." I'm trying to grab version, company name, product name, etc from the Assembly. (I'm just using your "BeforeBuild" section and replacying MyApp with my app path/name)
  • Brock Hensley
    Brock Hensley over 10 years
    Make sure the path to the exe or dll is correct, it is relative to where your Bootstrapper project lies, this is working for me I'm not sure why you would get that error if it is able to find the file
  • Omri Gazitt
    Omri Gazitt over 10 years
    Thanks dirt, I managed to get the buildversion to work. I was trying to extend your technique and also grab Company, Product, etc from the Assembly metadata, but wasn't able to get that to work.
  • Bigwave
    Bigwave about 10 years
    @brockhensley, the name in the !(bind.packageVersion.Setup) e.g. Setup, needs to be the contents of the Id attribute specified in the MsiPackage. So it should be something like <MsiPackage Id="SetUp" SourceFile="$(var.Setup.TargetPath)" />
  • MsBao
    MsBao almost 10 years
    @Bigwave Thanks. I got stuck on that.
  • JDennis
    JDennis almost 10 years
    I'm having some difficulty with this. I am packaging an msi instead of an exe; therefore, I have another wix project for that the msi. I tried copying the BeforeBuild tasks (i excluded the afterbuild portion), but couldn't get it to work. Being uncertain if wix setup projects supported define constants. I tried an alternate route. I have tried <CreateProperty Value="%(AssemblyVersion.Version)"> <Output TaskParameter="Value" PropertyName="BuildVersion" /> </CreateProperty> but the property is never set. Any advice is appreciated.
  • JDennis
    JDennis almost 10 years
    This did not work for me. I set message tasks showing that the property for BuildVersion was set; however, the property lost scope and a resulted in error: 'Undefined preprocessor variable '$(var.BuildVersion' Note that I am using a setup project and not a bootstrapper project.
  • jero2rome
    jero2rome over 9 years
    @NeilSleightholm How to include this version information to set as the OutputName in a burn bootstrapper ?