<#@ Import namespace= "System.Text" #> <#@ Import namespace= "System.IO" #> <#@ Import namespace= "System.Reflection" #> <#+ <summary> This class is primarily used to redefine the output position of the TT T4 so that its output position can be dynamically defined in the T4. </summary> <remarks> If you want to use this class, you need to refer to the following two files in your project C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.TextTemplating.10.0\v4.0_10.0.0.0__ B03f5f7f11d50a3a\microsoft.visualstudio.texttemplating.10.0.dll C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.TextTemplating.Interfaces.10.0\v4.0_ 10.0.0.0__b03f5f7f11d50a3a\microsoft.visualstudio.texttemplating.interfaces.10.0.dll </remarks> <example> <#@ Include file= "Classfile.ttinclude" #> using (New File (FullPath, this)) /// { Write the template code here /// } </example> public class File:System.IDisposable { private string M_filename; private string m_buffercontent; Private StringBuilder M_textbuffer; <summary> Here Texttransformation texttransformation always prompt for error 5 could not find the type or namespace name "Texttransformation" (is missing a using directive or assembly reference?) C:\xheditor-1.1.14\demo_ASP4\demo_ASP4\T4\ClassFile.ttinclude 22 33 But still can run normally, do not know why. Finally found the Microsoft.VisualStudio.TextTemplating class, in C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\ Microsoft.visualstudio.texttemplating.10.0\v4.0_10.0.0.0__b03f5f7f11d50a3a\ The Microsoft.visualstudio.texttemplating.10.0.dll file. The Texttransformation parameter defines a namespace whose type is generatedtexttransformation or texttransformation can be successfully generated because it is never possible with a randomly generated name in the TT template. T The exttransformation corresponds to. Also need to reference C:\WINDOWS\Microsoft.NET\assembly\GAC_MSIL\Microsoft.VisualStudio.TextTemplating.Interfaces.10.0\v4.0_ 10.0.0.0__b03f5f7f11d50a3a\microsoft.visualstudio.texttemplating.interfaces.10.0.dll </summary> <param name= "FileName" ></param> <param name= "Texttransformation" ></param> Public File (String fileName, Generatedtexttransformation texttransformation) Public File (String fileName, Generatedtexttransformation texttransformation) { string outputDir = null; The original code on the Internet is as follows; PropertyInfo Outputdirprop = Texttransformation.gettype (). GetProperty ("OutputDirectory"); if (Outputdirprop! = null) OutputDir = (string) outputdirprop.getvalue (texttransformation, NULL);
M_filename = (outputDir?? "") + FileName; //The parent directory to identify the error, so simply define the file name including the directory name that is done by the parent program m_fileName = fileName; PropertyInfo genEnvProp = Texttransformation.gettype (). GetProperty ("Generationenvironment", bindingflags.flattenhierarchy| bindingflags.nonpublic| BindingFlags.Instance); if (genenvprop != null) { m_textBuffer = (StringBuilder) genenvprop.getvalue (texttransformation, null); m_buffercontent = m_ Textbuffer.tostring (); m_textbuffer.remove (0, m_ Textbuffer.length); } return; } #region IDisposable Members public void Dispose () { if (m_textbuffer! = null) { using (StreamWriter StreamWriter = new StreamWriter (m_filename)) { StreamWriter.Write (M_textbuffer.tostring ()); } M_textbuffer.remove (0, m_textbuffer.length); M_textbuffer.append (m_buffercontent); } Return } #endregion } #>
|