對(duì)VS2003插件進(jìn)行深度研究
雖然有許多人對(duì)VS 2003插件的安全性表示懷疑,但在年復(fù)一年的不斷發(fā)展中,他的安全性也在不斷提高。保障VS 2003插件的安全性是完全有可能的,但前提是要深入理解到底什么是VS 2003插件,及他是怎么運(yùn)作的。 #t#
選擇"新建"->"項(xiàng)目"->"其他項(xiàng)目"->"Visual Studio.Net外接程序"創(chuàng)建一個(gè)C#的外接項(xiàng)目。默認(rèn)地,會(huì)生成一個(gè)Connet.cs文件,該文件就是當(dāng)你的Visual Studio 啟動(dòng)時(shí)加載的東西:好了,那么具體應(yīng)該怎么寫代碼呢,看幾個(gè)代碼片斷吧:
- object []contextGUIDS = new object[] { };
- // 獲得Visual Studio的Commands
- Commands commands = applicationObject.Commands;
- // 獲得Visual Studio的菜單
- _CommandBars commandBars = applicationObject.CommandBars;
- try
- {
- // 獲得Visual Studio的"工具"菜單
- CommandBar toolsBar = (CommandBar)commandBars["Tools"];
- foreach(CommandBarControl control in toolsBar.Controls)
- {
- // 如果VSX菜單已經(jīng)存在就直接返回
- if(control.Caption == "VSX")
- {
- return;
- }
- }
- // 添加VSX菜單到工具欄下面
- CommandBar vsxBar = (CommandBar)commands.AddCommandBar("VSX",vsCommandBarType.vsCommandBarTypeMenu,toolsBar,1);
- // 添加OutLook到VSX菜單下面
- Command command = commands.AddNamedCommand(addInInstance,"OutLook","打開OutLook","在VS中嵌入OutLook",true,50,ref contextGUIDS,(int)vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatusEnabled);
- command.AddControl(vsxBar,1);
- }
- catch(Exception ex)
- {
- System.Windows.Forms.MessageBox.Show(ex.ToString());
- }
看看VS 2003插件注釋就知道干了些什么。首先獲取"工具"菜單,然后在"工具"上面加了個(gè)"VSX", ***在VSX上面加了個(gè)"OutLook". F5Debug一下,會(huì)彈出Visual Studio 2003,VS 2003插件看到工具下面的VSX沒有?不過還沒有任何功能。這里要注意的是:command.AddControl(vsxBar,1);就將command命令和vsxBar綁定在一起了。

















