C# : Create Setup project which also include multiple applications in one setup
By Jignesh Shah
Hi Friends,
I have prepared below steps with snap shots that you can follow very easily to create the setup project. This will also tell about how to create setup project which includes multiple application. Moreover it also covers all the possible custom actions, registry keys and custom dialogs that you can add while building setup project.
Any question regarding this article will be most welcomed.
-Jack
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" );
}
}
Popularity (21487 Views)
| Biography - Jignesh Shah |
"I am electric engg and professor in college. Working on all the softwar languages are my passion." - Jignesh |
Article Discussion: C# : Create Setup project which also include multiple applications in one setup
Require additional information regarding setup projecty
Ctal Jagad replied
to Jignesh Shah at Saturday, November 01, 2008 3:53 PM
Hi Jack,
Your Article was very nice.
I have one question regarding setup project. I am trying it but not grtting sucess.So please help me if you can.
My problem is :: I have developed add-in for outlook. When I install this Add-in I want to check that Outlook is Open or not ? If Open then ask user to first close the outlook & then install again.
Its very urgent please help me...
Thanks
Regards
Ctal
reply
Perry replied
to Ctal Jagad at Saturday, November 01, 2008 3:53 PM
I think you will need to check outlook.exe is running instance or not using Application class or GetProcessByName function in Process class.
Regards,
Jack
Require Additional information for Setup Project
Ctal Jagad replied
to Perry at Saturday, November 01, 2008 3:53 PM
Thanks a lot Jack for your reply.
I already tried getting process from task manager and check outlook.exe is running or not.
But
my question is Where I have to write this code ??? Because when I
install my add-in Onconnection Method is not called, It is called when
user opens the outlook.
So I think I have to write this code when my " Add-in " is installed .
Please help me if you know how we can check this during installation process.
Thanks
Regards
Ctal
403: access forbidden
anand patil replied
to Perry at Saturday, November 01, 2008 3:53 PM
I have a list of customers. whenever a customer tat includes symobl ' in them like mc'donalds.On click of the search button i get the below error.
403: Access Forbidden
Due to the presence of characters known to be used in Cross Site Scripting attacks, access is forbidden. This web site does not allow Urls which might include embedded HTML tags.
Can anyone help me on this..For all the other customers it works fine.
How to include multiple setups in one setup project
uet champ replied
to Jignesh Shah at Saturday, November 01, 2008 3:53 PM
Hi,
Great article. I really got the starting point on how to do it. I have one related question, I wanted to have a setup of setups. Actually I have two projects in my solution. One is my windows application and the other is a windows service. I just wanted to have setup for both of these projects.
With my understanding we can have separate setup projects for each of the project in my solution but the question is how to have a single setup which can install both of the applications (windows app and windows service).
I hope the problem is conveyed.
Regards,
Uetian
Thanks
uet champ replied
to Perry at Saturday, November 01, 2008 3:53 PM
Thanks a lot, it really helped
Uetian
How to customize application title through code?
Hi,
Thank you for sharing this great article on custom installation.I have a doubt, whether it is possible to overwrite Application Title , version , etc... in application coding. I am developing 2 application with some changes in a single source code. Now, I ma adding 2 setup projects and changing settings and taking setup.I want to have a SINGLE setup for those 2 application and the setup properties should be changed through code via settings. is it possible ?
Thanks,
Mathi
des replied
to Mathiyazhagan Sekar at Saturday, November 01, 2008 3:53 PM
Hi,
Well, i have made a setup for my project. But sometime a problem arises, when i make changes in my code like add some new windows forms etc. and than i build me solution also i explicitly build my setup project, now when i run my setup I see no changes that i have made. Also, can you tell me that is there any way to remove the graphic from the setup installation wizard and set a custom graphic icon there, this is at the top right of the installation wizard.
Thanks.
Installation within installation?
ramanathan replied
to des at Saturday, November 01, 2008 3:53 PM