How To Perform Custom Actions and Upgrades Using Visual Studio Installer
How To Perform Custom Actions and Upgrades Using Visual Studio Installer
In Focus
C# C# Corner
How To Perform Custom Actions And Upgrades Using Visual Studio
ASK A QUESTION CONTRIBUTE
Installer
Visual Studio provides installer projects in order to make application deployment simple. To have Visual Studio installer project type with
your version of Visual Studio, make sure you download and install corresponding extensions to your machine.
3 3 29.7k
ProjectInstaller.zip
Download Free .NET & JAVA Files API
Visual Studio provides installer projects in order to make application deployment simple. To have Visual Studio installer project type with
your version of Visual Studio, make sure you download and install corresponding extension to your machine.
To install Visual Studio Installer for Visual Studio 2015, see here.
Setup Project
Web Setup Project
Merge Module Project
Setup Wizard
https://www.c-sharpcorner.com/article/how-to-perform-custom-actions-and-upgrade-using-visual-studio-installer/ 1/10
20/6/2019 How To Perform Custom Actions And Upgrades Using Visual Studio Installer
CAB Project
In Focus
C# C# Corner
ASK A QUESTION CONTRIBUTE
As our scope is “Setup Project” type, we will focus on adding custom action and upgrades of this type, in this article.
Let’s create a project called SampleInstaller using “Setup Project” template. The ultimate purpose of SampleInstaller project is to deploy
binaries built using Windows project. Hence, let’s create windows service project called “SampleWinService”. The generated binaries
from SampleWinService project has to be deployed to target machine using SampleInstaller project.
https://www.c-sharpcorner.com/article/how-to-perform-custom-actions-and-upgrade-using-visual-studio-installer/ 2/10
20/6/2019 How To Perform Custom Actions And Upgrades Using Visual Studio Installer
In Focus
C# C# Corner
ASK A QUESTION CONTRIBUTE
From “Add Project Output Group” dialog, select appropriate project in Project eld for which you planned to ship binaries. Under the list
box of this dialog, select “Primary output” to tell the installer that it has to pick up only DLLs and EXEs from the selected project for
deployment and click OK.
Now, highlight SampleInstaller and click on Properties tab seen right side of the project. The below View would be seen,
https://www.c-sharpcorner.com/article/how-to-perform-custom-actions-and-upgrade-using-visual-studio-installer/ 3/10
20/6/2019 How To Perform Custom Actions And Upgrades Using Visual Studio Installer
In Focus
C# C# Corner
ASK A QUESTION CONTRIBUTE
Now, ll the elds appropriately as per the description mentioned when you highlight the eld. Make sure you select appropriate
platform using TargetPlatform. If you want to install this installer on 64 bit machine as 64 bit application then select x64 instead of x86.
https://www.c-sharpcorner.com/article/how-to-perform-custom-actions-and-upgrade-using-visual-studio-installer/ 4/10
20/6/2019 How To Perform Custom Actions And Upgrades Using Visual Studio Installer
In Focus
UpgradeCode is important GUID (Globally Unique Identi er) which is used to identify the family of products using this number. When
C# C# Corner
the Version number of product get changed, the UpgradeCode won’t change but ProductCode get change. This allows user to perform
ASK A QUESTION
upgrade operation of the product. Hence, make sure that ProductCode is changed when changing CONTRIBUTE
the Version, if you planned to
perform upgrade. This can be done by clicking YES to below question when you modify the Version number,
Needless to say that if you don’t want to perform upgrade, then click No option.
Custom Actions are the one which enables the main project’s (SampleWinService) custom code to be executed at corresponding installer
actions. To con gure that:
https://www.c-sharpcorner.com/article/how-to-perform-custom-actions-and-upgrade-using-visual-studio-installer/ 5/10
20/6/2019 How To Perform Custom Actions And Upgrades Using Visual Studio Installer
In Focus
C# C# Corner
ASK A QUESTION CONTRIBUTE
Here, four basic installer actions appear: Install, Commit, Rollback and Uninstall. If you want to customize any of the installer action,
highlight the action > Add Custom Action… and select the project and type of output where the custom action handler code been
written.
For instance, by default, SampleWinService project doesn’t start the installed service on target machine. Also, we want to stop the service
when the product is about to get uninstalled. If we want to achieve them, we need to write custom code in SampleWinService project
using appropriate class and methods like below,
https://www.c-sharpcorner.com/article/how-to-perform-custom-actions-and-upgrade-using-visual-studio-installer/ 6/10
20/6/2019 How To Perform Custom Actions And Upgrades Using Visual Studio Installer
In Focus
C# C# Corner
Override OnAfterInstall method of ProjectInstaller class and perform start operation to enable automatic windows service start after
installation. Similarly, override OnBeforeUninstall method to stop the running service at the time of product uninstallation.
Upgrade
https://www.c-sharpcorner.com/article/how-to-perform-custom-actions-and-upgrade-using-visual-studio-installer/ 7/10
20/6/2019 How To Perform Custom Actions And Upgrades Using Visual Studio Installer
In Focus is the process of installing or uninstalling required feature or component or binaries or le from the existing installation. To
Upgrade
C# C# Corner
perform upgrade using Visual Studio installer perform these steps:
ASK A QUESTION CONTRIBUTE
Change the Version number of the installer from it’s properties
Say YES to the dialog popup so that product code get changed
Don’t change the UpgradeCode
Change the version number of assembly (EXE/DLL) from previously installed version so that installer could understand what
assembly needs to be replaced at upgrade.
Write appropriate CustomAction handler in OnBeforeInstall method to remove existing service from panel or uninstall the existing
version, if required.
Build the installer with modi ed version number, ProductCode and assembly version and Install
Note
When performing upgrades to remove the existing product automatically, one should override OnBeforeInstall method of Installer class
and write the code to remove the product. Refer to OnBeforeInstall method for details.
Rajan M
https://www.c-sharpcorner.com/members/rajan-m4
1475 33.1k
3 3
Type your comment here and press Enter Key (Minimum 10 characters)
https://www.c-sharpcorner.com/article/how-to-perform-custom-actions-and-upgrade-using-visual-studio-installer/ 8/10
20/6/2019 How To Perform Custom Actions And Upgrades Using Visual Studio Installer
In Focus I was wondering why the code in the screenshot wasn't in the ZIP le download?
C# C# Corner
David Hunt Jun 10, 2019
1794 4 0 0 0 Reply
ASK A QUESTION CONTRIBUTE
Hi. I'm having an issue with the OnBeforeUninstall override and I was wondering if you or anyone else had an idea. Before my OnBeforeUninstall
method gets called, my Setup Project Uninstaller prompts me that my service is in use. I'm not sure what I can do at this point to stop my service
before it does this check/prompt. Immediately after this prompt, the OnBeforeUninstall method gets called.
aa Apr 23, 2019
1790 8 0 0 0 Reply
It's probably important to mention that this code requires a reference to the System.Con guration.Install assembly, and to add the following
using statements: using System.ComponentModel; using System.Con guration.Install;
Jamie LeTual Sep 26, 2018
1795 3 0 1 0 Reply
TRENDING UP
10 Angular Version 8? What's New? Breaking Changes? Updates? And Many More!
https://www.c-sharpcorner.com/article/how-to-perform-custom-actions-and-upgrade-using-visual-studio-installer/ 9/10
20/6/2019 How To Perform Custom Actions And Upgrades Using Visual Studio Installer
About Us Contact Us Privacy Policy Terms Media Kit Sitemap Report a Bug FAQ Partners C# Tutorials
©2019 C# Corner. All contents are copyright of their authors.
https://www.c-sharpcorner.com/article/how-to-perform-custom-actions-and-upgrade-using-visual-studio-installer/ 10/10