Skip to content

Commit

Permalink
fixup! Scaffolding: Enable text templates
Browse files Browse the repository at this point in the history
Resolve assemblies
  • Loading branch information
bricelam committed Mar 7, 2022
1 parent bdd2e26 commit 56adbe5
Show file tree
Hide file tree
Showing 2 changed files with 29 additions and 3 deletions.
15 changes: 12 additions & 3 deletions src/EFCore.Design/TextTemplating/Internal/TextTemplatingService.cs
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,6 @@ public TextTemplatingService(IServiceProvider serviceProvider)
/// </summary>
public virtual IList<string> StandardAssemblyReferences { get; } = new string[]
{
// TODO: Flow project references?
typeof(ITextTemplatingEngineHost).Assembly.Location,
typeof(CompilerErrorCollection).Assembly.Location
};
Expand Down Expand Up @@ -171,8 +170,18 @@ public virtual AppDomain ProvideTemplatingAppDomain(string content)
/// doing so can result in application failures when updating to a new Entity Framework Core release.
/// </summary>
public virtual string ResolveAssemblyReference(string assemblyReference)
// TODO: Expand variables? Try Assembly.Load? Use compilation context?
=> assemblyReference;
{
try
{
return Assembly.Load(assemblyReference).Location;
}
catch
{
}

// TODO: Expand variables?
return assemblyReference;
}

/// <summary>
/// This is an internal API that supports the Entity Framework Core infrastructure and not subject to
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -159,4 +159,21 @@ public void Output_works()
Assert.Equal(".txt", callback.Extension);
Assert.Equal(Encoding.ASCII, callback.OutputEncoding);
}

[Fact]
public void Assembly_works()
{
var host = new TextTemplatingService(
new ServiceCollection()
.BuildServiceProvider());
var callback = new TextTemplatingCallback();

var result = host.ProcessTemplate(
@"T:\test.tt",
@"<#@ assembly name=""Microsoft.EntityFrameworkCore"" #><#= nameof(Microsoft.EntityFrameworkCore.DbContext) #>",
callback);

Assert.Empty(callback.Errors);
Assert.Equal("DbContext", result);
}
}

0 comments on commit 56adbe5

Please sign in to comment.