Click here to Skip to main content
65,938 articles
CodeProject is changing. Read more.
Articles
(untagged)

A WIX web setup

0.00/5 (No votes)
9 May 2007 1  
Create WIX web setup using VS2005 and Wix 3.0

Introduction

Create a web setup in Visual studio 2005 using WIX 3.0. This also generates wix file automatically. The setup has the following features:

  • Install based on the environment
  • Create event source
  • Create virtual directory
  • Select web sites, application pool
  • Edit config file

Background

Based on a requirement in our project, I had to implement WIX setup projects. I was new into deployment and tried hard getting the project up and running. Well I should say thanks for the tutorial at: http://www.tramontana.co.hu/wix/ . Going further ahead in this article, I have created a kind of solution template which can be used to create a web setup in Visual Studio 2005. It has been built using .NET 2.0, Wix 3 (also votive for VS2005 integration).

Using the code

* What does this do?
Well, create web setup with some basic custom actions...

* What does it have?
It has the following features:
* Create web setup from wix script.
* ComponentWriter, writes the list of files to be added in setup, upgrades version no.
* Web Depolyment project precompiles the web project.
* CustomInstaller helps in creating event source, virtual directory, edit config file (you can also do it in WDPs).

* How to use?
Well, in the Web Deployment project, (right-click "Open project file...") just add the following code:
<!-- My customization -->
  <UsingTask AssemblyFile="..\SolutionItems\Djans.ComponentWriter.exe" TaskName="ComponentWriterTask" />
  
  <PropertyGroup>
    <SourceDirectory>$(OutputPath)</SourceDirectory>
  </PropertyGroup>
  
  <ItemGroup>
    <CustomInstallerFiles 
     Include="..\SolutionItems\Djans.CustomInstaller.dll;..\SolutionItems\Djans.CustomInstaller.dll.config"    
    />
    <EnvironmentFiles Include="..\SolutionItems\*.xml" />
  </ItemGroup>

  <ItemGroup>
    <FilesToBeDeleted Include="$(SourceDirectory)\bin\*.pdb;$(SourceDirectory)\*.csproj*" />
  </ItemGroup>

  <Target Name="AfterBuild">
    <Message Text="**************** After Build **********************" />

    <CallTarget Targets="DeleteUnwantedFiles" />
    <CallTarget Targets="CopyInstallerFiles" />
    <CallTarget Targets="CopyEnvironmentFiles" />
    <CallTarget Targets="WriteWix" />
  </Target>

  <Target Name="DeleteUnwantedFiles">
    <Message Text="Deleting unwanted Files ..." />
    <Delete  Files="@(FilesToBeDeleted)" TreatErrorsAsWarnings="true" />
    <RemoveDir Directories="$(SourceDirectory)\obj" />
  </Target>

  <Target Name="CopyInstallerFiles">
    <Message Text="Copying Installer Files ..." />
    <Copy SourceFiles="@(CustomInstallerFiles)" 
          DestinationFiles="@(CustomInstallerFiles->'$(SourceDirectory)\bin\%(Filename)%(Extension)')" />
  </Target>

  <Target Name="CopyEnvironmentFiles">
    <Message Text="Copying Environment Files ..." />
    <Copy SourceFiles="@(EnvironmentFiles)" 
          DestinationFiles="@(EnvironmentFiles->'$(SourceDirectory)\bin\%(Filename)%(Extension)')" />
  </Target>

  <Target Name="WriteWix">
    <Message Text="Writing wix files ..." />
    <ComponentWriterTask 
         SourceDirectory="$(SourceDirectory)" 
         OutputFile="..\WixSetup\Components.wxs" 
         UpgradeFile="..\WixSetup\WixSetup.wxs" 
    /> 
  </Target>
<!-- done --> 

From the target="WriteWix", the componentwriter task is called. It takes three arguments the location of source directory, the wix file which lists all the files to be deployed and the main wix file which has the Product element.

The ComponentWriter lists all the files from the release directory and writes the wix components file. Next it updates the version code in the Wix setup file (main). The ComponenWriter can be either separately called from command prompt or can be used as a task in msbuild script. The current WIX version does not automatically list the files needed for deployment. Hence I wrote a simple C# program to do the job, which will be launched before the WIX setup project is compiled. In the msbuild script, which in the sample is a part of the Web Deployment project, it is written as :

<Target Name="WriteWix">
    <Message Text="Writing wix files ..." />
    <ComponentWriterTask 
         SourceDirectory="$(SourceDirectory)" 
         OutputFile="..\WixSetup\Components.wxs" 
         UpgradeFile="..\WixSetup\WixSetup.wxs" 
    /> 
  </Target>

The ComponentWriter task takes three arguments:

  1. SourceDirectory: the complete physical path of the directory where source files are stored. The source files are those files which will be used for deployment.
  2. OutputFile: The wix file which lists out the directory structure, the files to be deployed and the feature element. In the sample it is named "Component.wxs".
  3. UpgradeFile: This is the main file which calls other wix files like UserInterface.wxs, Actions.wxs, Component.wxs etc. It also holds the Product, Upgrade elements. In the sample it is WixSetup.wxs.
  • Note: [UgradeFile] updates only first 3 parts, the 4th part is always 0 in the 4 part versioning. if you do not want to use upgrade provide '-skip'.

Screenshot - WixWebSetup.jpg


Files in WixSetup Project:

  • Component.wxs: This file lists all the files that are to be deployed.
  • WixSetup.wxs: This is the main file, has the product element, version details
  • Actions.wxs: the custom actions are defined in this file.
  • UserInterface.wxs: This defines the UI components for the setup.
  • Properties.wxs: This file holds all the property definitions of the setup
After compiling the Web deployment project, compile the Wix project, yo!, the setup is ready!

ComponentWriter from command prompt

Switches: '?', '/?', '-?', 'help' diplays this help.
'-skip' skips updating the upgrade code.

Usage:
ComponentWriter.exe [SourceDirectory] [OutputFile] [UgradeFile]

[SourceDirectory]: (Mandatory) The complete physical path of the directory where source files are stored.
The source files are those files which will be used for deployment.
[OutputFile]: (Mandatory) The wix file which lists out the directory structure, the files to be deployed and the feature element.
[UgradeFile]: (Optional) The wix file which has the upgrade element.
To skip using upgrade, instead of the file name, provide '-skip' as the argument.

Example:
Write component file and upgrade the version:

    Djans.ComponentWriter.exe c:\Project\Source c:\Project\WixSetup\Component.wxs c:\Project\WixSetup\WixMain.wxs
Write component file and do not upgrade the version:
    Djans.ComponentWriter.exe c:\Project\Source c:\Project\WixSetup\Component.wxs -skip

Note: [UgradeFile] updates only first 3 parts, the 4th part is always 0 in the 4 part versioning.

Points of Interest

  • Automate wix setup in Visual Studio 2005

History

--.

License

This article has no explicit license attached to it but may contain usage terms in the article text or the download files themselves. If in doubt please contact the author via the discussion board below.

A list of licenses authors might use can be found here