Skip to content

Commit

Permalink
Merge pull request #147 from mono/backport-2.3.1-to-main
Browse files Browse the repository at this point in the history
Backport 2.3.1 to main
  • Loading branch information
mhutch authored Oct 28, 2022
2 parents 384e6af + c9b085a commit 0053d8d
Show file tree
Hide file tree
Showing 5 changed files with 48 additions and 4 deletions.
1 change: 1 addition & 0 deletions .github/workflows/pull_request.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ on:
pull_request:
branches:
- main
- 'release/v*'

concurrency:
group: ci-pr-${{ github.ref }}-1
Expand Down
15 changes: 15 additions & 0 deletions Mono.TextTemplating.Tests/AssemblyLoadContextTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,21 @@ protected override void VerifyFinalState ((SnapshotSet<string> assembliesInDefau

state.allContexts.AssertUnchanged ();
}

/// Issue #143: System.Text.Json is a framework assembly on .NET Core 3.0 and does not need to be specified by absolute path
[Fact]
public async Task LoadSystemTextJson ()
{
string template = "<#@ assembly name=\"System.Text.Json\" #><#=System.Text.Json.JsonValueKind.Array.ToString()#>";

var gen = new TemplateGenerator ();
(_, string content, _) = await gen.ProcessTemplateAsync (null, template, null);

CompilerError firstError = gen.Errors.OfType<CompilerError> ().FirstOrDefault ();
Assert.Null (firstError);

Assert.Equal ("Array", content);
}
}

#endif
16 changes: 16 additions & 0 deletions Mono.TextTemplating.Tests/ProcessingTests.cs
Original file line number Diff line number Diff line change
Expand Up @@ -117,6 +117,22 @@ public async Task SetLangVersionViaAdditionalArgsInProcess ()
}
#endif

[Fact]
public async Task SetOutputExtension ()
{
string inputContent = "<#@ output extension=\".cfg\" #>";
string inputFile = "hello.tt";
string outputName = "hello.txt";

// this reproduces the calls made by dotnet-t4
var gen = new TemplateGenerator ();
var pt = gen.ParseTemplate (inputFile, inputContent);
TemplateSettings settings = TemplatingEngine.GetSettings (gen, pt);
(outputName, _) = await gen.ProcessTemplateAsync (pt, inputFile, inputContent, outputName, settings);

Assert.Equal ("hello.cfg", outputName);
}

[Fact]
public async Task ImportReferencesTest ()
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@

#if FEATURE_ASSEMBLY_LOAD_CONTEXT

using System;
using System.CodeDom.Compiler;
using System.IO;
using System.Reflection;
Expand Down Expand Up @@ -52,9 +53,20 @@ protected override Assembly Load (AssemblyName assemblyName)
return hostAssembly;
}

foreach (var asmFile in templateAssemblyFiles) {
if (assemblyName.Name == Path.GetFileNameWithoutExtension (asmFile)) {
return LoadFromAssemblyPath (asmFile);
for (int i = 0; i < templateAssemblyFiles.Length; i++) {
var asmFile = templateAssemblyFiles[i];
if (asmFile is null) {
continue;
}
if (MemoryExtensions.Equals (assemblyName.Name, Path.GetFileNameWithoutExtension (asmFile.AsSpan()), StringComparison.OrdinalIgnoreCase)) {
// if the file doesn't exist, fall through to host.ResolveAssemblyReference
if (File.Exists (asmFile)) {
return LoadFromAssemblyPath (asmFile);
} else {
// null out the missing file so we don't check it exists again
templateAssemblyFiles[i] = null;
break;
}
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -268,7 +268,7 @@ public string PreprocessTemplate (

var outputContent = await Engine.ProcessTemplateAsync (pt, inputContent, settings, this, token).ConfigureAwait (false);

return (outputFileName, outputContent);
return (OutputFile, outputContent);
}

#region Virtual members
Expand Down

0 comments on commit 0053d8d

Please sign in to comment.