【发布时间】:2012-07-29 03:17:04
【问题描述】:
我使用 Oleg Sych 所说的 Template - Generator 架构师通过 T4 生成一些代码,但是使用 Unicode 存在一些问题,在生成所有显示为问号的波斯字符后,我有一些波斯字符。
这是我的文件:模板:
<#@ 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
}
生成器:
<#@ 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");
}
}
还有脚本:
<#@ 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();
#>
正如 Oleg Sych 所说,我在输出中设置了 Unicode,正如您在这一行中看到的那样:<#@ output extension=".cs" encoding="UTF8" #> 我也将这 3 个文件都保存为 Unicode utf8
但问题依然存在,问题出在哪里?还有什么事情是我必须做的?
更新
我发现我新生成的文件(DAL.cs)没有一个没有保存为UTF8,所有这些文件都通过ANSI 编码保存。通过UTF8编码保存我的文件需要做什么?
【问题讨论】:
-
在
<#@ output extension=".log" encoding="UTF-8" #>,UTF8应该是UTF-8
标签: c# visual-studio-2010 templates unicode t4