Deploying Custom Tool using a Setup Project

April 8, 2009 · Posted in .NET, ASP.NET, C# 
Easy AdSense by Unreal

CustomToolDeploymentForVisualStudio.zip

Introduction

Making a custom tool work on the developers machine require several actions like placing keys in the registry and registering your DLL Library using the regasm command. This post will discuss the automation of this procedures using a setup project. for more information on making your own custom tool visit my post Building a Custom Tool Generator For Visual Studio

Using the Code

First add a class in your CustomTool Library Project that inherits from the Installer class in this class override two methods the first is the Install Method the Second is the Uninstall method.

To Get the regasm.exe path you could use the InteropServices.RuntimeEnvironment class to get the runtime directory of the .NET framework. Then you need to get the assembly location. After that you could simply start the process of the regasm and pass to it the /codebase parameter and the path of the library.

public override void Install(System.Collections.IDictionary stateSaver)
{
    base.Install(stateSaver);
    string regasmPath = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + @"regasm.exe";
    string componentPath = base.GetType().Assembly.Location;
    System.Diagnostics.Process.Start(regasmPath, "/codebase \"" + componentPath + "\"");
}

To uninstall remove the component registeration by the /unregister parameter

public override void Uninstall(System.Collections.IDictionary savedState)
{
    base.Uninstall(savedState);
    string regasmPath = System.Runtime.InteropServices.RuntimeEnvironment.GetRuntimeDirectory() + @"regasm.exe";
    string componentPath = base.GetType().Assembly.Location;
    System.Diagnostics.Process.Start(regasmPath, "/unregister \"" + componentPath + "\"");
}

The Setup Project

Now make a new setup project and add the output of the CustomTool Library to it. Then Right Click the setup project and select view then select custom actions.
customactions2
Then Add the CustomTool Project Output to the Install and Uninstall Sections as in the image below.
customtoolsetup
ok now you need to add the registry values right click on the setup project and then View then select Registry To add the Needed Registry Values follow the structure in the figure below.
customtoolregistry

Share your Thoughts

Now all you have to do is just build the setup project :) and you will have a setup deployment for your custom tool.
please share your thoughts and feel free to drop any comments. Hope you enjoy the project.

Short URL for this post: http://bit.ly/152XFS

Comments

3 Responses to “Deploying Custom Tool using a Setup Project”

  1. szehau on April 8th, 2009 1:21 pm

    Hi,

    You have an good idea here. Just looked at your code, I understand what you trying to do is to create a Codebase entry in the registry when installation and remove the Codebase entry when uninstalling the DLL.

    But for the Unintall part, you have put “/codebase” as the parameter for regasm.exe, is it a mistake or any reason behind that? Shouldn’t it be “/u”?

  2. admin on April 9th, 2009 3:26 am

    Hi, yeah sorry its a mistake it should be /unregister instead of /codebase i will correct it

  3. Prabir Shrestha on January 24th, 2010 1:01 pm

    How do I detect 64 bit or 32bit windows. If its 64bit we need to store the regsitries in WOW6432Node.
    Instead of making two setup I want it to automatically detect and install it in the appropriate registry key.
    Thanks.

Leave a Reply




Spam Protection by WP-SpamFree

























































download movies

ñêà÷àòü ôèëüìû