Tech /

T 4 Code Generation





edit SideBar

T 4 Code Generation

Code generation with T4 in VS2008? and above.

Compact Framework

  • http://www.agilification.com/post/T4-Templates-For-The-NET-Compact-Framework.aspx
  • By default prints the following errors:
    1. Compiling transformation: The type or namespace name 'CompilerError?' does not exist in the namespace 'System.CodeDom?.Compiler' (are you missing an assembly reference?)
    2. Compiling transformation: The type 'System.CodeDom?.Compiler.CompilerErrorCollection?' is defined in an assembly that is not referenced. You must add a reference to assembly 'System, Version=2.0.0.0, Culture=neutral, PublicKeyToken?=b77a5c561934e089'.
    3. Compiling transformation: 'System.CodeDom?.Compiler.CompilerErrorCollection?' does not contain a definition for 'Add'
    "Why doesn't this work? Because Visual Studio is attempting to use the Compact Framework assemblies in order to process the T4 template file. But the Compact Framework assemblies don't include the System.CodeDom? namespace.
    I don't think Microsoft is ever going to add the CodeDom? namespace to the Compact Framework. But there is a way to get T4 templates working in a Compact Framework project. You basically start off by creating two separate projects, one targeting the full .NET Framework, and another targeting the Compact Framework. Then, combine these projects into the same folder so they can share files between them. Finally, you can add .tt files to the full .NET Framework project and include the generated .cs files in your Compact Framework project. Voila! Templates for the Compact Framework."
  • Workaround is to create a C# project with access to the complete .NET environment, incorporating the T4 script outputting a CS file overlaid with the normal CF project. The CF project then includes only the generated CS file.
Recent Changes (All) | Edit SideBar Page last modified on 01 June 2012, at 01:46 PM UTC Edit Page | Page History
Powered by PmWiki