C#模板,从数据库调用动态生成角色类

C#模板,从数据库调用动态生成角色类,c#,.net-core,entity-framework-core,C#,.net Core,Entity Framework Core,我正在尝试生成下面的角色类: <#@ template debug="false" hostspecific="false" language="C#" #> <#@ output extension=".cs" #> <#@ assembly name="Microsoft.Extensions.Configuration"#> <#@ import n

我正在尝试生成下面的角色类:

<#@ template debug="false" hostspecific="false" language="C#" #>
<#@ output extension=".cs" #>
<#@ assembly name="Microsoft.Extensions.Configuration"#>
<#@ import namespace="Microsoft.Extensions.Configuration" #>
namespace COMPANY.Application.Interfaces.Security
{
    public static partial class Role {
    <#
    var builder = new ConfigurationBuilder()
    .SetBasePath(Directory.GetCurrentDirectory())
    .AddJsonFile("appsettings.json", optional: true, reloadOnChange: true)
    .AddEnvironmentVariables();
    var configuration = builder.Build();

    foreach (string nodeName in new string[]{"ADMIN", "GUEST", "TECH"}) {
    #>
    public const string <#= nodeName #> = nameof(<#= nodeName #>);
    <# } #>
}
}

除了单独查找所有这些依赖项之外,我不确定是否还有更简单的方法。 netstandard错误让我感到困惑,因为我已经有了对该SDK的引用

Error:  IDE1007 The name 'ErrorGeneratingOutput' does not exist in the current context. COMPANY.Application.Interfaces  C:\LocalRepos\project\Services\COMPANY.Application.Interfaces\Security\RoleTemplate.cs  1   Active

Error:  Compiling transformation: The type 'Object' is defined in an assembly that is not referenced. You must add a reference to assembly 'netstandard, Version=2.0.0.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51'.    COMPANY.Application.Interfaces  C:\LocalRepos\project\Services\COMPANY.Application.Interfaces\Security\RoleTemplate.tt  10  

Error:  Compiling transformation: 'ConfigurationBuilder' does not contain a definition for 'SetBasePath' and no accessible extension method 'SetBasePath' accepting a first argument of type 'ConfigurationBuilder' could be found (are you missing a using directive or an assembly reference?)    COMPANY.Application.Interfaces  C:\LocalRepos\project\Services\COMPANY.Application.Interfaces\Security\RoleTemplate.tt  10  

Error:  Compiling transformation: The name 'Directory' does not exist in the current context    COMPANY.Application.Interfaces  C:\LocalRepos\project\Services\COMPANY.Application.Interfaces\Security\RoleTemplate.tt  10