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)中有错误”)
  • 相关阅读:
    maven安装
    删掉centos原有的openjdk并安装sun jdk
    搭建私有仓库Harbor
    什么是Docker
    总结docker常用命令
    MySQL如何修改密码
    VMware vSphere
    安装Esxi 6.5
    Linux安装python3.6
    提高Linux运维效率的30个命令行常用快捷键
  • 原文地址:https://www.cnblogs.com/mxw09/p/1991816.html
Copyright © 2011-2022 走看看