T4 编译转换:类型或命名空间名称“模板”;找不到

发布于 2024-11-30 15:34:34 字数 1372 浏览 3 评论 0原文

我正在尝试使用模板 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 > 创建了这些文件模板

如何创建 Xaml 文件

文件的默认结构是,但仍然无法识别模板。

<#+
// <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

How to create the Xaml file

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

与酒说心事 2024-12-07 15:34:34

你需要为此添加一堆元标签..我通常添加的标签如下:

<#@ template language="C#v3.5" hostspecific="True" debug="True" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml" #>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Text" #> 
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections.Generic" #>

这里的Template指的是什么..我认为这是一个其名称空间找不到的类..你为什么延伸那个?如果您需要它,请提供一个完全限定的名称空间。

you need to add a bunch of meta tags for that.. the ones that I usually add are as follows:

<#@ template language="C#v3.5" hostspecific="True" debug="True" #>
<#@ output extension=".cs" #>
<#@ assembly name="System.Core" #>
<#@ assembly name="System.Xml" #>
<#@ import namespace="System.Xml" #>
<#@ import namespace="System.Text" #> 
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Collections.Generic" #>

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..

要走干脆点 2024-12-07 15:34:34

“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'.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文