I have an open document in Visual Studio. While my T4 template is running, it writes to the source file of the open document. When the T4 template finishes doing this, I want it to make Visual Studio reload the document in question from its source. The T4 template is triggered automatically upon saving of the document I want to refresh.
How can I do this? I've tried the "View.Refresh" command, but that says "Not Available". I've also tried closing and re-opening the document, but I get the following exception when re-opening it:
Error 3 Running transformation: System.Runtime.InteropServices.COMException (0x8004000C): User canceled out of save dialog (Exception from HRESULT: 0x8004000C (OLE_E_PROMPTSAVECANCELLED))
at EnvDTE.ProjectItem.Open(String ViewKind)
1 1
I've got:
var hostServiceProvider = (IServiceProvider)Host;
EnvDTE.DTE dte = (EnvDTE.DTE)hostServiceProvider.GetService(typeof(EnvDTE.DTE));
var projectItem = dte.ActiveDocument.ProjectItem;
var activeDocument = dte.ActiveDocument;
dte.ActiveDocument.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo); // vsSaveChanges value doesn't make a difference - still throws error
projectItem.Open(EnvDTE.Constants.vsViewKindPrimary);
User contributions licensed under CC BY-SA 3.0