Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Compiling transformation: The type or namespace name could not be found when running TypeLite.tt

Disclaimer: I'm new to just about every piece of technology I am using here, so forgive me please if I am missing the obvious...

I am starting to mess with MVC 4 with Entity Framework 5 and Web API, and I want to use TypeScript with Knockout to do some UI stuff. I found the TypeLite project which will take my EF model and generate TypeScript interfaces for me so that everything is "strongly" typed.

My solution consists of 3 projects:

  • MyApp.dll = Contains all of the MVC work
  • MyApp.Domain.dll = Contains the EF domain model
  • MyApp.WebAPI.dll = Contains the WebAPI work

I added the TypeLite reference to the MyApp project (via NuGet), and modified the TypeLite.tt to read:

<#@ template debug="false" hostspecific="True" language="C#" #>
<#@ assembly name="$(SolutionDir)packages\TypeLite.0.8.2\lib\net40\TypeLite.dll" #>
<#@ assembly name="$(TargetDir)$(TargetFileName)" #>
<#@ import namespace="TypeLite" #> 
<#@output extension=".d.ts"#>
<#= TypeScript.Definitions()
.For<MyApp.Domain.Models.Country>()
.For<MyApp.Domain.Models.State>()
.For<MyApp.Domain.Models.Address>()
.For<MyApp.Domain.Models.Contact>() #>

When I "Run Custom Tool" on the TypeLite.tt I get the error:

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

I have tried adding the line(s):

<#@ import namespace="MyApp" #>
<#@ import namespace="MyApp.Domain" #>
<#@ import namespace="MyApp.Domain.Models" #>

It still keeps giving me the same error though. I am certain I am missing something trivial, and I am still picking thru the thousands of articles that Dr. Google finds for me referencing a search for this, but I am hoping that someone on here can help me find the light.

Thanks for any help...

like image 609
ThinkingCap Avatar asked Apr 18 '13 13:04

ThinkingCap


1 Answers

T4 templating engine, that drives TypeScript interfaces generation, runs as a separate process, so even though MyApp.WebAPI project references MyApp.Domain.dll, T4 doesn't know about it.

You should add assembly directive that points to MyApp.Domain.dll to the TypeLite.tt. It's T4 analogue of the 'Add reference" command from regular C# projects.

<#@ assembly name="$(SolutionDir)path\to\MyApp.Domain.dll" #>

$(SolutionDir) is a variable, that contains path to your solution directory.

like image 130
Lukas Kabrt Avatar answered Sep 19 '22 04:09

Lukas Kabrt