projects As Array = applicationObject.ActiveSolutionProjects() ’开发环境下打开的所有项目
Dim theProject As EnvDTE.Project ‘定一个Project,指示当前Project
If (projects.Length > 0) Then ‘如过当前没有打开project,Pass什么也不错。
theProject = projects.GetValue(0) ‘ 获得当前Project
Dim p As ProjectItem
For Each p In theProject.ProjectItems ‘ 对改project下面的所有.vb文件添加注释
If p.Name.Substring(p.Name.Length - 3, 3) = ".vb" Then
Dim theWindow As EnvDTE.Window
theWindow = p.Open(Constants.vsViewKindCode)
Dim objTextDoc As TextDocument = theWindow.Document.Object("TextDocument")
Dim objEditPoint As EditPoint = objTextDoc.StartPoint.CreateEditPoint
objEditPoint.Insert(strRemark)
Dim strFileName As String = p.FileNames(0)
p.SaveAs(strFileName)
End If
Next
End If
Catch ee As Exception
MsgBox(ee.ToString)
End Try
End Sub
当用户调用了我们写的外接程序的时候,会有一个Exec过程,根据传递给它的参数来执行不同的过程,我们加入自己的过程:
Public Sub Exec(ByVal cmdName As String, ByVal executeOption As vsCommandExecOption, ByRef varIn As Object, ByRef varOut As Object, ByRef handled As Boolean) Implements IDTCommandTarget.Exec
handled = False
If (executeOption = vsCommandExecOption.vsCommandExecOptionDoDefault) Then
If cmdName = "CopyRightAddin.Connect.CopyRightAddin" Then
CreateCopyRightFileForAllVbfiles()
handled = True
Exit Sub
End If
End If
End Sub
Ok,到现在为止,运行F5,就可以看到实际效果了。是不是很简单?
补充
1、 发布的时候,我们可以制作一个Setup项目,安装一下就可以了。
2、 编译后,项目所在的目录下会生成一个注册表文件。外接程序出错的时候,会提示你是不是要移除这个外接程序,选择是会导致工具菜单中不出现这个外接程序,点击这个注册表文件就可以恢复了。
3、 这个只是一个简单的例子,只供初学者学习。
上一页 [1] [2] 没有相关教程
|