对VS2003插件进行深度研究

虽然有许多人对VS 2003插件的安全性表示怀疑,但在年复一年的不断发展中,他的安全性也在不断提高。保障VS 2003插件的安全性是完全有可能的,但前提是要深入理解到底什么是VS 2003插件,及他是怎么运作的。 #t#

成都创新互联坚持“要么做到,要么别承诺”的工作理念,服务领域包括:网站建设、做网站、企业官网、英文网站、手机端网站、网站推广等服务,满足客户于互联网时代的竹山网站设计、移动媒体设计的需求,帮助企业找到有效的互联网解决方案。努力成为您成熟可靠的网络建设合作伙伴!

选择"新建"->"项目"->"其他项目"->"Visual Studio.Net外接程序"创建一个C#的外接项目。默认地,会生成一个Connet.cs文件,该文件就是当你的Visual Studio 启动时加载的东西:好了,那么具体应该怎么写代码呢,看几个代码片断吧:

 
 
  1. object []contextGUIDS = new object[] { }; 
  2. // 获得Visual Studio的Commands 
  3. Commands commands = applicationObject.Commands; 
  4. // 获得Visual Studio的菜单 
  5. _CommandBars commandBars = applicationObject.CommandBars; 
  6. try
  7. { 
  8. // 获得Visual Studio的"工具"菜单 
  9. CommandBar toolsBar = (CommandBar)commandBars["Tools"]; 
  10. foreach(CommandBarControl control in toolsBar.Controls) 
  11. { 
  12. // 如果VSX菜单已经存在就直接返回 
  13. if(control.Caption == "VSX") 
  14. { 
  15. return;
  16. } 
  17. } 
  18. // 添加VSX菜单到工具栏下面 
  19. CommandBar vsxBar = (CommandBar)commands.AddCommandBar("VSX",vsCommandBarType.vsCommandBarTypeMenu,toolsBar,1); 
  20. // 添加OutLook到VSX菜单下面 
  21. Command command = commands.AddNamedCommand(addInInstance,"OutLook","打开OutLook","在VS中嵌入OutLook",true,50,ref contextGUIDS,(int)vsCommandStatus.vsCommandStatusSupported+(int)vsCommandStatus.vsCommandStatusEnabled); 
  22. command.AddControl(vsxBar,1);
  23. } 
  24. catch(Exception ex) 
  25. { 
  26. System.Windows.Forms.MessageBox.Show(ex.ToString()); 
  27. } 

看看VS 2003插件注释就知道干了些什么。首先获取"工具"菜单,然后在"工具"上面加了个"VSX",  ***在VSX上面加了个"OutLook". F5Debug一下,会弹出Visual Studio 2003,VS 2003插件看到工具下面的VSX没有?不过还没有任何功能。这里要注意的是:command.AddControl(vsxBar,1);就将command命令和vsxBar绑定在一起了。


文章题目:对VS2003插件进行深度研究
网站链接:http://wkslyf.com/article/dhejdei.html