Hi,
I build an add-in for Visual Studio 2005.
I use the wizzard, I fixed the bug with envdte reference and build my
project immediately after the wizzard.
All seems to work, the add-in is shown in add-in Manager window, but no
button appears in Tools window.
Here is my code:
namespace MyAddinTest
{
using System;
using Microsoft.Visua lStudio.Command Bars;
using Extensibility;
using EnvDTE;
using EnvDTE80;
/// <summary>The object for implementing an Add-in.</summary>
/// <seealso class='IDTExten sibility2' />
public class Connect : Object, IDTExtensibilit y2, IDTCommandTarge t
{
/// <summary>Implem ents the constructor for the Add-in object. Place
your initialization code within this method.</summary>
public Connect()
{
}
/// <summary>Implem ents the OnConnection method of the
IDTExtensibilit y2 interface. Receives notification that the Add-in is
being loaded.</summary>
/// <param term='applicati on'>Root object of the host
application.</param>
/// <param term='connectMo de'>Describes how the Add-in is being
loaded.</param>
/// <param term='addInInst '>Object representing this Add-in.</param>
/// <seealso class='IDTExten sibility2' />
public void OnConnection(ob ject application, ext_ConnectMode
connectMode, object addInInst, ref Array custom)
{
applicationObje ct = (DTE2)applicati on;
addInInstance = (AddIn)addInIns t;
if(connectMode == ext_ConnectMode .ext_cm_UISetup )
{
object []contextGUIDS = new object[] { };
Commands2 commands = (Commands2)appl icationObject.C ommands;
try
{
CommandBar menuBarCommandB ar;
CommandBarContr ol toolsControl;
CommandBarPopup toolsPopup;
CommandBarContr ol commandBarContr ol;
//Add a command to the Commands collection:
Command command = commands.AddNam edCommand2(addI nInstance,
"MyAddinTes t", "MyAddinTes t", "Executes the command for MyAddinTest",
true, 59, ref contextGUIDS,
(int)vsCommandS tatus.vsCommand StatusSupported +(int)vsCommand Status.vsCom
mandStatusEnabl ed, (int)vsCommandS tyle.vsCommandS tylePictAndText ,
vsCommandContro lType.vsCommand ControlTypeButt on);
String toolsMenuName;
try
{
//If you would like to move the command to a different menu,
change the word "Tools" to the
// English version of the menu. This code will take the culture,
append on the name of the menu
// then add the command to that menu. You can find a list of all
the top-level menus in the file
// CommandBar.resx .
System.Resource s.ResourceManag er resourceManager = new
System.Resource s.ResourceManag er("MyAddinTest .CommandBar",
System.Reflecti on.Assembly.Get ExecutingAssemb ly());
System.Threadin g.Thread thread =
System.Threadin g.Thread.Curren tThread;
System.Globaliz ation.CultureIn fo cultureInfo =
thread.CurrentC ulture;
toolsMenuName =
resourceManager .GetString(Stri ng.Concat(cultu reInfo.TwoLette rISOLanguage
Name, "Tools"));
}
catch(Exception )
{
//We tried to find a localized version of the word Tools, but one
was not found.
// Default to the en-US word, which may work for the current
culture.
toolsMenuName = "Tools";
}
//Place the command on the tools menu.
//Find the MenuBar command bar, which is the top-level command bar
holding all the main menu items:
menuBarCommandB ar =
((CommandBars)a pplicationObjec t.CommandBars)["MenuBar"];
//Find the Tools command bar on the MenuBar command bar:
toolsControl = menuBarCommandB ar.Controls[toolsMenuName];
toolsPopup = (CommandBarPopu p)toolsControl;
//Find the appropriate command bar on the MenuBar command bar:
commandBarContr ol =
(CommandBarCont rol)command.Add Control(toolsPo pup.CommandBar, 1);
}
catch(Exception )
{
}
}
}
/// <summary>Implem ents the OnDisconnection method of the
IDTExtensibilit y2 interface. Receives notification that the Add-in is
being unloaded.</summary>
/// <param term='disconnec tMode'>Describe s how the Add-in is being
unloaded.</param>
/// <param term='custom'>A rray of parameters that are host application
specific.</param>
/// <seealso class='IDTExten sibility2' />
public void OnDisconnection (ext_Disconnect Mode disconnectMode, ref
Array custom)
{
}
/// <summary>Implem ents the OnAddInsUpdate method of the
IDTExtensibilit y2 interface. Receives notification when the collection
of Add-ins has changed.</summary>
/// <param term='custom'>A rray of parameters that are host application
specific.</param>
/// <seealso class='IDTExten sibility2' />
public void OnAddInsUpdate( ref Array custom)
{
}
/// <summary>Implem ents the OnStartupComple te method of the
IDTExtensibilit y2 interface. Receives notification that the host
application has completed loading.</summary>
/// <param term='custom'>A rray of parameters that are host application
specific.</param>
/// <seealso class='IDTExten sibility2' />
public void OnStartupComple te(ref Array custom)
{
}
/// <summary>Implem ents the OnBeginShutdown method of the
IDTExtensibilit y2 interface. Receives notification that the host
application is being unloaded.</summary>
/// <param term='custom'>A rray of parameters that are host application
specific.</param>
/// <seealso class='IDTExten sibility2' />
public void OnBeginShutdown (ref Array custom)
{
}
/// <summary>Implem ents the QueryStatus method of the IDTCommandTarge t
interface. This is called when the command's availability is
updated</summary>
/// <param term='commandNa me'>The name of the command to determine
state for.</param>
/// <param term='neededTex t'>Text that is needed for the
command.</param>
/// <param term='status'>T he state of the command in the user
interface.</param>
/// <param term='commandTe xt'>Text requested by the neededText
parameter.</param>
/// <seealso class='Exec' />
public void QueryStatus(str ing commandName, vsCommandStatus TextWanted
neededText, ref vsCommandStatus status, ref object commandText)
{
if(neededText ==
vsCommandStatus TextWanted.vsCo mmandStatusText WantedNone)
{
if(commandName == "MyAddinTest.Co nnect.MyAddinTe st")
{
status =
(vsCommandStatu s)vsCommandStat us.vsCommandSta tusSupported|vs CommandStatu
s.vsCommandStat usEnabled;
}
}
}
/// <summary>Implem ents the Exec method of the IDTCommandTarge t
interface. This is called when the command is invoked.</summary>
/// <param term='commandNa me'>The name of the command to
execute.</param>
/// <param term='executeOp tion'>Describes how the command should be
run.</param>
/// <param term='varIn'>Pa rameters passed from the caller to the
command handler.</param>
/// <param term='varOut'>P arameters passed from the command handler to
the caller.</param>
/// <param term='handled'> Informs the caller if the command was
handled or not.</param>
/// <seealso class='Exec' />
public void Exec(string commandName, vsCommandExecOp tion
executeOption, ref object varIn, ref object varOut, ref bool handled)
{
handled = false;
if(executeOptio n == vsCommandExecOp tion.vsCommandE xecOptionDoDefa ult)
{
if(commandName == "MyAddinTest.Co nnect.MyAddinTe st")
{
handled = true;
return;
}
}
}
private DTE2 applicationObje ct;
private AddIn addInInstance;
}
}
Thanks in advance for your help.
*** Sent via Developersdex http://www.developersdex.com ***