Используйте TextDocument.ReplacePattern метод.Вы можете получить объект TextDocument из объекта ProjectItem следующим образом:
DirectCast(ProjectItem.Document.Object, TextDocument)
Полный код выглядит следующим образом:
Dim pi As ProjectItem = ...
Dim win As EnvDTE.Window = Nothing
If Not pi.IsOpen Then
win = pi.Open(Constants.vsViewKindPrimary)
'uncomment the following line if you want to show opened document
'win.Visible=True
End If
Dim td As TextDocument = DirectCast(pi.Document.Object, TextDocument)
td.ReplacePattern("abc", "def")
If Not win Is Nothing Then
win.Close(vsSaveChanges.vsSaveChangesYes)
End If