Dijgrid.RazorLight 3.0.1

dotnet add package Dijgrid.RazorLight --version 3.0.1
                    
NuGet\Install-Package Dijgrid.RazorLight -Version 3.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Dijgrid.RazorLight" Version="3.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Dijgrid.RazorLight" Version="3.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Dijgrid.RazorLight" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Dijgrid.RazorLight --version 3.0.1
                    
#r "nuget: Dijgrid.RazorLight, 3.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Dijgrid.RazorLight@3.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Dijgrid.RazorLight&version=3.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Dijgrid.RazorLight&version=3.0.1
                    
Install as a Cake Tool

RazorLight

This repository is an independently maintained continuation of toddams/RazorLight. Compatibility and release policy may diverge from the historical project. See UPSTREAM.md for provenance.

RazorLight is a generic C# text-template engine built on Razor. It compiles templates and renders them outside ASP.NET MVC, making Razor syntax useful for source generation, configuration files, messages, reports, prompts, and other structured or plain-text output.

The maintained release targets .NET 10 and is published as Dijgrid.RazorLight. HTML behavior is optional; the core library treats output as text.

Build Status NuGet

Capabilities

  • Render Razor templates from strings, files, embedded resources, databases, or custom projects.
  • Use dynamic or strongly typed models, standard Razor expressions, imports, LINQ, layouts, sections, and partial templates.
  • Compose templates with trusted ordinary C# helper files through AddCSharpSource or @compileSource.
  • Cache compiled templates and invalidate dependent templates when project sources change.
  • Cancel template lookup, compilation waits, rendering, layouts, and includes cooperatively.
  • Precompile templates with the Dijgrid.RazorLight.Precompile command-line tool and render them in a compiler-free execution mode that never falls back to runtime compilation.
  • Select plain-text output, optional HTML encoding, or a custom output encoder.
  • Control namespaces, metadata references, dependency discovery, diagnostics, and integration with dependency injection.
  • Run framework-dependent, self-contained, and extraction-based single-file deployments on Windows and Linux.

Install

dotnet add package Dijgrid.RazorLight --version 3.0.1

The historical RazorLight 2.3.1 package is the upstream release, not this continuation. Moving to the Dijgrid.RazorLight 3.x line is a framework and API migration. Read the 2.3.1-to-3.0 migration guide before upgrading.

Quick example

var engine = new RazorLightEngineBuilder()
    .UseMemoryCachingProvider()
    .Build();

string template = "Hello, @Model.Name. Welcome to RazorLight repository";
ViewModel model = new ViewModel { Name = "John Doe" };

string result = await engine.CompileRenderStringAsync("templateKey", template, model);

Each template key identifies a logical template and allows its compiled form to be reused. String templates work without a project; project-backed templates add file lookup, embedded resources, layouts, includes, and source change tracking.

For example, render a file relative to a configured template root:

var engine = new RazorLightEngineBuilder()
    .UseFileSystemProject("C:/Templates")
    .UseMemoryCachingProvider()
    .Build();

string result = await engine.CompileRenderAsync(
    "Reports/Summary.cshtml",
    new { Title = "Quarterly summary" });

The engine exposes cache administration without leaking compiled-page factories:

if (engine.IsTemplateCached("Reports/Summary.cshtml"))
{
    engine.InvalidateTemplate("Reports/Summary.cshtml");
}

Templates can also select ordinary C# helper code:

@compileSource "../Shared/ScenarioFunctions.cs"
@using ScenarioTemplates
@ScenarioFunctions.Quote(Model.Name)

See the RazorLight manual for installation details, template sources, models, composition, includes, caching, encoding, precompilation, deployment, and troubleshooting examples.

Output and trust model

The core package writes expression results as plain text. Install Dijgrid.RazorLight.Html and call UseHtmlEncoding() when producing HTML, or implement IOutputEncoder for another format.

Razor templates and imported C# sources are executable .NET code with the host process's permissions. RazorLight is intended for application-owned or otherwise trusted templates. It is not an in-process sandbox for untrusted authors; see the template security guide.

Compatibility

  • Maintained projects, tests, samples, and generated code target .NET 10 and C# 14.
  • Runtime compilation requires dynamic code and a preserved compilation context. Trimming and Native AOT are not supported by the runtime compiler.
  • The generic core does not provide MVC tag helpers or built-in HTML contracts.
  • Public compatibility, language behavior, and deployment expectations are recorded in the repository documentation rather than inferred from the historical package.

Documentation

Project maintenance

Read CONTRIBUTING.md before contributing, use the repository's GitHub issue forms for reproducible bugs and focused proposals, and report vulnerabilities according to SECURITY.md. Accepted roadmap work is tracked in .planfs.

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (1)

Showing the top 1 NuGet packages that depend on Dijgrid.RazorLight:

Package Downloads
Dijgrid.RazorLight.Html

Optional HTML output encoding for the Dijgrid RazorLight generic C# template engine.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
3.0.1 163 8/20/2026
3.0.0 253 8/10/2026
3.0.0-beta.4 65 8/8/2026
3.0.0-beta.3 56 8/8/2026