Pieter van der Westhuizen

Creating WiX setup project for Office add-ins on Visual Studio 2012 using Add-in Express

If you’ve switched to Visual Studio 2012, you might have noticed that Microsoft has sneakily removed all Visual Studio Installer project types. Instead of the usual Setup Project, Setup Wizard, CAB Project and Merge Module Project templates, the only option we now have is to use the limited edition of InstallShield.

The Visual Studio setup projects are quite literally a thing of the past, as Visual Studio 2010 was the final release that includes the templates.

Installer project types in Visual Studio 2010

Add-in Express supports building your setup project with InstallShield, but what to do if you do not have InstallShield installed? A good alternative is the WiX Toolset. It is a free and open source collection of tools with which you can build Windows Installer packages using XML. Another good thing about WiX is that the newly released version 7 of Add-in Express for Office and .net supports it!

Creating a setup project for your Office extension

When you need to create a setup project for your Office extension (whether it is an add-in for Outlook, Excel, Word, PowerPoint or other Office apps supported by Add-in Express) in Visual Studio 2012, all you need to do is right-click on your project in the Visual Studio Solution Explorer and select Create Setup Project from the context-menu.

Creating a setup project for an Add-in Express based Office add-in in Visual Studio 2012

Add-in Express will then show you a New Setup Project wizard and you can choose to create one of the following installers:

  • Visual Studio Installer
  • InstallShield
  • WiX

The New Setup Project wizard provided by Add-in Express

If you’re using Visual Studio 2012, the Visual Studio Installer option will never be enabled, and you need to install InstallShield and/or WiX in order for their radio buttons to be enabled.

I only have WiX installed, so in this example, I’ve selected WiX; and Add-in Express will create and add the setup project to the Visual Studio solution.

The WiX setup project for the Office add-in created by Add-in Express

At first glance, it might look like something did not work properly since the only file in the setup project is Product.wxs. Don’t worry, the WiX source file (.wxs) is the only file you require to create a simple WiX installer!

The insight of the Windows Installer XML (WiX) project

Add-in Express has already added most of the elements you need to the WiX source file, so all you really have to do is to build the setup project for your Office add-in, browse to its bin\Debug folder and run the .msi file. This in turn will start a standard setup program for your addin.

The default welcome screen of the WiX installer

Next, let’s take a look at the Product.wxs file and I’ll explain some of the elements within the file. Each WiX source file needs to start with an XML declaration and a WiX element. All other elements go inside this element.

Inside the WiX element, there should be a Product element, which in turn has a Package child element.

Product element of the WiX setup project

The Product element is used to describe the software inside the installer i.e. your Office Add-in. You can specify the name of your application, the default language (LCID), version number and the manufacturer. Most of these properties should stay the same for all builds, except when you want to increase the version number of your application.

<Package 
  InstallerVersion="200" 
  Compressed="yes" 
  InstallScope="perUser"
  Description="A handy add-in for Office"
  Manufacturer="Add-in Express"
  Languages="1033"
  SummaryCodepage="1252" 
  InstallPrivileges="limited"      
/>

It is, however, a good idea to specify the other attributes, such as the InstallerVersion, which specifies which version of Windows Installer is required for your setup program. InstallScope specifies whether the add-in will be installed per Machine or per User and finally the InstallPrivileges attribute specifies what privileges are required to install the add-in on Windows Vista and above e.g. limited or elevated permissions.

Media element

The file in the setup project is bundled into CAB files. Each Media element in your WiX source file will have its own CAB file. As a rule CAB files should not be larger than 2GB and you can choose whether to embed the CAB file into your .MSI file or not by changing the EmbedCab attribute. This is primarily used for very LARGE setups where you would like to split your installation media over multiple disks.

<ComponentGroup Id="ProductComponents" >
  <Component Id="ProductComponent" Guid="e0e8a9c7-6ebb-486b-9a28-91878c9c38c1" 
    DiskId="1" Directory="INSTALLFOLDER" >
    <RegistryKey Root="HKCU" Key="Software\[Manufacturer]\[ProductName]">
      <RegistryValue Type="string" Name="Installed" Value="[INSTALLFOLDER]" KeyPath="yes" />
    </RegistryKey>
    <File Id="_$(var.OfficeAddIn.TargetName)_dll" Name="$(var.OfficeAddIn.TargetFileName)"
      Source="$(var.OfficeAddIn.TargetPath)" />
    <File Id="_adxloader_dll_manifest" Name="adxloader.dll.manifest"
      Source="$(var.OfficeAddIn.ProjectDir)Loader\" />
    <File Id="_adxloader_dll" Name="adxloader.dll"
      Source="$(var.OfficeAddIn.ProjectDir)Loader\"  />
    <File Id="_adxloader64_dll" Name="adxloader64.dll" 
      Source="$(var.OfficeAddIn.ProjectDir)Loader\" />
    <File Id="_AddinExpress_MSO_2005_dll" Name="AddinExpress.MSO.2005.dll" 
      Source="C:\Program Files (x86)\Add-in Express\Add-in Express for .NET\Bin\" />
    <File Id="_Extensibility_dll" Name="Extensibility.dll"
      Source="C:\Windows\assembly\GAC\Extensibility\7.0.3300.0__b03f5f7f11d50a3a\" />
    <File Id="_Microsoft_Office_Interop_Excel_dll" Name="Microsoft.Office.Interop.Excel.dll"
      Source="$(var.OfficeAddIn.TargetDir)" />
    <File Id="_Microsoft_Vbe_Interop_dll" Name="Microsoft.Vbe.Interop.dll"
      Source="$(var.OfficeAddIn.TargetDir)" />
    <File Id="_Office_dll" Name="Office.dll"
      Source="$(var.OfficeAddIn.TargetDir)" />
  </Component>
</ComponentGroup>

Feature element

This element is used to specify which feature of your Office add-in must be installed and contains a reference to a ComponentGroup element that specifies which files need to be installed with the selected feature.

<UIRef Id="WixUI_FeatureTree"/>

Creating a customized WiX setup project for your Office add-in

UIRef element

The WiX toolset supports a number of pre-built UI’s, as listed below:

  • WixUI_Minimal;
  • WixUI_Advanced;
  • WixUI_FeatureTree;
  • WixUI_InstallDir; and
  • WixUI_Mondo.

If you would like to show your own license agreement in your plug-in, all you need to do is add the following WixVariable element to your WiX Source file:

<CustomAction Id="RegisterDll" BinaryKey="adxregistrator_exe" Execute="deferred"
  ExeCommand='/install="[INSTALLFOLDER]$(var.OfficeAddIn.TargetFileName)" /privileges=user /returnExitCode=false'
  Impersonate="yes" />
<CustomAction Id="UnregisterDll" BinaryKey="adxregistrator_exe" Execute="immediate"
  ExeCommand='/uninstall="[INSTALLFOLDER]$(var.OfficeAddIn.TargetFileName)" /privileges=user'
  Impersonate="yes" Return="ignore" />

There is a host of standard custom actions for WiX that will assist you in creating SQL server databases, run database scripts as well as configuring IIS websites and virtual directories to name but a few.

The final word

As you can see, WiX is a very powerful and flexible toolset for creating Windows based installers (MSI) for your Office add-ins. I have barely scratched the surface of what is capable with this toolset and I strongly encourage you to have a look at the WiX documentation.

I’m not the greatest fan of having to edit XML by hand and having some decent tooling for the WiX toolset in Visual Studio would be a tremendous help. Who knows, maybe we’ll see something along these lines in the near future…

Thank you for reading. Until next time, keep coding!

Updated on 21-Feb-2013:

Guys, if you want to convert your Visual Studio setup projects (vdproj) to WiX literally in 1 click, check out VDProj to WiX Converter.

Available downloads:

This example was developed using Add-in Express for Office and .net:
Sample Office add-in with WiX installer

6 Comments

  • https://secure.gravatar.com/avatar/9d9d44a72bbd0ad77938ccdf56c54ea8?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G D. Dunn says:

    Awesome post – you got me up and running again in minutes with this blog post.

  • https://secure.gravatar.com/avatar/856d4b67c1ca2a2307b3dcfd333c0719?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Nicholas Hebb says:

    For the license agreement, I think you meant to post this code from the sample file:

    Also, I would be helpful to see more examples in the future, such as how to add a sub-directory to the installation folder and Start menu shortcuts.

  • https://secure.gravatar.com/avatar/856d4b67c1ca2a2307b3dcfd333c0719?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Nicholas Hebb says:

    Oops, I forgot to add the eula sample:

  • https://secure.gravatar.com/avatar/ab4ec2858cfdf1e44dadf8c50fae314d?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Dmitry Kostochko (Add-in Express Team) says:

    Hi Nicholas,

    It looks like the XML code you are trying to post is removed by our blog editor. Please try to replace the XML angle brackets with corresponding HTML character entities (< with & lt; and > with & gt; without spaces):
    http://www.w3schools.com/html/html_entities.asp

  • https://secure.gravatar.com/avatar/366f6260f722c0aae95dff34103b600f?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Eric Legault says:

    Hey Peter! Can we now use a single WiX project to deploy an add-in for both 32-bit and 64-bit versions of any Office add-in? Without changing a single property? Is the installer logic smart enough to run adxregistrator.exe for the appropriate adxloader.dll?

  • https://secure.gravatar.com/avatar/e1a4c2b21a5186e0b27c1c601f418b76?s=32&d=https%3A%2F%2Fsecure.gravatar.com%2Favatar%2Fad516503a11cd5ca435acc9bb6523536%3Fs%3D32&r=G Pieter van der Westhuizen says:

    Hi Eric,

    Yes. I’ve built a simple Excel add-in and created a WiX setup project using Add-in Express. It installed without a problem on both a 32 and 64 bit machine.

Post a comment

Have any questions? Ask us right now!