diff --git a/.github/workflows/pull_request.yml b/.github/workflows/pull_request.yml index c2b7a7b..b3242d2 100644 --- a/.github/workflows/pull_request.yml +++ b/.github/workflows/pull_request.yml @@ -4,6 +4,7 @@ on: pull_request: branches: - main + - 'release/v*' concurrency: group: ci-pr-${{ github.ref }}-1 diff --git a/Mono.TextTemplating.Tests/AssemblyLoadContextTests.cs b/Mono.TextTemplating.Tests/AssemblyLoadContextTests.cs index 9ca2997..4b8bb5b 100644 --- a/Mono.TextTemplating.Tests/AssemblyLoadContextTests.cs +++ b/Mono.TextTemplating.Tests/AssemblyLoadContextTests.cs @@ -31,6 +31,21 @@ protected override void VerifyFinalState ((SnapshotSet 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 ().FirstOrDefault (); + Assert.Null (firstError); + + Assert.Equal ("Array", content); + } } #endif \ No newline at end of file diff --git a/Mono.TextTemplating.Tests/ProcessingTests.cs b/Mono.TextTemplating.Tests/ProcessingTests.cs index 4076f3c..344190c 100644 --- a/Mono.TextTemplating.Tests/ProcessingTests.cs +++ b/Mono.TextTemplating.Tests/ProcessingTests.cs @@ -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 () { diff --git a/Mono.TextTemplating/Mono.TextTemplating/TemplateAssemblyLoadContext.cs b/Mono.TextTemplating/Mono.TextTemplating/TemplateAssemblyLoadContext.cs index 59bb59b..7453e0c 100644 --- a/Mono.TextTemplating/Mono.TextTemplating/TemplateAssemblyLoadContext.cs +++ b/Mono.TextTemplating/Mono.TextTemplating/TemplateAssemblyLoadContext.cs @@ -3,6 +3,7 @@ #if FEATURE_ASSEMBLY_LOAD_CONTEXT +using System; using System.CodeDom.Compiler; using System.IO; using System.Reflection; @@ -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; + } } } diff --git a/Mono.TextTemplating/Mono.TextTemplating/TemplateGenerator.cs b/Mono.TextTemplating/Mono.TextTemplating/TemplateGenerator.cs index b92273b..92a8666 100644 --- a/Mono.TextTemplating/Mono.TextTemplating/TemplateGenerator.cs +++ b/Mono.TextTemplating/Mono.TextTemplating/TemplateGenerator.cs @@ -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