1

我是这个 T4 模板的新手。我所知道的是这些模板将从 LINQ 到 SQL 类模型(.dbml 文件)生成实体类我们有这个在 Visual Studio 2010 上运行的系统。

当我们迁移到 Visual Studio 2015 时,问题就开始了。我想向实体/表添加新列。当我运行自定义工具时,会弹出此错误

找不到名为“xsd”的指令的名为“T4Toolbox.XsdProcessor”的处理器。转换将不会运行。引发了以下异常:System.IO.FileNotFoundException:无法解析指令处理器 T4Toolbox.XsdProcessor 的类型。

下面是模板。

<#@ template hostspecific="True" debug="true" #>
<#@ xsd processor="T4Toolbox.XsdProcessor" file="%VS100COMNTOOLS%\..\..\Xml\Schemas\DbmlSchema.xsd" #>
<#@ output extension="log" #>
<#@ import namespace="System.Collections.Generic" #>
<#@ include file="T4Toolbox.tt" #>
<#

@ include file="..\..\..\Framework\Templates\LinqToSql.tt" #>
// <copyright file="Script1.tt" company="">
//  Copyright © . All Rights Reserved.
// </copyright>

// Generate entity classes from a LINQ to SQL class model (.dbml file)
NXpertGenerator generator = new NXpertGenerator();
generator.DbmlFile = "..\\..\\NXpert.Accounting.DataAccess\\Accounting.dbml";
generator.ConnectionStringKey = "AccountingDB2";
generator.DbmlNamespace = "NXpert.Accounting.DataAccess";
generator.UsingStatements = new List<string>{"NXpert.Core", "NXpert.Accounting", "NXpert.Accounting.DataAccess", "System.Data.Linq"};

generator.ClassMappings = new List<ObjectDescriptor>{   
    new ObjectDescriptor{
        Name = "BalanceSheet",
        NamePlural = "BalanceSheets",
        EntityName = "BalanceSheetEntity",
        Properties = new List<PropertyDescriptor>{
            new PropertyDescriptor{ Name = "Status", ConvertType = "CommonStatus" },
            new PropertyDescriptor{ Name = "CreatedDate", ConvertType = "DateTime" },
            new PropertyDescriptor{ Name = "UpdatedDate", ConvertType = "DateTime" }
        }
        }
};

generator.Run();

#>

我确实尝试删除该行

<#@ xsd processor="T4Toolbox.XsdProcessor" file="%VS100COMNTOOLS%\..\..\Xml\Schemas\DbmlSchema.xsd" #>

这个错误显示

编译转换:找不到类型或命名空间名称“关联”(是否缺少 using 指令或程序集引用?) 编译转换:找不到类型或命名空间名称“数据库”(是否缺少 using 指令还是汇编参考?)

这种错误有点告诉我,这只是我忘记添加的命名空间。但同样,这个模板在 Visual Studio 2010 中运行良好。

必须完成一些设置/步骤才能使这些模板在 VS2015 中运行。请告诉我。

我很乐意感谢您可以分享我的这个问题的任何解决方案或想法。

4

0 回答 0