5

I need to specify my T4 to use C# 4.0, to render my tt files? I tried using

<#@ template language="C#v4.0" debug="true" #>

But when I use a dynamic variable, like this

dynamic x=10;
Write(x.ToString());

I'm getting these errors

Error   2   Compiling transformation: Predefined type 'Microsoft.CSharp.RuntimeBinder.CSharpSetMemberBinder' is not defined or imported e:\projects\DynamicModel\DynamicModel\ModelGenerator.tt 1   1   
Error   3   Compiling transformation: Missing compiler required member 'Microsoft.CSharp.RuntimeBinder.CSharpInvokeMemberBinder..ctor'  e:\projects\DynamicModel\DynamicModel\ModelGenerator.tt 1   1   
Error   4   Compiling transformation: Missing compiler required member 'System.Runtime.CompilerServices.CallSite.Create'    e:\projects\DynamicModel\DynamicModel\ModelGenerator.tt 1   1   
Error   5   Compiling transformation: One or more types required to compile a dynamic expression cannot be found. Are you missing references to Microsoft.CSharp.dll and System.Core.dll?   e:\Projects\DynamicModel\DynamicModel\ModelGenerator.tt 7   8   
Error   6   A namespace cannot directly contain members such as fields or methods   e:\projects\DynamicModel\DynamicModel\ModelGenerator.cs 1   1   DynamicModel

Also, please note that I'm using TextTemplatingFileGenerator and Not pre-processor templates

amazedsaint
  • 7,642
  • 7
  • 54
  • 83

2 Answers2

6

Found that you should specify the correct assemblies as well.

Adding this will ensure you are using c# 4.0.

<#@ template language="C#" debug="true" #>
<#@ output extension=".txt" #>
<#@ Assembly Name="System.Core, Version=4.0.0.0, Culture=neutral" #>
<#@ Assembly Name="Microsoft.CSharp, Version=4.0.0.0, Culture=neutral" #>

How ever, for some reason, during the time of t4 transformation, the dynamic dispatching is still not working from T4, wondering why. From T4 it throws a runtime error, the same code does good directly from a cs file.

amazedsaint
  • 7,642
  • 7
  • 54
  • 83
2

I believe that by default the T4 engine can only use 4.0, although I'd make sure that any DLLs you reference are correct for your error.

Colin Asquith
  • 653
  • 1
  • 6
  • 13