【问题标题】:Can not use my custom class in T4 template无法在 T4 模板中使用我的自定义类
【发布时间】:2012-07-11 00:42:59
【问题描述】:

我研究了 google 和 SO,但找不到答案。

我查看了以下帖子,但没有成功。

Use class inside a T4 template

在我的 T4 模板中,我尝试使用自定义类 ResourceManager 中定义的 AddControls 方法,但出现以下错误。

编译转换:找不到类型或命名空间名称“WebApplication1”(您是否缺少 using 指令或程序集引用?)

请帮帮我。

namespace WebApplication1
{
    public static class ResourceManager
    {

        public static void AddControls(List<string> controlList)
        {
            controlList.Add("Label1");
            controlList.Add("Button1");
        }
     }
}

我的 T4 模板代码如下:

<#@ template debug="false" hostspecific="true" language="C#" #>
<#@ output extension=".txt" #>

<#@ assembly name="$(TargetPath)" #>
<#@ import namespace="WebApplication1" #>
<#@ import namespace="System.Collections.Generic" #>


<#
    List<String> controlList = new List<String>();

    ResourceManager.AddControls(controlList);

    foreach (string str in controlList)
    {

        string propName= str;
#>
    My control is  <#=            propName #>

<#
    }

#>

【问题讨论】:

    标签: c# t4


    【解决方案1】:

    构建包含命名空间WebApplication1 的项目并再次尝试保存模板。 使用您的代码对我有用。

    【讨论】:

      猜你喜欢
      • 2012-04-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2020-07-20
      • 1970-01-01
      • 2014-12-26
      相关资源
      最近更新 更多