5

I have researched google and SO and can not find answer.

I have looked at following post with out any success.

Use class inside a T4 template

In my T4 template, I am trying to use AddControls Method defined in my Custom class ResourceManager but I am getting the following error.

Compiling transformation: The type or namespace name 'WebApplication1' could not be found (are you missing a using directive or an assembly reference?)

Please help me.

namespace WebApplication1
{
    public static class ResourceManager
    {

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

My T4 Template code looks as follows:

<#@ 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 #>

<#
    }

#>
Community
  • 1
  • 1
dotnet-practitioner
  • 13,968
  • 36
  • 127
  • 200

1 Answers1

4

Build the project that contains namespace WebApplication1 and try saving the template again. That worked for me using your code.

dan radu
  • 2,772
  • 4
  • 18
  • 23