T4模板包含XML结果的解析错误模板、错误、结果、XML

由网友(人美性子野)分享简介:我已经创建T4模板我的网站和Windows项目的配置文件。我可以成功地生成主web.config中,和所有的configs为其他环境,即web.ci.config,etc..However,在我的主人TT文件,我无法摆脱的误区,如:I have created T4 Templates for the config...

我已经创建T4模板我的网站和Windows项目的配置文件。我可以成功地生成主web.config中,和所有的configs为其他环境,即web.ci.config,etc..However,在我的主人TT文件,我无法摆脱的误区,如:

I have created T4 Templates for the config files of my web and windows projects. I can successfully generate master web.config, and all configs for other environments, i.e. web.ci.config, etc..However, I could not get rid of the errors on my master tt files, such as :

  字符'#',十六进制。值0x23是XML名非法。   字符'&LT;',十六进制值0x3C符号是非法的XML属性值。   在意外的XML声明。 XML声明必须是文件中的第一个节点,也没有空白字符被允许在它之前出现。    Character '#', hexadecimal value 0x23 is illegal in an XML name. Character '<', hexadecimal value 0x3c is illegal in XML attribute values. Unexpected XML declaration. The XML declaration must be the first node in the document and no white space characters are allowed to appear before it.

我应该缺少一个XML架构或参考,但什么?

I should be missing a xml schema or a reference, but what?

我的文件是这样的:

<#@ template debug="true" hostSpecific="true" #>
<#@ output extension= ".config" #>  
<?xml version="1.0" encoding="utf-8"?>
<configuration>
...  
    <add key="FileUploadFolder" value="<#= this.FileUpload #>" /> 
...
</configuration>
<#+ 
   string FileUpload="\serverfolder";
#>

这里是截图

推荐答案

在这里同样的问题。我的工作围绕它通过替换在 .TT 文件中的行

Same problem here. I worked around it by replacing in the .tt file the line

<?xml version="1.0" encoding="utf-8"?>

<# WriteLine("<?xml version="1.0" encoding="utf-8"?>"); #>

一旦VS是困惑的模板文件的XML格式,它似乎要坚持这混乱 - 甚至编辑像上面并重新启动后。围绕着唯一的办法似乎是从项目中删除现有的 .TT 文件,并从头开始重新创建它。

Once VS is confused about the XML format of the template file, it seems to persist in that confusion -- even after editing like above and a restart. The only way around that seems to be to delete the existing .tt file from your project and re-create it from scratch.

通过这一变化, .TT 文件没有一个&LT;?XML&GT; 标记了所以VS不会认为这是一个XML文件。它无视一切的文本字符串中。你的整个模板现在看起来是这样的:

With this change, the .tt file does not have a <?xml?> tag anymore so VS does not consider it an XML file. It ignores everything inside the literal string. Your whole template now looks like this:

<#@ template debug="true" hostSpecific="true" #>
<#@ output extension= ".config" #>  
<# WriteLine("<?xml version="1.0" encoding="utf-8"?>"); #>
<configuration>
...  
    <add key="FileUploadFolder" value="<#= this.FileUpload #>" /> 
...
</configuration>
<#+ 
    string FileUpload="\serverfolder";
#>
阅读全文

相关推荐

最新文章