I'm recently trialling CodeSmith Generator Professional 7.1.0, There is one thing keep troubling me, every time when I generating some files with it, the file format always is UTF-8 with BOM, I really need the file format is UTF-8 without BOM, But I can not find any settings or configurations to do this, I'm searching on Google for days and got nothing useful. Any thoughts will be appreciated!
Here is template code below:
<% @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>
There are two properties you can set to control this property on the Code Template directive Encoding
and ResponseEncoding
attributes will control how the template is rendered and saved.
https://codesmith.atlassian.net/wiki/display/Generator/The+CodeTemplate+Directive