T4 编译转换:类型或命名空间名称“模板”;找不到
我正在尝试使用模板 T4 生成 Xaml 文件并像这样定义可重用文件 Xaml.tt
<#@ template language="C#" hostspecific="True" debug="True" #>
<#@ assembly name="System.Xml.dll" #>
<#@ assembly name="System.Xml.Linq.dll" #>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Xml.Linq" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
<#+
public class Xaml : Template
{
public override string TransformText()
{
#>
// Xaml Content
<#+
return this.GenerationEnvironment.ToString(); }
}
#>
但我有一个错误:找不到模板命名空间,有人知道吗?还是同样的错误!!令人沮丧!
错误:T4 编译转换:找不到类型或命名空间名称“模板”(您是否缺少 using 指令或程序集引用?)
我在生成器中遇到相同的错误。
我通过添加新项目 Code Generation > 创建了这些文件模板
文件的默认结构是,但仍然无法识别模板。
<#+
// <copyright file="Template1.tt" company="HP">
// Copyright © HP. All Rights Reserved.
// </copyright>
public class Template1 : Template
{
public override string TransformText()
{
return this.GenerationEnvironment.ToString();
}
}
#>
我缺少的是程序集引用还是指令?
顺便说一句,我也在使用 T4 Toolbox
I am trying to generate a Xaml file using Template T4 and defining a reusable file Xaml.tt like this
<#@ template language="C#" hostspecific="True" debug="True" #>
<#@ assembly name="System.Xml.dll" #>
<#@ assembly name="System.Xml.Linq.dll" #>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Xml.Linq" #>
<#@ import namespace="System.IO" #>
<#@ import namespace="System.Collections" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ import namespace="Microsoft.VisualStudio.TextTemplating" #>
<#+
public class Xaml : Template
{
public override string TransformText()
{
#>
// Xaml Content
<#+
return this.GenerationEnvironment.ToString(); }
}
#>
But i have an error: the template namespace couldn't be found, any one has idea about that ? Still same error !! frustrating !!
Error: T4 Compiling transformation: The type or namespace name 'Template' could not be found (are you missing a using directive or an assembly reference ?)
I am getting the same error for Generator.
I created these file by adding new item Code Generation > Template
The default structure of the file is and still not recognizing Template.
<#+
// <copyright file="Template1.tt" company="HP">
// Copyright © HP. All Rights Reserved.
// </copyright>
public class Template1 : Template
{
public override string TransformText()
{
return this.GenerationEnvironment.ToString();
}
}
#>
Is the an assembly reference or a directive i am missing ?
BTW i am using T4 Toolbox also
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
你需要为此添加一堆元标签..我通常添加的标签如下:
这里的Template指的是什么..我认为这是一个其名称空间找不到的类..你为什么延伸那个?如果您需要它,请提供一个完全限定的名称空间。
you need to add a bunch of meta tags for that.. the ones that I usually add are as follows:
what is Template here referring to.. that is the class whose namespace it is not able to find I think.. Why are you extending that? if you need it give a fully qualified namespace for the same..
“Template”可能是 T4Toolbox 中的一个类,因此您需要使用程序集和导入指令来引用它。
标准 VS 基类是“TextTransformation”。
'Template' is probably a class from T4Toolbox, so you'd need to reference that with an assembly and import directive.
The standard VS base class is 'TextTransformation'.