Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add option to run templates in current AssemblyLoadContext #170

Closed
wants to merge 1 commit into from
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -17,13 +17,16 @@ partial class CompiledTemplate
class TemplateProcessor : MarshalByRefObject
{
[SuppressMessage ("Performance", "CA1822:Mark members as static", Justification = "Needs to be an instance for MarshalByRefObject")]
public string CreateAndProcess (ITextTemplatingEngineHost host, CompiledAssemblyData templateAssemblyData, string templateAssemblyFile, string fullName, CultureInfo culture, string[] referencedAssemblyFiles)
public string CreateAndProcess (ITextTemplatingEngineHost host, CompiledAssemblyData templateAssemblyData, string templateAssemblyFile, string fullName, CultureInfo culture, string[] referencedAssemblyFiles, bool loadAssemblyIntoAppDomain)
{
using var context = new TemplateAssemblyContext (host, referencedAssemblyFiles);

Assembly assembly = templateAssemblyData is not null
? context.LoadInMemoryAssembly (templateAssemblyData)
: context.LoadAssemblyFile (templateAssemblyFile);
Assembly assembly =
templateAssemblyData is not null
? loadAssemblyIntoAppDomain
? Assembly.Load (templateAssemblyData.Assembly)
: context.LoadInMemoryAssembly (templateAssemblyData)
: context.LoadAssemblyFile (templateAssemblyFile);

// MS Templating Engine does not care about the type itself
// it only requires the expected members to be on the compiled type
Expand Down
5 changes: 4 additions & 1 deletion Mono.TextTemplating/Mono.TextTemplating/CompiledTemplate.cs
Original file line number Diff line number Diff line change
Expand Up @@ -105,9 +105,12 @@ TemplateProcessor CreateTemplateProcessor ()
#endif

public string Process ()
=> Process (loadAssemblyIntoAppDomain: false);

public string Process (bool loadAssemblyIntoAppDomain)
{
TemplateProcessor processor = CreateTemplateProcessor ();
return processor.CreateAndProcess (host, templateAssemblyData, templateAssemblyFile, templateClassFullName, culture, ReferencedAssemblyFiles);
return processor.CreateAndProcess (host, templateAssemblyData, templateAssemblyFile, templateClassFullName, culture, ReferencedAssemblyFiles, loadAssemblyIntoAppDomain);
}

public void Dispose ()
Expand Down
Loading