In Codesmith To generateCodeFile output to the file, you need to inherit from your own template Outputfilecodetemplate Class.
<% @ Codetemplate Language = " C # " Targetlanguage = " C # " Inherits = " Outputfilecodetemplate " Description = " Build M access code. " %>
<% @ Assembly name = " Codesmith. basetemplates " %>
OutputfilecodetemplateWe mainly do two things:
1. It addsOutputfileTo your template, this attribute requires you to select a file;
2 The template reloads the method. Onpostrender () , In Codesmith After the code is generated, write the corresponding content to the specified file.
If you want to customize Outputfile The "save file" dialog box pops up in properties. You need to reload it in your template Outputfile Attribute. For example, you want to select . CS To save the generated code, add the following code to your template:
< Script runat = " Template " >
// Override the outputfile property and assign our specific settings to it.
[Filedialog (filedialogtype. Save, title = " Select output file " , Filter = " C # files (*. CS) | *. CS " , Defaultextension = " . CS " )]
Public Override String Outputfile
{
Get {Return Base. Outputfile ;}
Set {Base. Outputfile=Value ;}
}
</ Script >