Addin工具的菜单没有出现在IDE中
其实向导已生成了主要的代码,代码如下
public void OnConnection(object application, Extensibility.ext_ConnectMode connectMode)
{
applicationObject = (_DTE)application;
addInInstance = (AddIn)addInInst;
if(connectMode == Extensibility.ext_ConnectMode.ext_cm_UISetup)
{
object []contextGUIDS = new object[] { };
Commands commands = applicationObject.Commands;
_CommandBars commandBars = applicationObject.CommandBars;
try
{
Command command = commands.AddNamedCommand(addInInstance, ); //添加到项目中
CommandBar barPro = (CommandBar)commandBars["Project"];
command.AddControl(barPro, 1);
//添加到项目菜单中
CommandBar barItem = (CommandBar)commandBars["Item"];
command.AddControl(barItem, 1);
}
catch(System.Exception e)
{
applicationObject.StatusBar.Text = e.Message;
}
}
}
{
applicationObject = (_DTE)application;
addInInstance = (AddIn)addInInst;
if(connectMode == Extensibility.ext_ConnectMode.ext_cm_UISetup)
{
object []contextGUIDS = new object[] { };
Commands commands = applicationObject.Commands;
_CommandBars commandBars = applicationObject.CommandBars;
try
{
Command command = commands.AddNamedCommand(addInInstance, ); //添加到项目中
CommandBar barPro = (CommandBar)commandBars["Project"];
command.AddControl(barPro, 1);
//添加到项目菜单中
CommandBar barItem = (CommandBar)commandBars["Item"];
command.AddControl(barItem, 1);
}
catch(System.Exception e)
{
applicationObject.StatusBar.Text = e.Message;
}
}
}
if(connectMode == Extensibility.ext_ConnectMode.ext_cm_UISetup)基本上只会得到一次机会,执行过后,你的机器就基本上不会再有connectMode == Extensibility.ext_ConnectMode.ext_cm_UISetup。如果我们在第一次执行的时候我们自己的代码出现了错误,菜单就不会出现。而以后里面的代码就没有执行的机会了。
其实向导已生成了注册表的合并文件在项目目录下了。一般文件名是ReCreateCommands.reg,将该文件合并到系统注册表中,上面添加菜单的代码又得到一次运行的机会。当然用户也可以自己去修改注册表
[HKEY_CURRENT_USER\SOFTWARE\Microsoft\VisualStudio\7.1\PreloadAddinState]
"YourAddin.Connect"=dword:1
"YourAddin.Connect"=dword:1