logo

C# : Create Setup project which also include multiple applications in one setup

By Jignesh Shah
Printer Friendly Version
View My Articles
3547 Views
    

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" );

}
}

Biography - Jignesh Shah
"I am electric engg and professor in college. Working on all the softwar languages are my passion." - Jignesh


Didn't Find The Answer You Were Looking For?

EggHeadCafe has experts online right now that may know the answer to your question.  We pay them a bonus for answering as many questions as they can.  So, why not help them and yourself by becoming a member (free) and ask them your question right now?
Ask Question In Live Forum

If you have an OpenID and do not want to become a member of the EggHeadCafe forum, you can also sign on to Chat Chaos and post your question to our real time Silverlight chat application.
Ask Question In Chat Chaos

Article Discussion: C# : Create Setup project which also include multiple applications in one setup
Jignesh Shah posted at Saturday, November 01, 2008 1:07 PM
Original Article
 

Require additional information regarding setup projecty
Ctal Jagad replied to Jignesh Shah at Monday, November 24, 2008 7:19 AM

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
Raj Cool... replied to Ctal Jagad at Saturday, November 29, 2008 7:24 AM

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 Raj Cool... at Tuesday, December 16, 2008 1:39 AM
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
 

reply
Raj Cool... replied to Ctal Jagad at Tuesday, December 16, 2008 1:53 AM
>>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.

You above statements clearly says that you have to write it in add-in. Are you writting add-in in C# then i think it is straight forward. Alternativelly you can kill outlook.exe if its already running using taskkill or any other utility after prompting user and continue with installation.

 

403: access forbidden
anand patil replied to Raj Cool... at Thursday, December 18, 2008 1:49 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.

 

reply
Raj Cool... replied to anand patil at Thursday, December 18, 2008 11:06 PM
Please post your question in Message board. you will get definately positive response.
 

How to include multiple setups in one setup project
uet champ replied to Jignesh Shah at Friday, May 08, 2009 10:40 AM

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

 

reply
Raj Cool... replied to uet champ at Friday, May 08, 2009 1:56 PM
You can have only one setup for both of your projects Service and Windows application. You will need to add the installer class for your service project which will be another project(in your case third project) say Setup.Custom which will start your service, setup the running context etc,etc while you run the setup. You can google for some example. Try to get Sudowin source code for Sourceforge.com. That source code have so many console and class  application along with service application and they also generating Setup.Custom project and eventually has only on setup file.

Regards.
 

Thanks
uet champ replied to Raj Cool... at Friday, May 15, 2009 6:25 AM

Thanks a lot, it really helped

Uetian

 

How to customize application title through code?
Mathiyazhagan Sekar replied to Jignesh Shah at Tuesday, July 21, 2009 4:01 AM
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
 






  $1000 Contest    [)ia6l0 iii - $228  |  Jonathan VH - $161  |  Huggy Bear - $135  |  F Cali - $95  |  egg egg - $94  |  more Advertise  |  Privacy  |   (c) 2010