Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

T4 template assembly directive

I have a custom dll, which has a class in it, and (for simplicity's sake) there's a method on it which'll return a string.

I have a project, which references said dll, and I want to use a (not preprocessed) T4 template in that project, which calls said method. I've tried this:

<#@ template debug="true" hostspecific="false" language="C#" #>
<#@ assembly name="MyDLL.dll" #>
<#@ output extension=".cs" #>
<#
    var template = new MyDLL.MyNamespace.MyClass();
        this.Write(template.Run());
#>

I got the following errors:

Error 14 Compiling transformation: Metadata file 'MyDLL.dll' could not be found
Error 13 A namespace cannot directly contain members such as fields or methods

even if MyClass.Run() is simply a return "//hello";

like image 896
TDaver Avatar asked May 27 '11 11:05

TDaver


People also ask

What is t4 template in Entity Framework?

t4 template is used to scaffold a DbContext class for the database, and the EntityType. t4 template is used to scaffold entity type classes for each table and view in the database.


1 Answers

Seems like Your problem:

Error Compiling transformation: Metadata file 'dotless.Core' could not be found

It's due to compatibility break described here:

http://weblogs.asp.net/lhunt/archive/2010/05/04/t4-template-error-assembly-directive-cannot-locate-referenced-assembly-in-visual-studio-2010-project.aspx

like image 136
Wojtek Turowicz Avatar answered Sep 28 '22 14:09

Wojtek Turowicz