【发布时间】:2014-11-09 19:16:22
【问题描述】:
我正在尝试在 Visual Studio 2013 中为 EF Code-First 上下文类创建项目模板。除了我想要一个指向当前项目中命名空间的 using 语句之外,我已经完成了所有工作。例如,当在 ProjectName.Contexts 中创建模板项的实例时, using 语句将是:
使用项目名称.Models
问题是我找不到替换项目模板中的部件的方法。据我所知,$projectname$ 和 $safeprojectname$ 仅适用于项目模板,而不适用于项目模板。
我的模板如下:
using System;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using $safeprojectname$.DAL.Models; // This is the problem line
namespace $rootnamespace$
{
public class $safeitemrootname$
: DbContext
{
// Constructors =======================================================
public $safeitemrootname$()
: base("$safeitemrootname$")
{
}
// DBSets =============================================================
// public DbSet<Company> Companies { get; set; }
// Configuration ======================================================
protected override void OnModelCreating(DbModelBuilder modelBuilder)
{
modelBuilder.Conventions.Remove<PluralizingTableNameConvention>();
}
}
}
更新:
作为对 Hans 评论的回应,这是我尝试使用 $projectname$ 时的输出($safeprojectname$ 也是如此):
using System;
using System.Data.Entity;
using System.Data.Entity.ModelConfiguration.Conventions;
using $projectname$.DAL.Models; // This is the problem line
如您所见,$projectname$ 替换只是被忽略了。
任何帮助将不胜感激,
杰森
【问题讨论】:
-
不,这在项目模板中也可以正常工作。它被项目的默认命名空间值替换。在项目 + 属性,应用程序选项卡中设置。
标签: c# visual-studio templates