/// <summary> /// Initializes an TemplateFileManager Instance with the /// TextTransformation (T4 generated class) that is currently running /// </summary> private TemplateFileManager(object textTransformation) { if (textTransformation == null) { throw new ArgumentNullException("textTransformation"); } _textTransformation = DynamicTextTransformation2.Create(textTransformation); _generationEnvironment = _textTransformation.GenerationEnvironment; var hostServiceProvider = _textTransformation.Host.AsIServiceProvider(); if (hostServiceProvider == null) { throw new ArgumentNullException("Could not obtain hostServiceProvider"); } dte = (EnvDTE.DTE)hostServiceProvider.GetService(typeof(EnvDTE.DTE)); if (dte == null) { throw new ArgumentNullException("Could not obtain DTE from host"); } this.templateProjectItem = dte.Solution.FindProjectItem(_textTransformation.Host.TemplateFile); this.CanOverrideExistingFile = true; this.IsAutoIndentEnabled = false; this.Encoding = System.Text.Encoding.UTF8; checkOutAction = fileName => dte.SourceControl.CheckOutItem(fileName); projectSyncAction = keepFileNames => ProjectSync(templateProjectItem, keepFileNames); }
/// <summary> /// Creates files with VS sync /// </summary> public static TemplateFileManager Create(object textTransformation) { DynamicTextTransformation2 transformation = DynamicTextTransformation2.Create(textTransformation); IDynamicHost2 host = transformation.Host; return(new TemplateFileManager(transformation)); }