Skip to content

Commit

Permalink
Scaffolding: Use "CodeTemplates" directory
Browse files Browse the repository at this point in the history
Part of dotnet#4038
  • Loading branch information
bricelam committed Mar 15, 2022
1 parent 8cd8c9a commit 4a81fd7
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 12 deletions.
2 changes: 1 addition & 1 deletion src/EFCore.Design/Scaffolding/TemplatedModelGenerator.cs
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ protected TemplatedModelGenerator(ModelCodeGeneratorDependencies dependencies)
/// Gets the subdirectory under the project to look for templates in.
/// </summary>
/// <value>The subdirectory.</value>
protected static string TemplatesDirectory { get; } = Path.Combine("Templates", "EFCore");
protected static string TemplatesDirectory { get; } = Path.Combine("CodeTemplates", "EFCore");

/// <inheritdoc/>
public override string? Language
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ public void HasTemplates_works_when_templates()
{
using var projectDir = new TempDirectory();

var template = Path.Combine(projectDir, "Templates", "EFCore", "DbContext.t4");
var template = Path.Combine(projectDir, "CodeTemplates", "EFCore", "DbContext.t4");
Directory.CreateDirectory(Path.GetDirectoryName(template));
File.Create(template).Close();

Expand Down Expand Up @@ -44,14 +44,14 @@ public void GenerateModel_uses_templates()
{
using var projectDir = new TempDirectory();

var contextTemplate = Path.Combine(projectDir, "Templates", "EFCore", "DbContext.t4");
var contextTemplate = Path.Combine(projectDir, "CodeTemplates", "EFCore", "DbContext.t4");
Directory.CreateDirectory(Path.GetDirectoryName(contextTemplate));
File.WriteAllText(
contextTemplate,
"My DbContext template");

File.WriteAllText(
Path.Combine(projectDir, "Templates", "EFCore", "EntityType.t4"),
Path.Combine(projectDir, "CodeTemplates", "EFCore", "EntityType.t4"),
"My entity type template");

var generator = CreateGenerator();
Expand Down Expand Up @@ -81,7 +81,7 @@ public void GenerateModel_works_when_no_entity_type_template()
{
using var projectDir = new TempDirectory();

var contextTemplate = Path.Combine(projectDir, "Templates", "EFCore", "DbContext.t4");
var contextTemplate = Path.Combine(projectDir, "CodeTemplates", "EFCore", "DbContext.t4");
Directory.CreateDirectory(Path.GetDirectoryName(contextTemplate));
File.WriteAllText(
contextTemplate,
Expand Down Expand Up @@ -112,7 +112,7 @@ public void GenerateModel_sets_session_variables()
{
using var projectDir = new TempDirectory();

var contextTemplate = Path.Combine(projectDir, "Templates", "EFCore", "DbContext.t4");
var contextTemplate = Path.Combine(projectDir, "CodeTemplates", "EFCore", "DbContext.t4");
Directory.CreateDirectory(Path.GetDirectoryName(contextTemplate));
File.WriteAllText(
contextTemplate,
Expand All @@ -122,7 +122,7 @@ public void GenerateModel_sets_session_variables()
ProjectDefaultNamespace: <#= Session[""ProjectDefaultNamespace""] #>");

File.WriteAllText(
Path.Combine(projectDir, "Templates", "EFCore", "EntityType.t4"),
Path.Combine(projectDir, "CodeTemplates", "EFCore", "EntityType.t4"),
@"EntityType not null: <#= Session[""EntityType""] != null #>
Options not null: <#= Session[""Options""] != null #>
NamespaceHint: <#= Session[""NamespaceHint""] #>
Expand Down Expand Up @@ -166,7 +166,7 @@ public void GenerateModel_defaults_to_model_namespace_when_no_context_namespace(
{
using var projectDir = new TempDirectory();

var contextTemplate = Path.Combine(projectDir, "Templates", "EFCore", "DbContext.t4");
var contextTemplate = Path.Combine(projectDir, "CodeTemplates", "EFCore", "DbContext.t4");
Directory.CreateDirectory(Path.GetDirectoryName(contextTemplate));
File.WriteAllText(
contextTemplate,
Expand Down Expand Up @@ -196,14 +196,14 @@ public void GenerateModel_uses_output_extension()
{
using var projectDir = new TempDirectory();

var contextTemplate = Path.Combine(projectDir, "Templates", "EFCore", "DbContext.t4");
var contextTemplate = Path.Combine(projectDir, "CodeTemplates", "EFCore", "DbContext.t4");
Directory.CreateDirectory(Path.GetDirectoryName(contextTemplate));
File.WriteAllText(
contextTemplate,
@"<#@ output extension="".vb"" #>");

File.WriteAllText(
Path.Combine(projectDir, "Templates", "EFCore", "EntityType.t4"),
Path.Combine(projectDir, "CodeTemplates", "EFCore", "EntityType.t4"),
@"<#@ output extension="".fs"" #>
My entity type template");

Expand Down Expand Up @@ -232,7 +232,7 @@ public void GenerateModel_warns_when_output_encoding()
{
using var projectDir = new TempDirectory();

var contextTemplate = Path.Combine(projectDir, "Templates", "EFCore", "DbContext.t4");
var contextTemplate = Path.Combine(projectDir, "CodeTemplates", "EFCore", "DbContext.t4");
Directory.CreateDirectory(Path.GetDirectoryName(contextTemplate));
File.WriteAllText(
contextTemplate,
Expand Down Expand Up @@ -266,7 +266,7 @@ public void GenerateModel_reports_errors()
{
using var projectDir = new TempDirectory();

var contextTemplate = Path.Combine(projectDir, "Templates", "EFCore", "DbContext.t4");
var contextTemplate = Path.Combine(projectDir, "CodeTemplates", "EFCore", "DbContext.t4");
Directory.CreateDirectory(Path.GetDirectoryName(contextTemplate));
File.WriteAllText(
contextTemplate,
Expand Down

0 comments on commit 4a81fd7

Please sign in to comment.