What am I missing to read content of T4-File?

Viewed 381

I'm in desperate need to generate HTML output with T4 in C#.

I'm using Runtime-T4-Files and chose as option "TextTemplatingFilePreprocessor" instead of "TextTemplatingFileGenerator".

My "MyTemplate.tt"-File contains:

<#@ template language="C#" #>
<#@ assembly name="System.Core" #>
<#@ import namespace="System.Linq" #>
<#@ import namespace="System.Text" #>
<#@ import namespace="System.Collections.Generic" #>

foo

My "Program.cs"-File contains:

using System;

namespace T4MS
{
    class Program
    {
        static void Main(string[] args)
        {
            string output = new MyTemplate().TransformText();
            Console.WriteLine(output);
        }
    }
}

What am I missing that following error occurs:

Schweregrad Code Beschreibung Projekt Datei Zeile Unterdrückungszustand Fehler CS1069 Der Typname "CompilerErrorCollection" konnte nicht im Namespace "System.CodeDom.Compiler" gefunden werden. Dieser Typ wurde an Assembly "System.CodeDom, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51" weitergeleitet. Sie sollten einen Verweis auf die Assembly hinzufügen. T4MS C:\Users\figaro\source\repos\T4MS\T4MS\MyTemplate.cs 47 Aktiv

Basically this error tells me to add an assembly reference "System.CodeDom", thrown by my auto generated "MyTemplate.cs"-File.

So I tried to add the "lacking" assembly with <#@ template language="C#" #> <#@ import namespace="System.CodeDom" #> or <#@ assembly name="System.CodeDom" #>in my tt-File.

2 Answers

This first line works for me. I can't remember where I read it but in my case it was langversion that caused the problem - nothing higher than 7.3 worked but that was a year or two ago

<#@ template debug="false" hostspecific="true" language="C#" compilerOptions="/langversion:7.3" #>
Related