Monday, April 28, 2008

Visual Studios 2005 Addin Setup

The process to get a VS Addin working is divided into two steps

1. Create a Extensibility project
Step 1: Launch Visual Studio.

Step 2: Click File -> New -> Project.

Step 3: Select “Visual Studio Add-in” from the New Project dialog (under Other Project Types -> Extensibility as shown below) and give the project a name. In this case I’ve named the project BuildCompleteSample.



Step 4: Visual Studio Add-in Wizard: Click next.

Step 5: Visual Studio Add-in Wizard (Page 1 of 6): Select “Create an Add-in using Visual C#” and click next.

Step 6: Visual Studio Add-in Wizard (Page 2 of 6): Deselect “Microsoft Visual Studio 2005 Macros” and click next.

Step 7: Visual Studio Add-in Wizard (Page 3 of 6): Add a name and description and then click next. For this sample I set them as shown below:

Name: Platform Builder - Build Complete Sample
Description: This sample shows how to generate an action when a build is completed.

Step 8: Visual Studio Add-in Wizard (Page 4 of 6): Select “I would like my Add-in to load when the host application starts” and click next.

Step 9: Visual Studio Add-in Wizard (Page 5 of 6): Click next or fill in the information to be included in the About dialog box if you wish.

Step 10: Click finish.

Step 11: Open Connect.cs and scroll to the bottom and add a private member variable to store a reference to the BuildEvents.

private BuildEvents _buildEvents;

Step 12: Modify the OnStartupComplete method to get the reference to the BuildEvents and register an OnBuildDone event handler.

public void OnStartupComplete(ref Array custom)
{
_buildEvents = _applicationObject.Events.BuildEvents;
_buildEvents.OnBuildDone += new _dispBuildEvents_OnBuildDoneEventHandler(_buildEvents_OnBuildDone);
}

Step 13: Implement the event handler and add code to start your favorite sound. There are a lot of ways to play sounds but the following is a very simple way that gets the job done for this sample.

///
/// The method that handles the on build done event.
///

/// Represents the scope of the build.
/// Represents the type of build action that is occurring, such as a build or a deploy action.
private void _buildEvents_OnBuildDone(vsBuildScope Scope, vsBuildAction Action)
{
if (Action == vsBuildAction.vsBuildActionBuild)
{
// Get the path to the executing assembly
System.Windows.Forms.DialogResult done;
if(Action == vsBuildAction.vsBuildActionBuild)
done = System.Windows.Forms.MessageBox.Show("Build Done"); }
}

Step 14: Compile the add-in

2. Create a setup

Step 1. Goto File -> Add -> New Project

Step 2. Other Project Type -> Setup and Deployment -> type in the name of the project.

Step 3. Select Application Folder -> right Click -> Add -> Project Output.

Step 4. Select Application Folder -> right Click -> Add -> Assembly.

Step 5. Select and Add 'extensility.dll' from the .Net tab.

Step 6. Select Application Folder -> right Click -> Add -> Assembly.

Step 7. Repeat step 6&7 for all the .dll files required for the addin project (in this case I added "System.Windows.Forms.dll"

Setp 8: Build The project

You will get a msi and an exe at the target directory.

Reffernces :
Setup&Deployment
VS Addin

No comments: