Base16.Svg.BuildTasks 1.0.0

Contains a build task for generating DrawingVisuals used in WPF from SVG-files at compile time.

Install-Package Base16.Svg.BuildTasks -Version 1.0.0
dotnet add package Base16.Svg.BuildTasks --version 1.0.0
<PackageReference Include="Base16.Svg.BuildTasks" Version="1.0.0" />
For projects that support PackageReference, copy this XML node into the project file to reference the package.
paket add Base16.Svg.BuildTasks --version 1.0.0
The NuGet Team does not provide support for this client. Please contact its maintainers for support.

Base16.Svg.BuildTasks

This package adds a custom build task that generates DrawingVisuals from SVG-files (Scalable Vector Graphics) which can then be directly used and referenced in WPF (Windows Presentation Foundation) applications.

This simplifies the process of creating a scalable UI using SVGs.

By adding a reference to this package all SVG-files in the referencing project will get a DrawingVisual generated with the same name as the SVG-file and a namespace that corresponds to the files location in the project structure.

Since this approach uses code-generation no additional runtime dependencies are required.

Getting Started

  1. Create a new WPF application and call it WpfSvgTestApp using either .NET Core or .NET Framework
  2. Add a reference to this NuGet-package
  3. Create a new folder in your project called Svg
  4. Add any SVG-file that you might have to the Svg folder (see known issues) and name the file MySvg.svg
  5. Verify that Build Action for the SVG-file is set to Svg Visual/SvgVisual
  6. Open MainWindow.xaml and replace the content with the following
<Window x:Class="WpfSvgTestApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfSvgTestApp"
        xmlns:Svg="clr-namespace:WpfSvgTestApp.Svg"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.Background>
            <VisualBrush Stretch="Uniform">
                <VisualBrush.Visual>
                    <Svg:MySvg />
                </VisualBrush.Visual>
            </VisualBrush>
        </Grid.Background>
    </Grid>
</Window>

  1. Compile and run the application

Known issues

  • If Svg Visual/SvgVisual is not available as Build Action after first adding this package simple unload and reload the project/solution
  • Symbols are currently not handled - only the "root visual" will get processed - this might change
  • "CSS type styles" are not handled
  • "Advanced masks" are not handled
  • Filenames are not mangled/normalized/cleaned - the name of the file will be used as the name of the generated DrawingVisual (excluding extension)
  • ...

Change log

Version 1.0.0

Initial release.

Base16.Svg.BuildTasks

This package adds a custom build task that generates DrawingVisuals from SVG-files (Scalable Vector Graphics) which can then be directly used and referenced in WPF (Windows Presentation Foundation) applications.

This simplifies the process of creating a scalable UI using SVGs.

By adding a reference to this package all SVG-files in the referencing project will get a DrawingVisual generated with the same name as the SVG-file and a namespace that corresponds to the files location in the project structure.

Since this approach uses code-generation no additional runtime dependencies are required.

Getting Started

  1. Create a new WPF application and call it WpfSvgTestApp using either .NET Core or .NET Framework
  2. Add a reference to this NuGet-package
  3. Create a new folder in your project called Svg
  4. Add any SVG-file that you might have to the Svg folder (see known issues) and name the file MySvg.svg
  5. Verify that Build Action for the SVG-file is set to Svg Visual/SvgVisual
  6. Open MainWindow.xaml and replace the content with the following
<Window x:Class="WpfSvgTestApp.MainWindow"
        xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
        xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
        xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
        xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
        xmlns:local="clr-namespace:WpfSvgTestApp"
        xmlns:Svg="clr-namespace:WpfSvgTestApp.Svg"
        mc:Ignorable="d"
        Title="MainWindow" Height="450" Width="800">
    <Grid>
        <Grid.Background>
            <VisualBrush Stretch="Uniform">
                <VisualBrush.Visual>
                    <Svg:MySvg />
                </VisualBrush.Visual>
            </VisualBrush>
        </Grid.Background>
    </Grid>
</Window>

  1. Compile and run the application

Known issues

  • If Svg Visual/SvgVisual is not available as Build Action after first adding this package simple unload and reload the project/solution
  • Symbols are currently not handled - only the "root visual" will get processed - this might change
  • "CSS type styles" are not handled
  • "Advanced masks" are not handled
  • Filenames are not mangled/normalized/cleaned - the name of the file will be used as the name of the generated DrawingVisual (excluding extension)
  • ...

Change log

Version 1.0.0

Initial release.

  • .NETFramework 4.7.1

    • No dependencies.
  • .NETStandard 2.1

    • No dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version History

Version Downloads Last updated
1.0.0 235 2/2/2020