Saturday, January 19, 2013

Creating a distribution package (.msi) for you VS project

Creating a distribution package (.msi) for you Visual Studio project

So you created a nice application in C# and want to share it with the world.
One way to do it is by creating a distribution package. By doing so Microsoft helps you by adding a few features to your setup process. I'll show you a few in the step by step.

First add a new installer project to your solution.
I choose Visual Studio Installer -> Setup Wizard which can be found in Setup and Deployment category

Visual Studio Installer
Visual Studio Installer

 Follow the wizard, its fairly simple.
Visual Studio Setup Wizard - Step 1

 Choose the project type you wish to create.

Visual Studio Setup Wizard - Step 2

Choose the project output you wish to use.
I usually select "Primary output from <Project>" as in the sample image below.
Visual Studio Setup Wizard - Step 3

The next page allows you to select files to add to the distribution.
The files can be a readme file, nfo file, images or whatever else you want to add.
Visual Studio Setup Wizard - Step 4
The final page is the confirmation.
At this point your done creating the simple package.

Adding Prerequisites to Installer

Sometimes, your project requires prerequisites to run correctly. The most common prerequisite is the .Net Framework itself. The Visual Studio Installer allows you to add the prerequisites with your distribution thus helping the user install the application correctly and your program run smother.

To add prerequisites, go to the setup project and open the properties.
Notice the Prerequisites button on the lower right.
Visual Studio Installer properties

After clicking the button, we can add the relevant items.
In my case I choose the .NET Framework 4 Client Profile so in the case that the user didn't download in advance, the .NET Framework, the Installation will help the user do so.
Notice that you can choose from where you want the component to be installed.
Either download from the vendors website (usually Microsoft) or from the location of the application. The same location means that the prerequisite will be bundled with your program making the install file larger.
I've never found much use for the third option.

Visual Studio Installer Prerequisites

Creating a shortcut to the application

One of the most important things an installer needs to do is add a shortcut to start up the application, we wouldn't want the user looking for the application all over the filesystem :-)

Go to the Install Projects' File System Editor. You can find it by selecting the Installer project from the solution explorer and notice the new icons at the top of the solution explorer. The file system editor is the second from the left.

Select the Application Folder
You should see the "Primary Output ..." in the window beside it.
Right click on the "Primary Output ..." and select the "Create Shortcut" option.
Now you can drag the new shortcut to the User's Desktop or the User's Program Menu.
I usually rename the shortcut as well.

Visual Studio Installer File System
The Installer has loads more features, if you find any good ones, leave a comment.


  1. many people think that gps based vehicle tracking solutions is just only a tracking location of the vehicle but it more then it it also monitor driver safety, fuel monitoring etc.