Skip to content

RazorEngine.NetFramework 4.2.0

Choose a tag to compare

@github-actions github-actions released this 29 Oct 01:34
· 39 commits to master since this release
fabc05e
  • (NEW) The C# language version of templates can be pinned with DefaultCompilerServiceFactory.LanguageVersion (also on RoslynCompilerServiceFactory, and CSharpRoslynCompilerService.LanguageVersion). The default stays the newest version the bundled Roslyn supports (C# 14). Pin an older version when a newer C# version changes the meaning of existing templates, see the field entry under 4.1.0:

    config.CompilerServiceFactory = new DefaultCompilerServiceFactory { LanguageVersion = Microsoft.CodeAnalysis.CSharp.LanguageVersion.CSharp13 };
  • (PERFORMANCE) The Roslyn compiler service caches the metadata references of the loaded assemblies templates are compiled against, per AppDomain, so Roslyn reuses what it read from them instead of reading and analyzing every referenced assembly on each compile. Each compile after the first is about 35 to 50% faster: in a benchmark, about 25 ms instead of 40 ms with 64 loaded assemblies, and about 48 ms instead of 95 ms with 255. The first compile in a process is unchanged (about 2 s for loading Roslyn). A loaded assembly cannot change, so the cache never goes stale; references given as a file path, stream or byte array (by a custom IReferenceResolver) are read on every compile. Templates themselves are not cached by this; changed templates are recompiled as before.

  • (BUILD) dotnet pack validates the package against the last published version (package validation, baseline 4.1.0) and fails on breaking changes of the public API.

  • (DOCS) The README links the documentation pages in doc (with absolute links, so they also work on nuget.org) instead of the original project's website, and its AppDomain example for cleaning up temporary files uses a fully trusted AppDomain instead of suggesting a partially trusted one.

  • (DOCS) New page Caching: how compiled templates are cached (template key and model type), what RunCompile, Compile, Run and IsTemplateCached do, the three caching providers with examples for invalidating, why invalidating does not free memory (each recompile loads a new assembly that stays until its AppDomain is unloaded) and when temporary files are deleted.

  • (DOCS) Roslyn shows how to pin LanguageVersion when RazorEngine is configured in app.config/web.config: derive a factory that sets it in its constructor and name that type in compilerServiceFactoryType.

  • (DOCS) Outdated passages removed from the documentation: links to the original project's website, notes about Mono (the fork targets .NET Framework 4.8 on Windows) and an old Travis CI link. ReferenceResolver.md explains which compiler needs which references.

  • (BUILD) Removed files and projects that nothing used or shipped: RazorEngine.Mvc, RazorEngine.Hosts.Console, the old FSharp.Formatting doc site, the class diagram and an unused ruleset. The tests build TestHelper.dll instead of using a checked-in binary.

NuGet: https://www.nuget.org/packages/RazorEngine.NetFramework/4.2.0