开发VS2008 AddIn 入门Sample

本文主要介绍的是VS2008插件开发

环境要求:VS2008;.Net3.5

目标:开发插件功能为“在VS中创建文本文档,并在文本开头输入//This code was created For Testing”

 

1,Create new project(Visual Studio Add-In)

 2010060520403556.png

2,按照wizard一步一步操作:

选择使用C#编写Addin

选择在.NET IDE 和Macro IDE中都可以使用AddIn

输入name和description

2010060520451978.png

选中确定需要AddIn在Tool中显示

2010060520480636.png

选择需要About Information

summary

 2010060520511183.png

 

Finish 生成solution

2010060520534571.png

 

此时debug(F5)这个solution,会跳出另外一个VS2008窗口,并且你会发现在Tool工具栏下有^-^笑脸:

2010060520583253.png

 

3 将Connect类中的Exec方法改为:

 

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
public void Exec( string commandName, EnvDTE.vsCommandExecOption executeOption, ref object varIn, ref object varOut, ref bool handled)
{
handled
= false ;
if ( executeOption ==
EnvDTE.vsCommandExecOption.vsCommandExecOptionDoDefault)
{
if (commandName == " CopyrRightAddIn.Connect.CopyrRightAddIn " )
{
// Add your command execution here
CreateNewFile();
handled
= true ;
return ;
}
}
}

 

4 在connect类中增加方法:

 

ContractedBlock.gif ExpandedBlockStart.gif 代码
 
   
public void CreateNewFile()
{
// Create a new text document.
_applicationObject.ItemOperations.NewFile( " General\\Text File " , "" ,
Constants.vsViewKindCode);
// Get a handle to the new document.
TextDocument objTextDoc = (TextDocument)_applicationObject.ActiveDocument.Object( " TextDocument " );
EditPoint objEditPoint
= (EditPoint)objTextDoc.StartPoint.CreateEditPoint();
// Create an EditPoint and add some text.
objEditPoint.Insert( " //This code was created For Testing " );
}

 

5 build and debug

当按下Tool中的AddIn工具时候会发现文本已经创建,并且文字也已经加入到文本中:

2010060521065930.png

 

至此,VS AddIn开发完成。

 

PS:本文示例参考:http://www.c-sharpcorner.com/uploadfile/mgold/addins11292005015631am/addins.aspx

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值