简体   繁体   English

是否可以在t4模板的注释中使用拉丁字符?

[英]Is it possible to use latin character in comments of t4 template?

I'm trying to create a portuguese comments in a t4 template of the Add Controller in my project. 我正在尝试在我的项目中添加控制器的t4模板中创建葡萄牙语注释。

The comments in t4 template: t4模板中的注释:

/// <summary>
/// Controller que trata as requisições de pesquisa, inclusão, alteração e exclusão de <#= mvcHost.ControllerName.Replace("Controller", "") #>.
/// </summary>

The problem is when i add a controller, the comments appear like this: 问题是当我添加一个控制器时,注释显示如下:

/// <summary>
/// Controller que trata as requisi��es de pesquisa, inclus�o, altera��o e exclus�o de Teste.
/// </summary>

Obs: The square is the black "? diamond" symbol. Obs:方形 是黑色的“钻石”符号。

So, how can i use latin characteres in a t4 template? 那么,我如何在t4模板中使用拉丁字符呢?

My Template: 我的模板:

<#@ template language="C#" HostSpecific="True" #>
<#@ output extension=".cs" encoding="UTF-8" #> 
<#
MvcTextTemplateHost mvcHost = (MvcTextTemplateHost)(Host);
#>
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace <#= mvcHost.Namespace #>
{
    /// <summary>
    /// Controller que trata as requisições de pesquisa, inclusão, alteração e exclusão de <#= mvcHost.ControllerName.Replace("Controller", "") #>.
    /// </summary>
    public class <#= mvcHost.ControllerName #> : Controller
    {
         // The class code
    }
}

Try to specify the encoding explicitly for the output of your templates: 尝试为模板的输出明确指定编码:

<#@ output extension=".cs" encoding="UTF-8" #>

Edit : Your code works correctly on mine (after removing the mvcHost parts). 编辑 :您的代码在我的代码上正常工作(删除mvcHost部分后)。

Try resaving both your template and its output file as UTF-8 by performing this procedure for each: 尝试通过对每个模板执行此过程将模板及其输出文件重新保存为UTF-8:

  1. Open it in Visual Studio 在Visual Studio中打开它
  2. Click File, Save As… 单击文件,另存为...
  3. Choose Save with Encoding… (see below) 选择保存编码...(见下文)
  4. Make sure that UTF-8 is selected 确保选择了UTF-8
  5. Click OK 单击确定

在此输入图像描述在此输入图像描述

Try to write the characters like this 尝试写下这样的字符

inclus&atilde;o

See a table of HTML codes here . 请在此处查看HTML代码表。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM