2012-07-11 18 views
5

私はGoogleとSOを研究しており、回答を見つけることができません。T4テンプレートでカスタムクラスを使用できません

私はすべての成功を追って次の投稿を見てきました。私のT4テンプレートで

Use class inside a T4 template

、私は私のカスタムクラス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 #> 

<# 
    } 

#> 

答えて

4

は、名前空間WebApplication1が含まれており、再びテンプレートを保存しようとしたプロジェクトをビルドします。 あなたのコードを使用して私のために働いた。

+0

すごい..ありがとうダン –

関連する問題