Visual Studio Package and Development wizard provides facility to create setup of your .Net Application. But in some cases we want to control the installation steps using custom action, means we want to add some custom functionality while installing the application.
Using custom action we can handle functionalities like-
- Setting registry value while installation
- Reading registry value while installation
- Serial key implementation
Etc.
In this article, I am explaining - How to add custom action to Windows Installer in C#?
Here I am giving complete steps with pictorial representation. Follow these steps -
Step1: First, develop your application with required functionality.
Step2: For performing your custom action while installing application, we need to add "Installer Class" in application. Add one "Installer Class" using "Add New Item" to the project like this-
Step 3: After adding Installer Class to the project , add your custom functionality , Here I am adding some code in "MyInstaller.cs" file-
//Code to perform at the time of installing application
public override void Install(System.Collections.IDictionary stateSaver)
{
System.Windows.Forms.MessageBox.Show("Installing Application...");
}
//Code to perform at the time of uninstalling application
public override void Uninstall(System.Collections.IDictionary savedState)
{
System.Windows.Forms.MessageBox.Show("Uninstalling Application...");
}
Here I have added to events, this is for custom functionality, you can write your own code which you want to perform at the time of Installing and uninstalling application.
Step 4: Now set your application in "Release Mode" and build it.
Step 5: Now we have to add setup project for developed application, so right click on "Solution Explorer" and click on "Add -> New Project option".
Here you will get Project Templates dialog, Select "Visual Studio Installer" from "Other Project Types" option.
See this Image-
Step 6: After adding Setup project to solution, set project output for Setup project. For this right click on setup project and click on "Add -> Project Output"
you will get "Add project Output Group Dialog”, Here you need to set some setting like this-
After setting click on "OK" button.
Step 7: Now to add custom action, again right click on "Setup project" and click on "View -> Custom Actions".
Now to set Custom action for installation right click on "Install" click on "Add Custom Action",
Here double click on "Application folder" and select Primary output from Myproject and click on "OK" button.
Step 8: Repeat same for UN-installation process also.
Step 9: Finally your solution structure will be like this-
Step 10: Now build setup project and finally build the solution. Now you are done.
To test the complete process just try to install your application now, while installing application you will get message like this-
This is the same message which we have given in Install () event. Means whatever the action or code we will write in this event that will be perform at the time of installing application.
//Code to perform at the time of installing applicationpublic override void Install(System.Collections.IDictionary stateSaver)
{
System.Windows.Forms.MessageBox.Show("Installing Application...");
}
And when you will uninstall application you will get message like this-
Here also we can see that the code which we have written in Uninstall () event that is executing.
Like Install () event we can handle Uninstall () event also.
//Code to perform at the time of uninstalling application
public override void Uninstall(System.Collections.IDictionary savedState)
{
System.Windows.Forms.MessageBox.Show("Uninstalling Application...");
}
These complete helps you to handle custom action while installation or uninstallation, Using these step we can implement serial key for application, means while installing application we can set expiration time for application and while uninstallation we can delete application related registry settings.
Thanks
great post...
ReplyDeleteThanks for appreciation.
DeleteBefore you install a release version of the .NET Framework, you must remove any beta versions on which the release version is based.
ReplyDelete.Net Application Development
I am reading a registry entry from HKCU hive in custom action, but it is not reading properly(coming as zero). Could you help with the same?
ReplyDeleteI am readying the all post. it is great and nice post. InstalleRex is a unique, smart and modern, cloud based installer, customized to your needs. Installerex makes cloud base installers ,Installerex expertise on the download monetization.InstalleRex build me a great and agile installer just the way i wanted , installerex custom installers
ReplyDeleteNice Article !!
ReplyDeleteThanks for appreciation.
DeleteI really liked this post. Thank you so much for sharing this wonderful piece of work with us.
ReplyDeleteinstallerex
Thanks for appreciation.
Deletegreat thing yar..I am trying to do this....nice.keep it up.
ReplyDeleteThanks for appreciation.
DeleteC# create custom setup navigation for Windows application
ReplyDeletethanks a lot for this. helped a lot
ReplyDeleteThanks for appreciation.
DeleteNice Tutorial :)
ReplyDeleteBut it seems like I have a problem every time i try to install gives me this error: "Error 1001. InstallUtilLib.dll: Unknown error".
(Only occurs with custom action).
Any help would be appreciated.
Hi,
DeleteThanks for the appreciation...
Check this link hope this will help you-
http://social.msdn.microsoft.com/Forums/windows/en-US/1a1343ba-6991-4a69-8a2c-c0a0a23ead5b/error-1001-installutillibdll-unknown-error
This comment has been removed by the author.
DeleteGreetings
DeleteLooks like i only could use .NET Framework 3.5 =/
I tried with .Net 3.5 and its working without problems but in .Net 4.5 appears that annoying error :(
Anyway I'll try to figure it out and if I find workaround i'll give the solution ;)
P.S:
I think that everybody should look to this tutorial after read this one :)
Link -> http://blogs.msdn.com/b/wriju/archive/2009/05/21/setup-and-deployment-custom-action-to-capture-user-input.aspx
I hopefully that you dont care for sharing this...
And thanks for the quick answer =D
Custom applications are available in market become some applications are much expensive due to clients preferred to customized application design to reduced their operating cost. Now on Outsourcing you can hire application developer from all over the world.
ReplyDeleteplease i want to create the database when i finish instaling the projet and i don't know what to write in the installer classe .
ReplyDeletecan you help me please !!
Great Post. Just what looking for. Thank you very much..
ReplyDeleteHello dear,
ReplyDeleteI want put condition before installation of setup if this condition is verified and true then setup should run else not
Thanks alot
ReplyDeleteGreat post! I am see the programming coding and step by step execute the outputs.I am gather this coding more information. It's helpful for me my friend. Also great blog here with all of the valuable information you have.
ReplyDeleteDot Net Training in Chennai
I am really happy with your blog because your article is very unique and powerful for new reader.
ReplyDeleteClick here:
Selenium Training in Chennai | Selenium Training in Bangalore | Selenium Training in Pune | Selenium online Training
Can you please explain The above process in C++
ReplyDeleteJitendra sir .. hats off for your article
ReplyDeleteThanks for spending all your pleasant time to make such a Creative content for us.Keep doing the same as Ever
ReplyDeleteJava training in chennai | Java training in annanagar | Java training in omr | Java training in porur | Java training in tambaram | Java training in velachery
I'm getting mad about this issue, so thank you for sharing! I have implemented your solution and I see the message when installing, but not when uninstalling, and I need to perform some actions at uninstalling... Dou you have any idea why it does not work? Thank you in advance!
ReplyDeleteNice to learn something different about this topic from this article. Thanks for your valuable information, it is very easy to learn and understand.
ReplyDeleteAWS training in Chennai
AWS Online Training in Chennai
AWS training in Bangalore
AWS training in Hyderabad
AWS training in Coimbatore
AWS training
What as up, I read your blogs like every week. Your writing style is awesome, keep up the good work!
ReplyDeleteOracle fusion order management online online training
Oracle golden gate online online training
Oracle identity manager online online training
its really interesting to read and useful article
ReplyDeletebest-angular-training in chennai |
ReplyDeletehadoop training in chennai
software testing training in chennai
Nice blog thank you .For your Sharing It's a pleasure to read your post.It's full of information I'm looking for and I'd like to express that "The content of your post is awesome"
ReplyDeleteDotnet Training in Chennai
Core java Training in Chennai
ReplyDeleteNice blog thank you .For your Sharing It's a pleasure to read your post.It's full of information I'm looking for and I'd like to express that "The content of your post is awesome"
ASP.NET Training in Chennai
C#.NET Training In Chennai
hadoop training in chennai
software testing training in chennai
ccna training in chennai
Whatsapp Number Call us Now! 01537587949
ReplyDeleteoutsourcing in Bangladesh
USA pone web iphone repair USA
USA SEX WEB careful
bd sex video B tex
bd sex video sex video
bd sex video freelancing course
You should take help from professionals who have immense experience on Microsoft Business Central. They will help you with Solutions easily. Read: dynamics 365 business central pricing
ReplyDelete