Question

I am trying to use Robert Koritnik's t4 template to generate Enums.

These arent regular enums, my company is using a TypeSafeEnum pattern that is used occasionally in java. Its basically just a collection of classes with values. This isnt important, except to note that the TypeSafeEnum base class is in a different project from my EDMX and template files.

I also cant reference the enum project in my DB project because it would create a circular reference.

So, when I generate the enum classes, I reference the base class but it doesnt exist.

My question then:

Is there a way to copy the T4 generated code over to the correct project?

Or perhaps a better way of generating the code so I could have access to both namespaces?

Here is a snippet of my generated code:

using System;
using System.CodeDom.Compiler;
using xxxxxx.Core.Enums.BaseClasses;   //<--- Isnt referenced

namespace xxxxxx.Core.Enums
{
    /// <summary>
    /// InventoryAdjustmentType auto generated enumeration
    /// </summary>
    [GeneratedCode("TextTemplatingFileGenerator", "10")]
                                          //vvvvvvvv---- base class not referenced  
    public class InventoryAdjustmentType : TypeSafeEnum<InventoryAdjustmentType, byte>
    {
Was it helpful?

Solution

Move your .tt file to the project where you want the generated files to be:

- Solution "MySolution"
   |-> Project "DBProject"
   |      |-> MyModel.edmx
   |
   |-> Project "EnumsProject"
          |-> References
          |      |-> DBProject.dll
          |
          |-> MyT4Template.tt
                 |-> Generatedfiles.cs

and then make sure you provide the proper path to the EDMX file inside the T4 template so that it can read it properly:

var edmxPath = "..\DBProject\MyModel.Edmx";
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top