PosInformatique.Foundations.Text.Templating
1.4.0-rc.3
Prefix Reserved
dotnet add package PosInformatique.Foundations.Text.Templating --version 1.4.0-rc.3
NuGet\Install-Package PosInformatique.Foundations.Text.Templating -Version 1.4.0-rc.3
<PackageReference Include="PosInformatique.Foundations.Text.Templating" Version="1.4.0-rc.3" />
<PackageVersion Include="PosInformatique.Foundations.Text.Templating" Version="1.4.0-rc.3" />
<PackageReference Include="PosInformatique.Foundations.Text.Templating" />
paket add PosInformatique.Foundations.Text.Templating --version 1.4.0-rc.3
#r "nuget: PosInformatique.Foundations.Text.Templating, 1.4.0-rc.3"
#:package PosInformatique.Foundations.Text.Templating@1.4.0-rc.3
#addin nuget:?package=PosInformatique.Foundations.Text.Templating&version=1.4.0-rc.3&prerelease
#tool nuget:?package=PosInformatique.Foundations.Text.Templating&version=1.4.0-rc.3&prerelease
PosInformatique.Foundations.Text.Templating
Introduction
This package provides a small abstraction to generate text from templates, independently of the underlying templating engine.
It defines the TextTemplate<TModel> base class and the ITextTemplateRenderContext interface, which can be implemented by concrete template engines.
Currently only the following text engine implementations are provided in PosInformatique.Foundations:
- PosInformatique.Foundations.Text.Templating.Razor
- PosInformatique.Foundations.Text.Templating.Scriban
Install
You can install the package from NuGet:
dotnet add package PosInformatique.Foundations.Text.Templating
Features
- Abstraction to represent a text template with a strongly-typed model:
TextTemplate<TModel> - Asynchronous rendering API through
RenderAsync - Pluggable rendering context via
ITextTemplateRenderContextto access services during template execution - Engine-agnostic design: can be used with different template engines (Razor, etc.)
ConstantTextTemplate<TModel>implementation to generate a constant (fixed) text, regardless of the data model
Usage
This package only provides the abstraction (base classes and interfaces). To actually render templates using Razor components, use one of the dedicated implementation packages:
- PosInformatique.Foundations.Text.Templating.Razor
- PosInformatique.Foundations.Text.Templating.Scriban
Trimming and Native AOT
The implementations of TextTemplate<TModel> (Razor, Scriban,...) access the members of the TModel model through reflection.
The trimmer cannot detect this usage statically, so when your application is published with trimming or Native AOT enabled,
the model type and its members can be removed, which causes errors at runtime.
The TModel type passed to RenderAsync() must therefore be preserved by the application using the DynamicDependencyAttribute.
Apply it on the method (or the class) which calls RenderAsync(), and reference the model type:
using System.Diagnostics.CodeAnalysis;
public class MyEmailModel
{
public string UserName { get; set; }
public DateTime Now { get; set; }
}
public class EmailSender
{
[DynamicDependency(DynamicallyAccessedMemberTypes.All, typeof(MyEmailModel))]
[UnconditionalSuppressMessage("Trimming", "IL2026", Justification = "MyEmailModel is preserved by the DynamicDependency attribute.")]
public async Task SendAsync(TextTemplate<MyEmailModel> template, MyEmailModel model, TextWriter writer, ITextTemplateRenderContext context)
{
await template.RenderAsync(model, writer, context);
}
}
Notes:
- Every type of the model graph accessed by the template (nested objects, items of collections,...) must be preserved as well, by adding one
DynamicDependencyAttributeper type. RenderAsync()is annotated withRequiresUnreferencedCode: without theUnconditionalSuppressMessage(orRequiresUnreferencedCodeon your own method), the trimming analyzer raises theIL2026warning on the call.
Links
| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net8.0 is compatible. net8.0-android was computed. net8.0-browser was computed. net8.0-ios was computed. net8.0-maccatalyst was computed. net8.0-macos was computed. net8.0-tvos was computed. net8.0-windows was computed. net9.0 is compatible. net9.0-android was computed. net9.0-browser was computed. net9.0-ios was computed. net9.0-maccatalyst was computed. net9.0-macos was computed. net9.0-tvos was computed. net9.0-windows was computed. 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. |
-
net10.0
- No dependencies.
-
net8.0
- No dependencies.
-
net9.0
- No dependencies.
NuGet packages (3)
Showing the top 3 NuGet packages that depend on PosInformatique.Foundations.Text.Templating:
| Package | Downloads |
|---|---|
|
PosInformatique.Foundations.Emailing
Provides a lightweight, template-based emailing infrastructure for .NET. Allows registering strongly-typed email templates, instantiating emails from models, and sending them through pluggable providers (e.g. Azure Communication Service). |
|
|
PosInformatique.Foundations.Text.Templating.Razor
Provides Razor-based text templating using Blazor components. Allows generating text from Razor components with a strongly-typed Model parameter and full integration with the application's dependency injection (IServiceProvider). |
|
|
PosInformatique.Foundations.Text.Templating.Scriban
Provides Scriban-based text templating with mustache-style syntax. Allows generating text from Scriban templates with a strongly-typed Model and automatic property exposure using simple {{ }} syntax. |
GitHub repositories
This package is not used by any popular GitHub repositories.
| Version | Downloads | Last Updated |
|---|---|---|
| 1.4.0-rc.3 | 106 | 10/14/2026 |
| 1.4.0-rc.2 | 109 | 10/6/2026 |
| 1.4.0-rc.1 | 83 | 10/5/2026 |
| 1.3.0 | 234 | 10/2/2026 |
| 1.3.0-rc.4 | 101 | 9/29/2026 |
| 1.3.0-rc.3 | 96 | 9/28/2026 |
| 1.3.0-rc.2 | 90 | 9/25/2026 |
| 1.3.0-rc.1 | 111 | 9/23/2026 |
| 1.2.0 | 276 | 8/18/2026 |
| 1.1.0 | 273 | 3/30/2026 |
| 1.0.0 | 611 | 11/19/2025 |
1.4.0
- Added the `ConstantTextTemplate<TModel>` implementation to generate a constant (fixed) text.
1.0.0
- Initial release with base text templating infrastructure.