【发布时间】:2016-09-13 16:30:59
【问题描述】:
在为实体框架使用 T4 类时,有几个开发人员在生成类时为每一行生成一个额外的新行。我想知道这是否是某种需要更改的设置,以便他们的 T4 生成文件看起来像其他开发人员生成的文件。作为我正在谈论的示例:(删除了特定名称,但您应该能够看到从同一个 *.tt 文件生成的新行数的差异。)
(更新:此问题也出现在其他 T4 模板中,而不仅仅是 EF。两台 PC 都使用 TextTemplatingFileGenerator 作为 T4 自定义工具。)
我的电脑的 T4 输出:
public virtual DbSet<GeneratedObject1> GeneratedObject1 { get; set; }
public virtual DbSet<GeneratedObject2> GeneratedObject2 { get; set; }
public virtual int SomeMethod1(Nullable<int> inParameter)
{
var localParameter = inParameter.HasValue ?
new ObjectParameter("SomePropertyName", inParameter) :
new ObjectParameter("SomePropertyName", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("SomeMethod1", localParameter);
}
public virtual int SomeMethod2(Nullable<int> inParameter)
{
var localParameter = inParameter.HasValue ?
new ObjectParameter("SomePropertyName", inParameter) :
new ObjectParameter("SomePropertyName", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("SomeMethod2", localParameter);
}
他们 PC 的 T4 输出:
public virtual DbSet<GeneratedObject1> GeneratedObject1 { get; set; }
public virtual DbSet<GeneratedObject2> GeneratedObject2 { get; set; }
public virtual int SomeMethod1(Nullable<int> inParameter)
{
var localParameter = inParameter.HasValue ?
new ObjectParameter("SomePropertyName", inParameter) :
new ObjectParameter("SomePropertyName", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("SomeMethod1", localParameter);
}
public virtual int SomeMethod2(Nullable<int> inParameter)
{
var localParameter = inParameter.HasValue ?
new ObjectParameter("SomePropertyName", inParameter) :
new ObjectParameter("SomePropertyName", typeof(int));
return ((IObjectContextAdapter)this).ObjectContext.ExecuteFunction("SomeMethod2", localParameter);
}
编辑:
【问题讨论】:
-
它们是否在完全相同的 Visual Studio 版本以及实体框架版本上?
-
是的,VS 2015(在我们使用 2013 时也发生了),Entity Framework 版本是项目的一部分,并且在 repo 中,所以对我们双方来说应该是一样的。
-
你能在十六进制编辑器中打开文件并发布截图吗?我很想知道文件的原始内容是什么,包括回车、换行、不可打印的字符等。
-
已更新,但我并没有真正看到任何突出的地方。
-
@Thomas927 我有时遇到从 git 返回的行尾问题。所以我在这里生成的 tt 文件中什么也看不到? (您的输出中有 0D 0A 与 0D 0A 0D 0A 相比)