2012-07-11 95 views
5

我已经研究过Google和SO并找不到答案。不能在T4模板中使用我的自定义类

我看了以下帖子,没有任何成功。

Use class inside a T4 template

在我的T4模板,我想使用AddControls方法在我的自定义类ResourceManager的定义,但我收到以下错误。

编译转型:类型或命名空间名称“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 #> 

<# 
    } 

#> 

回答

4

构建一个包含命名空间WebApplication1项目并再次尝试保存模板。 这对我来说使用你的代码。

+0

真棒..谢谢丹 – 2012-07-11 16:24:45

相关问题