NewYour coding agent can read the release notes before it upgrades.Set up the MCP server →
NuGet
NuGet, #1222 most downloaded on NuGet
Use Razor to build your templates from strings / files / EmbeddedResources outside of ASP.NET MVC for .NET Core
Latest stable
2.3.1
Last release 4 years ago
no release in 18 months
Ships unpredictably
gaps range from 8 days to 1.9 years
Most releases are documented
notes for 7 of 8 stable releases
1 version withdrawn
withdrawn after publishing
127 years old
30 releases · first in 1900
Drag across the ruler to compare, or tap a release to open it.
Missing space in exception message #498
Associated milestone tracker for v2.3.1:
https://github.com/toddams/RazorLight/milestone/19
Associated milestone tracker for v2.3.1: https://github.com/toddams/RazorLight/milestone/19
This release publishes to nuget.org @MarkKharitonov 's Razorlight.Precompile package.
This release publishes to nuget.org @MarkKharitonov 's Razorlight.Precompile package.
See previous version 2.2.0 release notes for details.
Your coding agent can read these notes before it upgrades. Set up the MCP server →
Issues By Milestone #491 Feature Request: Generate an assembly and persist it to disk (Precompile views) PRs By Milestone #492 Implement the RazorLigh
#491 Feature Request: Generate an assembly and persist it to disk (Precompile views)
#492 Implement the RazorLight.Precompile tool
#500 Fix broken tests on Unix (related to RazorLight.Precompile)
Docs updated by @mwasson74 , @vdurante
#481 System.UriFormatException: Invalid URI: The hostname could not be parsed (Fixed by @Xtansia #489 )
Nothing published for this version
#349 - Fixes #349 dotnet pack bug causes .netcoreapp3.1 TFM projects issues @(@jzabroski)
#349 - Fixes #349 dotnet pack bug causes .netcoreapp3.1 TFM projects issues @(@jzabroski)
#335 - Fixed spelling errors in the code (@SimonCropp) #309 - Added regression tests for common Razorlight renderer cases (@weyert) #346 - Introduce V
#335 - Fixed spelling errors in the code (@SimonCropp)
#309 - Added regression tests for common Razorlight renderer cases (@weyert)
#346 - Introduce Verify for section approval tests (@SimonCropp)
#308 - Fixed "The name 'section' does not exist in the current context in .net core 3" (@jzabroski)
Fixes #322 via commit 2d9c031 (@jzabroski )
Fixes #311 (via @HakanL PR #312): Incorrect template key when using constructor that takes assembly.
Fixes #287 via #310 (@matthewwren viz a viz @chancie86 )
Nothing published for this version
Nothing published for this version
@Raw() will not throw NullReferenceException on null or empty value (@ReinisV1 )
Nothing published for this version
Added new type: RazorLightEngineBuilder that comes to replace EngineFactory, as too many overloads are annoying
Note: there was a major refactoring, you may find some classes are moved to another namespaces
Templates that are resolved from FileSystem are now invalidated from MemoryCache when you change it.
You can now create an engine without a project, if you want to only create templates from strings - #110
It is possible now to create engine without caching provider
Add ability to set operating assembly (uses EntryAssembly if not specified)
Disable encoding for the entire document with template property "DisableEncoding" - #106
We added rendering of the strings back! And now they are cached, so you will not be affected by bad performance.
We added rendering of the strings back! And now they are cached, so you will not be affected by bad performance.
Note: if you store your templates in database - it is recommended approach to define custom RazorLightProject that fetches templates from database and create RazorLightEngine passing your implementation to it. This way, engine will your RazorLightProject to resolve layouts. String rendering is just another option for some exclusive use cases when you have microservice structure and pass templates between nodes, so you might not need it at all.
Here is an example of RazorLightProject that uses EntityFramework to get templates from database- https://github.com/toddams/RazorLight/blob/dev-2.0/samples/RazorLight.Samples/Program.cs
string templateKey = "key";
string result = await engine.CompileRenderAsync(templateKey , "Hello @Model.Name", new { Name = "Johny" });
//Returns true, so next time you render template with this key - it will not be compiled, but taken from cache
engine.TemplateCache.Contains(templateKey);
When RazorLight compiles your template - it loads all the assemblies from your entry assembly and creates MetadataReference from it. This is a default strategy and it works in 99% of the time. But sometimes compilation crashes with an exception message like "Can not find assembly My.Super.Assembly2000". In order to solve this problem you can pass additional metadata references to RazorLight.
var options = new RazorLightOptions();
var metadataReference = MetadataReference.CreateFromFile("path-to-your-assembly")
options.AdditionalMetadataReferences.Add(metadataReference );
var project = new FileSystemRazorProject("path-to-your-views");
var engine = new EngineFactory().Create(project, options);
Added support for includes via @{ await IncludeAsync("key", model); }
As always, you can avoid encoding using @Raw() function
@Raw(Model.Data)
Or disable encoding for entire document
@{
DisableEncoding = true;
}
GetTemplateAsync is now called CompileTemplateAsyncThere are a lot of breaking changes. Project literally has been made from scratch
This is not a full list of changes, only key notes about the changes and important info
So what is implemented?
Fixed bug with Configuration.Namespace not applied to the template
Fix #47 (ExpandoObject as model type throws RuntimeBinderException)
## What's new: - Update nuget packages to 1.1 - Minor bug fixes
Project migrated to MSBuild / *.csproj
This release comes out with some improvements and refactorings. We are planning to roll up a stable version soon
This release comes out with some improvements and refactorings. We are planning to roll up a stable version soon
ParseString() is extracted to an extension method (under RazorLight.Extensions namespace)IEngineConfigurationInvalidOperationException - RazorLightException is thrownAggregateExceptions. I'm erasing annoying AggregateExceptions from code. Please, open an issue If you see it again somewhereThis small release brings fixed for #15 and #18
This small release brings fixed for #15 and #18
Now you can use RazorLight with a Full .NET Framework v4.5.1 and higher
New package brings ASP.NET MVC Core integration which allows you to inject services into your templates via built in Dependency Injection container
Add package
Install-Package RazorLight.MVC
Add RazorLight services in Startup.cs
public void ConfigureServices(IServiceCollection services)
{
....
services.AddRazorLight("/Views"); // <- This one
....
}
private readonly IRazorLightEngine engine;
public HomeController(IRazorLightEngine engine)
{
this.engine = engine;
}
@inject MyProject.TestViewModel myModel
@Include now works in Layout and ViewStart pages as well (#12)
This release brings you Include feature
This release brings you Include feature
Example
@model MyProject.TestViewModel
<div>
Hello @Model.Title
</div>
@{ await IncludeAsync("SomeView.cshtml", Model); }
First argument takes a key of the template to resolve, second argument is a model of the view (can be null)
Use Raw() method to output model value without encoding
Raw() method to output model value without encoding ( #7 )IMemoryCache from DefaultPageLookupCachingPageFactoryPass ITemplateConfiguration to EngineFactory #3
IEngineConfiguration config = EngineConfiguration.Default;
config.Namespaces.Add("My.Custom.Namespace");
var engine = EngineFactory.CreatePhysical("root/folder", config);
Note: Viewbag is accessible both from the template page and it's layout.
Code
var model = new MyModel()
{
Title = "Test"
};
//create a dynamic viewbag
dynamic viewBag = new ExpandoObject();
viewBag.DataForLayoutPage = "Hello world";
string result = engine.Parse("key", model, viewBag);
Template
@model MyViewModel
@{
Layout = "layout_key";
}
<div>Hello @ViewBag.Title</div>
Package is under active development and there might be breaking changes in a new releases. I expect to ship 3-4 betas and then go to stable, sorry for…
This release brings Layout, _Viewstart pages support, sections and custom template namespaces. API is completely reworked.
ITemplateManager(string key) to resolve a templates. For files, Key - is a relative path to the view. For embeded resources - it's a name of the resourse.@model MyModel
@{
Layout = "_Layout.cshtml"; // <- This is a key of the layout page
}
Layout.cshtml:
@RenderSection("section-name", required : false)
View.cshtml:
@section section-name
{
<div>It is a content inside a section</div>
}
ITemplateConfiguration.Namespaces (ISet<string)Before:
var config = new ConfigurationOptions() { ViewsFolder = "C:/path/to/folder" }
var engine = new RazorLightEngine(config);
string result = engine.ParseFile("Test.cshtml", model);
After:
var engine = EngineFactory.CreatePhysical("C:/path/to/folder");
string result = engine.Parse("Test.cshtml", model);
First release with initial features:
First release with initial features:
One column per quarter.