Friday, August 22, 2008

AddIn Part 5 : Cusom Actions on AddIn Installation

Apart from basic functionality of the AddIn, we also want to copy some of the files like text and images for use in our AddIn when our AddIn gets installed on client system.

This can be achieved using Setup project functionality - Custom Actions.

First of all, let’s add one class library project to the solution and name it say FileHandler and add one Installer class to this project. After this step, our solution structure looks like:

Being an Installer class, we can override different methods on Handler class like, OnAfterInstall, OnAfterUninstall, OnAfterRollback, OnBeforeInstall, OnBeforeUninstall and OnCommited.

In our case we will override OnAfterInstall and will write the code to create one text file (overwrite if exists) on client system and in OnAfterUninstall event, we will delete this file.

As the code is ready, now we have to assign this module to Installer. Right click the AddIn Setup project and go to View -> Custom Actions.

In the resulting window, select Install and Right click and then Add Custom Action...

You will see “Select item in Project” dialog, click Add Output…, and set the Primary output of FileHandler using figure shown below

Click Ok.

We should set the same handler for the Uninstall also using same steps above as we want the file to be deleted when this AddIn is uninstalled.

Now when you install this AddIn, it will create one text file on client computer and will get deleted on uninstalling.

No comments: