I've got a T4 template (also using the T4Toolbox) that scans a folder for files, then processes them and kicks out .cs files. When the processing from the template is done, I want to format them with VS. I've got this far:
IServiceProvider hostServiceProvider = (IServiceProvider)Host;
EnvDTE.DTE dte = (EnvDTE.DTE)hostServiceProvider.GetService(typeof(EnvDTE.DTE));
dte.ExecuteCommand("File.OpenFile", newFile); // newFile is full path to file
dte.ExecuteCommand("Edit.FormatDocument", string.Empty);
This only works if the file is open and I don't know how to save the changes. Any pointers?