zoukankan      html  css  js  c++  java
  • CodeSmith4.1在控制台根据模板生成文件

    class.cst内容如下:
    <%@ CodeTemplate Language="C#" TargetLanguage="C#" Debug="False" ResponseEncoding="utf-8"%>
    <%@ Assembly Name="System.Windows.Forms" %>
    <%@ Import Namespace="System.Windows.Forms" %>

    <script runat="template">
        string PageName="wq";
        void ExecTemplate()
        {
            CodeTemplateCompiler  temCompiler=new CodeTemplateCompiler (this.CodeTemplateInfo.DirectoryName+"First.cst");          
            temCompiler.Compile();
            CodeTemplate tem =        temCompiler.CreateInstance();
            tem.SetProperty("Age",66);
            
            tem.Render(Response);
        }
        
        //注意,这个方法在控制台调用模板生成的时候,会将生成的文件保存为以下方法返回的路径。如果没有重写此方法,则返回模板同目录同名不同后缀名的文件(这个例子里没有重写此方法,则在class.cst的同级目录生成class.cs文件)
        public override string GetFileName()
        {
            return @"C:\2.cs";   
        }
    </script>
    using System;
    using System.Data;
    using System.Configuration;
    using System.Collections;
    using System.Web;
    using System.Web.Security;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using System.Web.UI.WebControls.WebParts;
    using System.Web.UI.HtmlControls;
    using Lexun.FoolDay.Output.Pages;

    public partial class <%= PageName %> : <%= "C"+PageName %>
    {
        
    }


    class.csp如下:
    <?xml version="1.0"?>
    <codeSmith xmlns="http://www.codesmithtools.com/schema/csp.xsd">
      <propertySets>
        <propertySet template="class.cst">      
        </propertySet>
      </propertySets>
    </codeSmith>

    在CodeSmith控制台输入如下指令:cs "C:\Documents and Settings\Administrator\桌面\class.csp"
    则会在C盘生成一个class.cs

    注意:在CodeSmith4.1中,控制台只能根据csp文件来生成文件(csp存储模板的位置,参数等信息),而不能直接根据cst文件来生成文件(使用cst文件,会爆这个错误:“xml文档(1,2)中有错误”)
  • 相关阅读:
    12-29 批量删除
    12-29 注册审核
    12-25造数据库面向对象
    12-23 会话保持
    2016-12-19 php修改数据库数据
    12-18数据访问
    12-16php测试题
    1027 制作表格
    1027 超链接
    1027 HTML
  • 原文地址:https://www.cnblogs.com/mxw09/p/1991816.html
Copyright © 2011-2022 走看看