In CodeSmith, to output the generated code file to a file, you need to inherit the OutputFileCodeTemplate class from your own template. % @ CodeTemplateLanguageC # targetreceivagec # InheritsOutputFileCodeTemplateDescriptionBuildcustomaccesscode. %
In CodeSmith, to output the generated code file to a file, you need to inherit the OutputFileCodeTemplate class from your own template. % @ CodeTemplateLanguage = "C #" TargetLanguage = "C #" Inherits = "OutputFileCodeTemplate" Description = "Buildcustomaccesscode." %
InCodeSmithTo output the generated code file to the file, you need to inherit from your own templateOutputFileCodeTemplateClass.
<%@ 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;
2The template reloads the method.OnPostRender (), InCodeSmithAfter the code is generated, write the corresponding content to the specified file.
If you want to customizeOutputFileThe "save file" dialog box pops up in properties. You need to reload it in your templateOutputFileAttribute. For example, you want to select. CsTo 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 StringOutputFile
{
Get {Return Base. OutputFile ;}
Set {Base. OutputFile=Value ;}
}
Script>