Skip to content

Latest commit

 

History

History
189 lines (142 loc) · 4.98 KB

Configuration.md

File metadata and controls

189 lines (142 loc) · 4.98 KB

Configuration

Nugets

For using global configuration from user code (*.nt.cs), local configuration does not need one.

https://www.nuget.org/packages/NTypewriter.Editor.Config/

Local vs Global configuration

All available here options can be set in two ways:

  • in separate c# file (with *.nt.cs extension) that will be used by all templates in the given project (aka global configuration)
  • inside *.nt template (aka local configuration)

Local configuration should be used only at the beginning of the template, before any other template code. If both configuration options are used, the local configuration will overwrite things set in the global configuration.

Files that contain global configuration are detected by file extension : *.nt.cs.

How global configuration is discovered and compiled, you can see in UserCodeLoader.cs

AddGeneratedFilesToVSProject

By default, all generated files are added to project in which template is located.

Global configuration (*.nt.cs file)

using System;
using System.Collections.Generic;
using NTypewriter.Editor.Config;

namespace ConsoleApp
{    
    class NameDoesNotMatter : EditorConfig
    {
        public override bool AddGeneratedFilesToVSProject { get => true; }
    }
}

Local configuration

{{ config.AddGeneratedFilesToVSProject = true }}

NamespacesToBeSearched

Only types located inside listed namespaces will be available in code model. If the list is empty, filtering is not applied.

Global configuration (*.nt.cs file)

using System;
using System.Collections.Generic;
using NTypewriter.Editor.Config;

namespace ConsoleApp
{    
    class NTEConfig : EditorConfig
    {
        public override IEnumerable<string> NamespacesToBeSearched
        {
            get
            {
                yield return "MediatR";
                yield return "Scriban";
                yield return "NetArchTest";
            }
        }
    }
}

Local configuration

{{ config.NamespacesToBeSearched = ["MediatR", "Scriban", "NetArchTest"] }}

ProjectsToBeSearched

By default code model is populated with symbols from all projects in solution. With this option, you can limit the scope to only specified projects. When you have a lot of projects in your solution, using this option can significantly improve performance (see #29 ).

Global configuration (*.nt.cs file)

using System;
using System.Collections.Generic;
using NTypewriter.Editor.Config;

namespace ConsoleApp
{    
    class NTEConfig : EditorConfig
    {
        public override IEnumerable<string> ProjectsToBeSearched
        {
            get
            {
                yield return "NTypewriter.CodeModel";
                yield return "Scriban";
            }
        }
    }
}

Local configuration

{{ config.ProjectsToBeSearched = ["NTypewriter.CodeModel", "Scriban"] }}

SearchInReferencedProjectsAndAssemblies

This option allows getting access to symbols defined in all referenced assemblies, even System symbols. Thus it should only be used with very limited code model by GetProjectsToBeSearched and/or GetNamespacesToBeSearched options, otherwise, your code model will contain thousands of symbols.

Also, have in mind that symbols from the same assembly but referenced from different projects are treated as different symbols. The best way to avoid duplication it is to use this option enabled only when GetProjectsToBeSearched returns limited number of projects without references to the same assembly.

Global configuration (*.nt.cs file)

using System;
using System.Collections.Generic;
using NTypewriter.Editor.Config;

namespace ConsoleApp
{    
    class NameDoesNotMatter : EditorConfig
    {
        public override bool SearchInReferencedProjectsAndAssemblies => false;
    }
}

Local configuration

{{ config.SearchInReferencedProjectsAndAssemblies = false }}

RenderWhenTemplateIsSaved

With this option, you can decide if you want to automatically render a template always when it is saved.

Global configuration (*.nt.cs file)

using System;
using System.Collections.Generic;
using NTypewriter.Editor.Config;

namespace ConsoleApp
{    
    class Config : EditorConfig
    {
        public override bool RenderWhenTemplateIsSaved { get => false; }
    }
}

Local configuration

{{ config.RenderWhenTemplateIsSaved = false }}

RenderWhenProjectBuildIsDone

With this option, you can decide if you want to automatically render all templates from a given project, when it is successfully built.

Global configuration (*.nt.cs file)

using System;
using System.Collections.Generic;
using NTypewriter.Editor.Config;

namespace ConsoleApp
{    
    class Config : EditorConfig
    {
        public override bool RenderWhenProjectBuildIsDone { get => false; }
    }
}

Local configuration

{{ config.RenderWhenProjectBuildIsDone = false }}