![]() |
VOOZH | about |
dotnet add package Mono.TextTemplating --version 3.0.0
NuGet\Install-Package Mono.TextTemplating -Version 3.0.0
<PackageReference Include="Mono.TextTemplating" Version="3.0.0" />
<PackageVersion Include="Mono.TextTemplating" Version="3.0.0" />Directory.Packages.props
<PackageReference Include="Mono.TextTemplating" />Project file
paket add Mono.TextTemplating --version 3.0.0
#r "nuget: Mono.TextTemplating, 3.0.0"
#:package Mono.TextTemplating@3.0.0
#addin nuget:?package=Mono.TextTemplating&version=3.0.0Install as a Cake Addin
#tool nuget:?package=Mono.TextTemplating&version=3.0.0Install as a Cake Tool
NOTE: To use a template at runtime in your app, you do not need to host the engine. It is generally preferable to use
dotnet-t4to generate a runtime template class and compile that into your app, as this has substantially less overhead than hosting the engine.
Mono.TextTemplating is an open-source reimplementation of the Visual Studio T4 text templating engine, and supports C# 10 and .NET 6. This package is the engine package, which can be used to host the T4 engine in your own app.
By default the engine uses the C# compiler from the .NET SDK, but the Mono.TextTemplating.Roslyn package can be used to bundle a copy of the Roslyn C# compiler and host it in-process. This may improve template compilation performance when compiling multiple templates, and guarantees a specific version of the compiler.
This will read a template from templateFile, compile and process it, and write the output to outputFile:
var generator = new TemplateGenerator ();
bool success = await generator.ProcessTemplateAsync (templateFilename, outputFilename);
This does the same thing as a series of lower-level steps, allowing it to provide additional compiler arguments by modifying the TemplateSettings:
string templateContent = File.ReadAllText (templateFilename);
var generator = new TemplateGenerator ();
ParsedTemplate parsed = generator.ParseTemplate (templateFilename, templateContent);
TemplateSettings settings = TemplatingEngine.GetSettings (generator, parsed);
settings.CompilerOptions = "-nullable:enable";
(string generatedFilename, string generatedContent) = await generator.ProcessTemplateAsync (
parsed, inputFilename, inputContent, outputFilename, settings
);
File.WriteAllText (generatedFilename, generatedContent);
In most cases, you need only use or subclass TemplateGenerator:
ITextTemplatingEngineHost and ITextTemplatingSessionHost with a default implementation that can be overridden if needed.TemplateEngine instance and provides simplified ProcessTemplateAsync() and PreprocessTemplateAsync() methods.Mono.TextTemplating has session, host and directive processor interfaces and classes in the Microsoft.VisualStudio.TextTemplating namespace that are near-identical to the original Visual Studio T4 implementation. This allows older T4 templates and directive processors to work with Mono.TextTemplating with few (if any) changes.
ITextTemplatingEngineHostITextTemplatingSessionHost, ITextTemplatingSession, TextTemplatingSessionIDirectiveProcessor, IRecognizeHostSpecific, DirectiveProcessor, DirectiveProcessorException, RequiresProvidesDirectiveProcessor, ParameterDirectiveProcessorThe Microsoft.VisualStudio.TextTemplating.(ITextTemplatingEngine,Engine) hosting API is supported but deprecated.
For advanced use, some lower level classes and methods are accessible:
TemplatingEngine: generates C# classes from T4 templates and compiles them into assembliesTemplateGenerator.ParseTemplate(): uses a Tokenizer to parse a template string into a ParsedTemplateTokenizer: tokenizes an T4 input streamParsedTemplate: provides direct access to the segments and directives of a parsed templateTemplatingEngine.GetSettings(): uses the directives in a ParsedTemplate to initialize a TemplateSettingsTemplateSettings: settings that control code generation and compilation.CompiledTemplate: a template that has been compiled but not executedThe Mono.TextTemplating engine contains many improvements over the original Visual Studio T4 implementation, including:
AssemblyLoadContext, which allows the generated assemblies to be garbage collected (where supported)<#@ parameter name="Foo" type="int" #>| Product | Versions Compatible and additional computed target framework versions. |
|---|---|
| .NET | net5.0 net5.0 was computed. net5.0-windows net5.0-windows was computed. net6.0 net6.0 is compatible. net6.0-android net6.0-android was computed. net6.0-ios net6.0-ios was computed. net6.0-maccatalyst net6.0-maccatalyst was computed. net6.0-macos net6.0-macos was computed. net6.0-tvos net6.0-tvos was computed. net6.0-windows net6.0-windows was computed. net7.0 net7.0 was computed. net7.0-android net7.0-android was computed. net7.0-ios net7.0-ios was computed. net7.0-maccatalyst net7.0-maccatalyst was computed. net7.0-macos net7.0-macos was computed. net7.0-tvos net7.0-tvos was computed. net7.0-windows net7.0-windows was computed. net8.0 net8.0 was computed. net8.0-android net8.0-android was computed. net8.0-browser net8.0-browser was computed. net8.0-ios net8.0-ios was computed. net8.0-maccatalyst net8.0-maccatalyst was computed. net8.0-macos net8.0-macos was computed. net8.0-tvos net8.0-tvos was computed. net8.0-windows net8.0-windows was computed. net9.0 net9.0 was computed. net9.0-android net9.0-android was computed. net9.0-browser net9.0-browser was computed. net9.0-ios net9.0-ios was computed. net9.0-maccatalyst net9.0-maccatalyst was computed. net9.0-macos net9.0-macos was computed. net9.0-tvos net9.0-tvos was computed. net9.0-windows net9.0-windows was computed. net10.0 net10.0 was computed. net10.0-android net10.0-android was computed. net10.0-browser net10.0-browser was computed. net10.0-ios net10.0-ios was computed. net10.0-maccatalyst net10.0-maccatalyst was computed. net10.0-macos net10.0-macos was computed. net10.0-tvos net10.0-tvos was computed. net10.0-windows net10.0-windows was computed. |
| .NET Core | netcoreapp2.0 netcoreapp2.0 was computed. netcoreapp2.1 netcoreapp2.1 was computed. netcoreapp2.2 netcoreapp2.2 was computed. netcoreapp3.0 netcoreapp3.0 was computed. netcoreapp3.1 netcoreapp3.1 was computed. |
| .NET Standard | netstandard2.0 netstandard2.0 is compatible. netstandard2.1 netstandard2.1 was computed. |
| .NET Framework | net461 net461 was computed. net462 net462 was computed. net463 net463 was computed. net47 net47 was computed. net471 net471 was computed. net472 net472 is compatible. net48 net48 was computed. net481 net481 was computed. |
| MonoAndroid | monoandroid monoandroid was computed. |
| MonoMac | monomac monomac was computed. |
| MonoTouch | monotouch monotouch was computed. |
| Tizen | tizen40 tizen40 was computed. tizen60 tizen60 was computed. |
| Xamarin.iOS | xamarinios xamarinios was computed. |
| Xamarin.Mac | xamarinmac xamarinmac was computed. |
| Xamarin.TVOS | xamarintvos xamarintvos was computed. |
| Xamarin.WatchOS | xamarinwatchos xamarinwatchos was computed. |
Showing the top 5 NuGet packages that depend on Mono.TextTemplating:
| Package | Downloads |
|---|---|
|
Microsoft.EntityFrameworkCore.Design
Shared design-time components for Entity Framework Core tools. |
|
|
Microsoft.DotNet.Scaffolding.Shared
Contains interfaces for Project Model and messaging for scaffolding. |
|
|
Microsoft.EntityFrameworkCore.Specification.Tests
Shared test suite for Entity Framework Core database providers. |
|
|
Microsoft.EntityFrameworkCore.Relational.Specification.Tests
Shared test suite for Entity Framework Core relational database providers. |
|
|
dotnet-t4-project-tool
Project tool for processing T4 templates, a general-purpose way to generate text or code files using C# |
Showing the top 7 popular GitHub repositories that depend on Mono.TextTemplating:
| Repository | Stars |
|---|---|
|
dotnet/efcore
EF Core is a modern object-database mapper for .NET. It supports LINQ queries, change tracking, updates, and schema migrations.
|
|
|
linq2db/linq2db
Linq to database provider.
|
|
|
mono/monodevelop
MonoDevelop is a cross platform .NET IDE
|
|
|
ErikEJ/EFCorePowerTools
Entity Framework Core Power Tools - reverse engineering, migrations and model visualization in Visual Studio & CLI
|
|
|
dotnet/dotnet
Home of .NET's Virtual Monolithic Repository which includes all the code needed to build the .NET SDK.
|
|
|
dotnet/Scaffolding
Code generators to speed up development.
|
|
|
microsoftgraph/MSGraph-SDK-Code-Generator
MSGraph SDK Code Generator
|
| Version | Downloads | Last Updated |
|---|---|---|
| 3.0.0 | 136,568,385 | 9/3/2024 |
| 3.0.0-preview-0052-g5d0f76c785 | 377,310 | 2/28/2024 |
| 3.0.0-preview-0049-g4f33c8d8b1 | 1,100 | 1/27/2024 |
| 3.0.0-preview-0045-g9b6fc72764 | 113,418 | 1/23/2024 |
| 3.0.0-preview-0027-g2711105671 | 3,396 | 10/3/2023 |
| 2.3.1 | 33,250,189 | 10/28/2022 |
| 2.3.0 | 20,706 | 10/5/2022 |
| 2.2.1 | 283,698,832 | 2/23/2021 |
| 2.2.0 | 43,470 | 12/5/2020 |
| 2.0.5 | 170,566 | 6/13/2019 |
| 2.0.4 | 14,255 | 4/4/2019 |
| 2.0.3 | 8,704 | 3/7/2019 |
| 2.0.2 | 8,770 | 12/14/2018 |
| 2.0.1 | 6,130 | 12/14/2018 |
| 2.0.0 | 6,083 | 12/13/2018 |
| 1.3.1 | 268,868 | 3/31/2017 |
| 1.3.0 | 58,555 | 3/17/2017 |
| 1.2.0 | 6,549 | 3/17/2017 |