I am using a T4 template with T4 Toolbox within Visual Studio 2012 to generate about 100 files and add them to the project. I have two templates, one of which outputs a .cs file, the other outputs a corresponding .designer.cs. Naming it this way seems to automatically assign the <DependentUpon>
property in the .csproj file. (Is this a VS2012 feature? Or T4Toolbox?)
The generation itself only takes a couple of seconds. However, there is a long pause of about 3 minutes where Visual Studio is hogging the CPU during this time. Is there any way I can avoid this long pause?
My template looks something like this
<#@ template language="C#" debug="false" #>
<#@ output extension="txt" #>
<#@ assembly name="System.Core" #>
// imports ommitted...
<#@ assembly name="T4Toolbox.dll"#>
<#@ include file="T4Toolbox.tt" #>
<#
// about 100 files
var filenames = MyHelper.GetFilenamesToProcess();
// for each input file, generate two output files
foreach(string filename in filenames)
{
var mainPartTemplate = new MainPartTemplate();
mainPartTemplate.RenderToFile(fileName + ".cs");
var designerPartTemplate = new DesignerPartTemplate();
designerPartTemplate.RenderToFile(fileName + ".designer.cs");
}
// Beep so I can hear when the script finishes.
Console.Beep();
// It takes about two seconds to get here, then there is a 3 minute wait while
// Visual Studio is unresponsive.
#>
If I change the extension .designer.cs to anything else then there is no delay after the script runs, but the <DependentUpon>
tag is then missing so the files are separated in the solution explorer and the View in Designer option is not available when right-clicking.