Click here to Skip to main content
15,860,844 members
Articles / Web Development / ASP.NET
Article

A WIX web setup

Rate me:
Please Sign up or sign in to vote.
2.05/5 (8 votes)
9 May 20074 min read 71.3K   856   26   16
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:
XML
<!-- 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 :

XML
<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


Written By
Architect
India India
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
GeneralSome issues Pin
zlezj9-Jun-08 1:52
zlezj9-Jun-08 1:52 
GeneralFragmentRef removed from schema Pin
si61829-Aug-07 20:43
si61829-Aug-07 20:43 
GeneralRe: FragmentRef removed from schema Pin
si61829-Aug-07 20:51
si61829-Aug-07 20:51 
GeneralRe: FragmentRef removed from schema Pin
si61829-Aug-07 21:06
si61829-Aug-07 21:06 
GeneralRe: FragmentRef removed from schema Pin
JannuD30-Aug-07 1:48
JannuD30-Aug-07 1:48 
GeneralRe: FragmentRef removed from schema [modified] Pin
si61830-Aug-07 14:00
si61830-Aug-07 14:00 
BugRe: FragmentRef removed from schema Pin
dbirdz5-Jun-12 22:18
dbirdz5-Jun-12 22:18 
GeneralCustom Installer Pin
sekars21-May-07 2:26
sekars21-May-07 2:26 
GeneralRe: Custom Installer Pin
JannuD24-May-07 0:47
JannuD24-May-07 0:47 
GeneralRe: Custom Installer Pin
noobix3-May-10 22:16
noobix3-May-10 22:16 
Questionhow to update web.config? Pin
LaFlour15-May-07 1:28
LaFlour15-May-07 1:28 
AnswerRe: how to update web.config? Pin
JannuD15-May-07 10:25
JannuD15-May-07 10:25 
GeneralProblems with Article/Attachment Pin
IgDev9-May-07 5:18
IgDev9-May-07 5:18 
AnswerRe: Problems with Article/Attachment Pin
JannuD10-May-07 0:45
JannuD10-May-07 0:45 
QuestionI don't understand Pin
barbq20006-May-07 10:28
barbq20006-May-07 10:28 
AnswerRe: I don't understand Pin
JannuD6-May-07 22:35
JannuD6-May-07 22:35 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.