Create Add-In
This subroutine checks for the existence of the Add-In. The status of the
installation is reported to the user.
private void btnCheckForAddIn_Click(object sender, System.EventArgs e)
{
bool isInstalled = false;
System.Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.7.1");
object obj = System.Activator.CreateInstance(t, true);
// Create a DTE object, to get the Add-In informations.
EnvDTE.DTE myDTE = (EnvDTE.DTE)obj;
// Create a collection of all the AddIn objects.
EnvDTE.AddIns myAddIns = myDTE.AddIns;
// Iterate through the AddIns to determine if the C# How To
// Example Add-in is installed.
foreach(EnvDTE.AddIn myAddIn in myAddIns)
{
if (myAddIn.Name == "How-To Example Add-In")
{
isInstalled = true;
}
}
// Report installation status to the user.
if (isInstalled)
{
txtInstalled.Text = "C# How To Example Add-in is installed!";
}
else
{
txtInstalled.Text = "C# How To Example Add-in is not installed!";
}
}
This subroutine executes when the main form is loaded. It simply calls the btnCheckForAddIn_Click subroutine to determine if the Add-in is loaded.
private void frmMain_Load(object sender, System.EventArgs e)
{
Call the btnCheckForAddIn_Click subroutine.
btnCheckForAddIn_Click(this, new System.EventArgs());
}
