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 #>
<#
}
#>
真棒..謝謝丹 – 2012-07-11 16:24:45