Search code examples
codefluent

Do not automatically add reference when using the Templace producer


I'm doing a CodeFluent Entities project and I use the Template Producer to generate a report that print some statistics about my model.

As I could see, this Producer automatically add two references (CodeFluent.Runtime.dll and CodeFluent.Runtime.Web.dll). This is a great feature, nevertheless in my case, I don't generate any C# classes so the target project don't really need those references.

How can I disable this behavior ?


Solution

  • The Template producer inherits from the CodeDomProducer (the one that generates the BOM). This allows the template producer to have some useful methods like AddToGeneratedFiles that adds the file to Visual Studio target project, or AddCompilationReferences which adds references to the target project.

    The producer also inherits some configuration options like Target Project Layout of type CodeFluent.Model.Design.TargetProjectLayoutOptions

    [Flags]
    public enum TargetProjectLayoutOptions
    {
        None        = 0x0,
    
        [Description("Update All")]
        Update = UpdateReferences | UpdateItems,
    
        [Description("Update References")]
        UpdateReferences = 0x1,
    
        [Description("Update Items")]
        UpdateItems = 0x2,
    
        [Description("Do Not Remove Existing Items")]
        DontRemove = 0x4,
    
        Default     = Update,
    }
    

    As you can see this allows you to not update project references. So to answer your question, your producer configuration should look like

    <cf:producer name="Template" typeName="CodeFluent.Producers.CodeDom.TemplateProducer, CodeFluent.Producers.CodeDom">
        <cf:configuration cfx:targetProjectLayout="UpdateItems" [other options] />
    </cf:producer>
    

    Happy templating :)