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?
As per MSDN (https://msdn.microsoft.com/en-us/library/gg586943.aspx), to do this in the output
element, you need to say encoding="utf-8"
, so with the hyphen (the letter casing does not appear to make a difference).
The <#@output
directive applies to the direct output of the T4 file.
You need to alter your template so its output is UTF8
public class DALTable : Template
{
public DALTable()
{
Output.Encoding = System.Text.Encoding.UTF8;
}
public override string TransformText()
...
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With