Calling a class in the same project from T4 template

I am trying to create several linings for classes CRUDand would like to use T4 to help create these classes. I am just getting started and have a problem causing a class that lives in the same project. Example:

<#@ import namespace="System.Collections.Generic" #>
<#@ template    language="C#"   #>
<#@ output      extension=".cs" #>
<#@ include file="T4Toolbox.tt" #>

using System;
using System.Data;
using System.Data.Linq;
using System.Collections.Generic;

namespace TTFileGenerator
{
<#var entityName = "TEST";#>
    public class <#=entityName#>
    {
    <#
            MyClass myClass = new MyClass();
            List<string> something = myClass.GetSomething()
            ...
    #>
    }
}

Error:

Conversion compilation: MyClass namespace type or name could not be found (do you miss the using directive or assembly references?)

This is an open class in the same project. I can access it from other classes in the project, and not to the T4 file. Still new to T4. Any direction will be appreciated.

+4
source share
2 answers

What you want to do will not be straightforward.

T4 ( MyClass), , T4 ( , EF). , , , T4 ( IDE ). t4 dll, . Visual Studio . < & GT;

, , (3 ). , , MyClass. .

( ) runtime t4 . ( MyClass) , , , ! .

. .

Aspect Oriented Programming (AOP). , , .

, . . .

+3

, , , .

, , . (VS 2012)... , - T4:

//Reference to another project (for testing, it lives in the debug folder)
<#@ assembly name="$(SolutionDir)\MyAssembly\bin\x86\Debug\MyAssembly.dll"#>

<#  
    var helper = new Utilities.MyHelperClass();
#>

<#
     var something = helper.GetSomething(param1, param2);
#>
+2

Source: https://habr.com/ru/post/1530097/


All Articles