Creating a WPF with MudBlazor Project Template and Multi-Project Template Packaging
WPF and MudBlazor Integration Template
This template facilitates the creation of .NET 8 WPF applications integrated with MudBlazor components, compatible with Visual Studio 2022.
Template Packaging Process
1. Project Structure Preparation
Create a base project (e.g., WpfMudBlazor) containing your desired WPF+MudBlazor implementation. This serves as the foundation for your template.
2. Template Token Replacement
Create a duplicate project (TemplateCode) where you replace specific identifiers with Visual Studio template tokens:
<Project Sdk="Microsoft.NET.Sdk.Razor">
<PropertyGroup>
<OutputType>WinExe</OutputType>
<TargetFramework>net8.0-windows</TargetFramework>
<RootNamespace>$safeprojectname$</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="Microsoft.AspNetCore.Components.WebView.Wpf" Version="8.0.6" />
</ItemGroup>
</Project>
namespace $safeprojectname$
{
public partial class MainWindow : Window
{
public MainWindow()
{
InitializeComponent();
InitializeBlazor();
}
}
}
3. Multi-Project Template Assembly
- Export each project as individual tepmlates through VS's Export Template feature
- Create a master
.vstemplatefile referencing all components:
<VSTemplate Version="3.0.0" Type="ProjectGroup" xmlns="http://schemas.microsoft.com/developer/vstemplate/2005">
<TemplateData>
<Name>WPF with MudBlazor</Name>
<Description>.NET 8 WPF application with MudBlazor integration</Description>
</TemplateData>
<TemplateContent>
<ProjectCollection>
<ProjectTemplateLink ProjectName="$safeprojectname$">
WpfMudBlazor/Template.vstemplate
</ProjectTemplateLink>
<ProjectTemplateLink ProjectName="$safeprojectname$.Pages">
WpfMudBlazor.Pages/Template.vstemplate
</ProjectTemplateLink>
</ProjectCollection>
</TemplateContent>
</VSTemplate>
- Mark child templates as hidden in their respective
.vstemplatefiles:
<TemplateData>
<Hidden>true</Hidden>
</TemplateData>
- Package all files into a single ZIP archive
4. VSIX Extension Packaging (Optional)
- Create a new VSIX Project in Visual Studio
- Include your template ZIP as content (set to Copy Always)
- Configure
source.extension.vsixmanifestwith:- Metadata (name, description, version)
- Assets (template file reference)
- Installation targets (VS version requirements)
- Build to generate distributable VSIX package