Follow below steps to create the setup project which will also allow you to keep multiple applications in same setup.
1. Select New Project from file you will see below window. Select other project types and Setup and Deployment->Setup Project.
2. Once you select setup file name and clicks OK button you will see below window. If you not then in right side solution explorer right click on project “Setup1” and select File System so that we will first setup the directories hierarchy.
3. Create Directory Hierarchies
Right click on the Application folder and click Add and
create folders.
If you want to add multiple applications then the directory hierarchy
will be look like below:
Here Application1 and Application2 are two totally
independent applications and a sub folder contains the corresponding executables.
To Add the executables and dlls for each Application, right click on the sub
folder and add “File” and select the location of the file. Then added file will
be appeared in right side. See below figure.
4. Create Desktop
Shortcut
Right click on “User’s
Desktop” and click on “Create shortcut
to user’s desktop” and give the appropriate name of the shortcut. I have given name MyApplication.exe. You can
also set the icon and give the description to the executable by selecting icon
in property window. See below figure:
5. Put Application in Program’s menu: For
this right click on user’s program menu just below user’s desktop option. And click
“Create shortcut to user’s program menu” and follow the same procedure as we
followed in creating desktop shortcut.
6. Now you are ready with the complete directory heararchy.
If you don’t want anything else then you can start building your setup file by
right clicking the project Setup1 and click build. Your setup project is ready. Enjoy !!!!
7. Now onwards you will see advanced options like setting
registry key option used by your application, set the user interface, set the
custom action on Intallation, Rollback, Uninstall or Commit. First we will see
how to set the registry options.
8. Right click on the project -> Select View -> Select
Registry. You can create new key in any registry location where your
application will go and read the some settings you have made while writing the
application. See below figure.

9. User Interface: You can change the process of installation
by adding dialogs or messages or caption to the form. To do this Right click on the project ->
Select View -> Select Custom Actions. The below window will appear. To add
the custom messages right click on the item and click property. You will see
property window in the right side and change the messages or captions to the
form as per your requirements. You can also add custom dialogs(TextBoxes,
radiobuttons, forms etc) in Start or Progress or End process by right clicking
it and add dialog.
10. Add Custom
Actions: If you want to perform some
task programmatically like delete registry keys directory hierarchy or the
entire setup component etc then you will need to add this. For this you will
need to create Installer.cs project for Setup.CostomActions. You can see below
figure I have given the required output from this Setup.CostomActions to the
Install, Commit, Rollback and Uninstall items.
The Installer class code given below:
using System;
using System.IO;
using System.Xml;
using System.Globalization;
using System.Windows.Forms;
using System.ComponentModel;
using System.DirectoryServices;
using System.Collections.Generic;
using System.Configuration.Install;
using System.Text.RegularExpressions;
namespace Setup.CustomActions
{
[RunInstaller( true )]
public partial class Installer : System.Configuration.Install.Installer
{
public Installer()
{
InitializeComponent();
}
public override void Install( System.Collections.IDictionary stateSaver )
{
base.Install( stateSaver );
}
public override void Rollback( System.Collections.IDictionary savedState )
{
base.Rollback( savedState );
//Remove the files or directory created and environment path if any set by setup
string target_dir = this.Context.Parameters[ "TargetDir" ];
if ( File.Exists( exe_new_path ) )
File.Delete( exe_new_path );
if ( File.Exists( cfg_new_path ) )
File.Delete( cfg_new_path );
Environment.SetEnvironmentVariable( "PATH", path, EnvironmentVariableTarget.Machine );
}
public override void Uninstall( System.Collections.IDictionary savedState )
{
string target_dir = this.Context.Parameters[ "TargetDir" ];
base.Uninstall( savedState );
//Remove the files or directory created and environment path if any set by setup
if ( File.Exists( exe_new_path ) )
File.Delete( exe_new_path );
if ( File.Exists( cfg_new_path ) )
File.Delete( cfg_new_path );
string path = Environment.GetEnvironmentVariable( "PATH" );
}
}