As usual when dealing with the VS SDK, the answer is a bit obscure. The way that I solved it (right or wrong) is to make the ProjectItem instance the active document and then use the DTE2.ActiveDocument.Selection
property to get the text. This is accomplished via the following:
if (!projectItem.IsOpen)
projectItem.Open(@"{7651A701-06E5-11D1-8EBD-00A0C90F26EA}").Document.Activate(); //EnvDTE.Constants.vsViewKindCode
TextSelection selection = _vsApp.ActiveDocument.Selection;
selection.SelectAll();
string text = selection.Text;
selection.Delete();
//Do replacements
text = ReplaceTemplateValues(text, replacements);
selection.Insert(text);
Is there a better way?