Including a C # file in a T4 template using:
<#@ include file="$(ProjectDir)ClassDefinition.cs" #>
Add text to the output of the T4 template. It does not compile the class.
You have debug = true set in your T4 template so that you can see what T4 generates if you look in your% TEMP% directory. When you run your T4 template, you will see the .cs file generated in the TEMP directory. In this file you will have something similar to:
this.Write("public class ClassDefinition\r\n{\r\n public string NameSpace { get; set; }\r\np" + "ublic string Name { get; set; }\r\n public string Protection { get; set; }\r\n\r\n " + " List<ClassProperty> Properties { get; set; }\r\n}");
So, all that happens to your C # class is that it will be written to the generated T4 output.
What you probably want to do is include the ClassDefinition.cs file in your project so that it is compiled as part of your project. You can then reference the assembly, which includes the ClassDefinition class. Therefore, if your project is MyLibrary.dll, which contains the ClassDefinition.cs compilation, you should be able to use:
<#@ assembly name="$(SolutionDir)$(OutDir)MyLibrary.dll" #>
The line containing the ClassDefinition.cs file must be deleted.
source share