Windows Install XML (WIX) is a nice simple way to create an MSI installation file. Some of the items it automatically handles, such as registering with Add / Remove Programs, are very nice features.
In this example we are going to create a simple MSI that deploys a single file.
- This assumes you have already installed Visual Studio 2010. If not, download and install it now. http://www.microsoft.com/visualstudio/en-us. I haven’t tried the Express edition, but it may work.
- This also assumes that you have also installed the WIX 3.5 add-ons. If not, download the latest 3.5 or 3.6 build and install both ProjectAggregator2.msi and Wix35.msi: http://wix.sourceforge.net/releases/
Step 1 – Create a WIX project in Visual Studio
Creating a new project is a very simple task once you have done it a few times. However, I try to make my walk-thrus newbie proof, so even some one who has never done this feels comfortable. So if you need help with this step, use my instructions below. If you don’t, skip them.
- Open Visual Studio if it is not already open.
- Got to File | New | Project.
- You should have an option under Installed Templates for Windows Install XML. Select it.
- Now you should see the option for Setup Project. Select it.
- Enter a Name for the project. I called the project I made for this walk-thru DeployOneFile.
- Change the directory to store the project if you want. It doesn’t matter what directory you choose, but it is nice to keep your learning projects organized.
- Click OK.
Your project should now be created. In solution explorer you should now have a solution, a project, a reference and the Product.wxs. See the image below.
Ok, I hope that was easy for you. Let move on.
Step 2 – Add a file to the project
These steps are preformed in Visual Studio on the project you just created in the above step.
- Right-click on the project name, DeployOneFile, and from the drop down, choose Add | New Item.
- Select Text File.
- Name it whatever you want. I used Install.conf for this example.
- Click Add.
Your file is now added to the Visual Studio project. However, it is not automatically added into the Product.wxs as a file to be installed. This is done manually in the next step.
Step 3 – Take a moment to learn
We are going to change the Product.wxs file to include the file we just created.
The Product.wxs file has the following XML text in it. Take a moment to look at the XML nodes and their elements so are familiar with the syntax it is using.
The text of the Xml gives us hints as to what we are supposed to do in its comments. Take a moment and read the comments.
Step 4 – Configure the WIX Xml file to deploy that file
Lets start editing that XML file.
Note: I am going to use the term “node’ to indicate and XML section. So
- Uncomment the Component node the Directory nodes.
- Remove the two TODO: comments.
- Uncomment the ComponentRef node that is inside the Feature node.
- Remove the TODO: comment and the Note comment.
- Inside the Component node, at a File node as follows:
Ok, you are done. Yes, that was all there is too it.
You XML syntax should now look as follows:
Ok, you are ready to build.
Step 4 – Build the project
Well, there really isn’t much to debug, so we are only going to build a release version here.
- In the Visual Studio 2010 tool bar, there should be a drop down box that either says Debug or Release. Change it to Release if it is not already at Release.
- Select Build | Build Solution or use the shortcut key.
You should now have an MSI built in the project’s bin\release directory.
Step 5 – Test the MSI
Let’s go get the MSI and test it.
- Right-click on the project, DeployOneFile, and choose, Open Folder in Windows Explorer.
- In Explorer, navigate into the bin\release directory.
- You will see two files:
DeployOneFile.msi – This is the MSI and is all you need.
DeployOneFile.wixpdb – This is a file for debugging only. You may never use it unless you need to debug.
- You may or may not want to test the MSI on you development box. If you do, just double-click the MSI. Otherwise, copy it to a test box and run the MSI there.
- Verify that the file installed.
Note: If on a 64 bit system, it will by default install as an x86 app, so look in c:\program files (x86)\ for a folder called DeployOneFile.
- Check Add / Remove Programs to make sure the install shows up there and that the uninstall works.
Congratulations. You just use WIX to create and deploy your first MSI.
Bonus Information – Learning about Repair
Repairing an installation is an important feature of to understand.
What you are going to learn here, is that if you delete a file in a component that has the KeyPath=’yes’ tag, the component will reinstall.
- Make sure the MSI you just created above is installed. If you uninstalled it doing steps above, reinstall it.
- On the machine where you installed the MSI, Browse to the installation directory.My directory is here.
C:\Program Files (x86)\DeployOneFile
- The only file in that directory is the file you installed:
- Delete the Install.conf file.
- Still on the machine where you installed the MSI, go to Add / Remove Programs.
- Right-click on the DeployOneFile instance and choose Repair.
- The file you deleted should be restored.
Ok, so you probably have questions about repair. This was just a basic introduction. Hopefully we will learn more about repair as we go on.