I use Template – Generator architect as Oleg Sych said to generate some code by T4, but there is some problems in using Unicode, I have some Persian characters after generate all of the Persian characters displayed as question mark.
This is my files: Template:
<#@ assembly name="Microsoft.SqlServer.ConnectionInfo" #>
<#@ assembly name="Microsoft.SqlServer.Smo" #>
<#@ assembly name="Microsoft.SqlServer.Management.Sdk.Sfc" #>
<#@ import namespace="Microsoft.SqlServer.Management.Smo" #>
<#@ import namespace="System.Collections.Generic" #>
<#+
public class DALTable : Template
{
public override string TransformText()
{
//My Template
}
Generator:
<#@ assembly name="Microsoft.SqlServer.ConnectionInfo" #>
<#@ assembly name="Microsoft.SqlServer.Smo" #>
<#@ assembly name="Microsoft.SqlServer.Management.Sdk.Sfc" #>
<#@ include file="DALTable.tt" #>
<#+
public class TableDALGenerator : Generator
{
public DALTable DALTableTemplate = new DALTable();
protected override void RunCore()
{
this.DALTableTemplate.Table = table;
this.DALTableTemplate.RenderToFile("DAL.cs");
}
}
And Script:
<#@ template language="C#v4" hostspecific="True" debug="True" #>
<#@ assembly name="System.Core" #>
<#@ output extension=".cs" encoding="UTF8" #>
<#@ include file="T4Toolbox.tt" #>
<#@ include file="TableDALGenerator.tt" #>
<#
TableDALGenerator TableDALGen = new TableDALGenerator();
//Pass Parameters
TableORMGen.Run();
#>
As Oleg Sych said I set Unicode in output as you see in this line: <#@ output extension=".cs" encoding="UTF8" #> also I save as all of this 3 files with Unicode utf8
but the problem still remain, where is the problem? what another thing remain that I must do that?
Update
I found that none of my new generated files (DAL.cs) not saved as UTF8 all of them saved by ANSI encoding. what need to do to save my files by UTF8 encoding?
The
<#@outputdirective applies to the direct output of the T4 file.You need to alter your template so its output is UTF8