Deepstaging.Roslyn.Scriban 1.0.0-dev-20260210010244

This is a prerelease version of Deepstaging.Roslyn.Scriban.
The owner has unlisted this package. This could mean that the package is deprecated, has security vulnerabilities or shouldn't be used anymore.
dotnet add package Deepstaging.Roslyn.Scriban --version 1.0.0-dev-20260210010244
                    
NuGet\Install-Package Deepstaging.Roslyn.Scriban -Version 1.0.0-dev-20260210010244
                    
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="Deepstaging.Roslyn.Scriban" Version="1.0.0-dev-20260210010244" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Deepstaging.Roslyn.Scriban" Version="1.0.0-dev-20260210010244" />
                    
Directory.Packages.props
<PackageReference Include="Deepstaging.Roslyn.Scriban" />
                    
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 Deepstaging.Roslyn.Scriban --version 1.0.0-dev-20260210010244
                    
#r "nuget: Deepstaging.Roslyn.Scriban, 1.0.0-dev-20260210010244"
                    
#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 Deepstaging.Roslyn.Scriban@1.0.0-dev-20260210010244
                    
#: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=Deepstaging.Roslyn.Scriban&version=1.0.0-dev-20260210010244&prerelease
                    
Install as a Cake Addin
#tool nuget:?package=Deepstaging.Roslyn.Scriban&version=1.0.0-dev-20260210010244&prerelease
                    
Install as a Cake Tool

Deepstaging.Roslyn.Scriban

Scriban template infrastructure for Roslyn incremental source generators.

📚 Full Documentation

**See also: ** Roslyn Toolkit | Testing

What is this?

This library provides a convenient way to use Scriban templates in Roslyn source generators. Instead of building C# strings manually, you write .scriban-cs templates and render them with model objects.

Quick Start

1. Create a template

Add a .scriban-cs file as an embedded resource:

// {{ model.name }}.g.cs
// <auto-generated/>
#nullable enable

namespace {{ model.namespace }};

public partial class {{ model.name }}
{
{{~ for prop in model.properties ~}}
    public {{ prop.type }} {{ prop.name }} { get; set; }
{{~ end ~}}
}

2. Set up the template name factory

public class MyGenerator : IIncrementalGenerator
{
    private static readonly Func<string, TemplateName> Named = 
        TemplateName.ForGenerator<MyGenerator>();
    
    // ...
}

3. Render and add to output

context.AddFromTemplate(
    Named("MyTemplate.scriban-cs"),
    hintName: $"{model.Name}.g.cs",
    context: model);

API Reference

TemplateName

Identifies a template by its embedded resource name and assembly:

// Create a factory for your generator's namespace
var Named = TemplateName.ForGenerator<MyGenerator>();

// Creates: "MyNamespace.Templates.MyTemplate.scriban-cs"
var templateName = Named("MyTemplate.scriban-cs");

Template

Loads and renders Scriban templates from embedded resources:

// Render directly
var result = Template.RenderTemplate(templateName, model);

switch (result)
{
    case RenderResult.Success success:
        string code = success.Text;
        break;
    case RenderResult.Failure failure:
        Diagnostic error = failure.Diagnostic;
        break;
}

Context Extensions

Extension methods for generator contexts:

// In SourceProductionContext (main generation phase)
context.AddFromTemplate(
    Named("Template.scriban-cs"),
    hintName,
    context: model,
    diagnostics: optionalDiagnosticList,
    format: true);  // Optional: format with Roslyn

// In IncrementalGeneratorPostInitializationContext (static output)
context.AddFromTemplate(
    Named("StaticTemplate.scriban-cs"),
    hintName,
    context: model);

Template Conventions

File Extension

Templates use .scriban-cs extension and are embedded resources:

<ItemGroup>
  <EmbeddedResource Include="Templates\*.scriban-cs" />
</ItemGroup>

Directory Structure

Templates live in a Templates/ directory next to your generator:

MyProject/
├── MyGenerator.cs
└── Templates/
    ├── Class.scriban-cs
    └── Interface.scriban-cs

Snake Case Access

Model properties are automatically accessible in snake_case:

// C# model
record MyModel(string FullName, int MaxRetries);
{{ model.full_name }}     # Accesses FullName
{{ model.max_retries }}   # Accesses MaxRetries

Performance

Templates are cached at two levels:

  1. Text cache - Embedded resource text is cached by (Assembly, ResourceName)
  2. Parse cache - Parsed Scriban templates are cached by template text

This avoids repeated I/O and parsing during incremental generation, which is critical for IDE responsiveness.

Error Handling

Template errors produce Roslyn diagnostics with ID DEEPCORE001:

Scenario Message Format
Parse error ParsingError occurred while rendering a template: {errors}
Render error {ExceptionType} occurred while rendering a template: {message}

Errors are reported via SourceProductionContext.ReportDiagnostic() so they appear in the IDE.

License

RPL-1.5 (Reciprocal Public License) — Real reciprocity, no loopholes.

You can use this code, modify it, and share it freely. But when you deploy it — internally or externally, as a service or within your company — you share your improvements back under the same license.

Why? We believe if you benefit from this code, the community should benefit from your improvements. That's the deal we think is fair.

Personal research and experimentation? No obligations. Go learn, explore, and build.

See LICENSE for the full legal text.

Product Compatible and additional computed target framework versions.
.NET net5.0 was computed.  net5.0-windows was computed.  net6.0 was computed.  net6.0-android was computed.  net6.0-ios was computed.  net6.0-maccatalyst was computed.  net6.0-macos was computed.  net6.0-tvos was computed.  net6.0-windows was computed.  net7.0 was computed.  net7.0-android was computed.  net7.0-ios was computed.  net7.0-maccatalyst was computed.  net7.0-macos was computed.  net7.0-tvos was computed.  net7.0-windows was computed.  net8.0 was computed.  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 was computed.  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 was computed.  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. 
.NET Core netcoreapp2.0 was computed.  netcoreapp2.1 was computed.  netcoreapp2.2 was computed.  netcoreapp3.0 was computed.  netcoreapp3.1 was computed. 
.NET Standard netstandard2.0 is compatible.  netstandard2.1 was computed. 
.NET Framework net461 was computed.  net462 was computed.  net463 was computed.  net47 was computed.  net471 was computed.  net472 was computed.  net48 was computed.  net481 was computed. 
MonoAndroid monoandroid was computed. 
MonoMac monomac was computed. 
MonoTouch monotouch was computed. 
Tizen tizen40 was computed.  tizen60 was computed. 
Xamarin.iOS xamarinios was computed. 
Xamarin.Mac xamarinmac was computed. 
Xamarin.TVOS xamarintvos was computed. 
Xamarin.WatchOS xamarinwatchos was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
Loading failed