I have a T4 that is generating multiple .html files.
After creating them all it then deletes them. I have seen the files create in both explorer and VS2010 ultimate (the solution explorer bar grows and then shrinks right back).
I have modified Oleg Synch's updated multiple output code as follows:
ProjectItem GetTemplateItem(DTE dte)
{
return // Find the .tt file's ProjectItem
dte.Solution.FindProjectItem(Host.TemplateFile);
}
void SaveOutput(string outputFileName,List<string> savedOutputs)
{
string templateDirectory = Path.GetDirectoryName(Host.TemplateFile);
string outputFilePath = Path.Combine(templateDirectory, outputFileName);
var text= this.GenerationEnvironment.ToString();
WriteDiagnosticLine("Writing:"+text.Length+" characters");
File.WriteAllText(outputFilePath,text);
this.GenerationEnvironment = new StringBuilder();
ProjectItem templateProjectItem = GetTemplateItem(Dte);
templateProjectItem.ProjectItems.AddFromFile(outputFilePath);
savedOutputs.Add(outputFileName);
WriteDiagnosticLine("Added:"+outputFileName);
}
void WriteDiagnosticLine(string line)
{
System.Diagnostics.Debug.WriteLine(line);
}
the initial code to set Dte
is
bool AlwaysKeepTemplateDirty = true;
DTE Dte;
var serviceProvider = Host as开发者_如何学JAVA IServiceProvider;
if (serviceProvider != null) {
Dte = serviceProvider.GetService(typeof(SDTE)) as DTE;
}
// Fail if we couldn't get the DTE. This can happen when trying to run in TextTransform.exe
if (Dte == null) {
throw new Exception("T4Generator can only execute through the Visual Studio host");
}
it happens whether I make a change and hit save, or right click the .tt file and say run custom tool.
In case it's helpful here's my tt declaration:
<#@ template language="C#" hostspecific="True" debug="True" #>
<#@ output extension=".txt" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml" #>
<#@ assembly name="Microsoft.VisualStudio.Shell.Interop.8.0" #>
<#@ assembly name="EnvDTE" #>
<#@ assembly name="EnvDTE80" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Text.RegularExpressions" #>
<#@ import namespace="Microsoft.VisualStudio.Shell.Interop" #>
<#@ import namespace="EnvDTE" #>
<#@ import namespace="EnvDTE80" #>
removing
<#@ include file="T4Toolbox.tt" #>
seems to have solved it. pretty bizarre.
精彩评论