Svg.CodeGen.Skia turns the intermediate ShimSkiaSharp.SKPicture model into C# source code. It is the package to choose when SVG parsing should happen ahead of time and the final application should ship compiled SKPicture builders instead of raw .svg files.
dotnet add package Svg.CodeGen.Skia
ShimSkiaSharp.SKPicture.| Type | Role |
|---|---|
SkiaCSharpCodeGen |
Generates C# source from a ShimSkiaSharp.SKPicture |
The generated class includes:
Picture property,Draw(SKCanvas) method,SkiaCSharpCodeGen.Generate(...)..cs file.using System.IO;
using Svg.CodeGen.Skia;
using Svg.Skia;
using var svg = new SKSvg();
if (svg.Load("Assets/icon.svg") is not null && svg.Model is not null)
{
var code = SkiaCSharpCodeGen.Generate(svg.Model, "MyApp.Generated", "Icon");
File.WriteAllText("Generated/Icon.g.cs", code);
}
This example uses Svg.Skia to create the intermediate model, but Svg.CodeGen.Skia itself only needs a ShimSkiaSharp.SKPicture.
Choose Svg.CodeGen.Skia when generation is an explicit build step and you want control over:
Choose Svg.SourceGenerator.Skia when SVG files already live in the consuming project and implicit build-time generation is the better experience.
svgc.