CodeSmith生成的文件格式是UTF-8 with BOM,如何改成UTF-8 without BOM?

The files format which CodeSmith generated are UTF-8 with BOM, how to change it to UTF-8 without BOM?

我最近在试用CodeSmith Generator Professional 7.1.0,有一件事一直困扰着我,每次我用它生成一些文件时,文件格式总是UTF-8带BOM,我真的需要文件格式是没有 BOM 的 UTF-8,但我找不到任何设置或配置来执行此操作,我在 Google 上搜索了几天,但没有得到任何有用的信息。任何想法将不胜感激!

下面是模板代码:

<% @CodeTemplate Language = "C#"
TargetLanguage = "C#"
ResponseEncoding = "UTF-8"
Description = "Generates a very simple business object." %>
  <% @Property Name = "SourceDatabase"
Type = "SchemaExplorer.DatabaseSchema"
DeepLoad = "True"
Optional = "False"
Category = "01. Getting Started - Required"
Description = "Database that the tables views, and stored procedures should be based on. IMPORTANT!!! If SourceTables and SourceViews are left blank, the Entire Database will then be generated." %>
  <% @Property Name = "SourceTable"
Type = "SchemaExplorer.TableSchema"
Category = "Context"
Description = "Table that the object is based on." %>
  <% @Assembly Name = "SchemaExplorer" %>
  <% @Assembly Name = "System.Data" %>
  <% @Import Namespace = "SchemaExplorer" %>
  <% @Import Namespace = "System.Data" %>
  <% @Assembly Name = "MySql.Data" %>
  <% @Import NameSpace = "MySql.Data.MySqlClient" %>
  <? php

//Language File for <%= SourceTable.Name.ToLower() %> [EN]
define('LANG_<% = SourceTable.Name.ToUpper() %>', '<% = GetTablebPerfix(SourceTable.Name) %> List'); <%
for (int i = 0; i < SourceTable.NonForeignKeyColumns.Count; i++) { %>
  define('LANG_<% = SourceTable.NonForeignKeyColumns[i].Name.ToUpper() %>', '<% = GetColumnComment(SourceTable.Columns[i].Name) %>'); <%
} %>
?>

< script runat = "template" >
  public string GetColumnComment(string _columnname) {
    DataSet _auditTables = new DataSet();
    string ConnectionString = "server=localhost; user id = root; password = xxxxx; database =" + SourceDatabase + "";
    MySqlConnection conn = new MySqlConnection(ConnectionString);
    MySqlDataAdapter adapter = new MySqlDataAdapter(conn.CreateCommand());
    adapter.SelectCommand.CommandText = "select * from information_schema.columns where (table_schema='" + SourceDatabase + "') and (table_name='" + SourceTable + "') and (column_name='" + _columnname + "')";
    adapter.Fill(_auditTables);
    string en_comment = "";
    if (_auditTables.Tables.Count > 0) {
      DataTable dt = _auditTables.Tables[0];
      if (dt.Rows.Count > 0) {
        string comments = dt.Rows[0][dt.Columns.Count - 1].ToString();
        if (comments.IndexOf('/') == -1) {
          en_comment = comments;
        } else {
          en_comment = comments.Split('/')[1];
        }
      }
    }

    conn.Close();
    return en_comment;

  }

public string GetTablebPerfix(string _tablename) {
  string _tbnamewhtprefix = "";
  if (_tablename.IndexOf('_') == -1) {
    _tbnamewhtprefix = _tablename;
  } else {
    _tbnamewhtprefix = _tablename.Split('_')[1];
  }

  return System.Threading.Thread.CurrentThread.CurrentCulture.TextInfo.ToTitleCase(_tbnamewhtprefix);
} < /script>

您可以设置两个属性来控制此 属性 代码模板指令 EncodingResponseEncoding 属性将控制模板的呈现和保存方式。

https://codesmith.atlassian.net/wiki/display/Generator/The+CodeTemplate+Directive