Categories
.NET .NET 8 .NET 9 .NET MAUI Blazor Desktop Developer Extensions General Getting Started Hybrid NuGet Templates Visual Studio VS Code Web What's New Windows Xamarin

.NET Blazor Hybrid – Windows Desktop Templates

Windows Forms and WPF are proven solid frameworks for creating high-performance Windows desktop client applications.

Blazor, a framework for full-stack web development with C# and Razor.

When these two technologies come together, then it’s certainly a delight for the .NET developers as it paves the way to leverage the skills they’re already familiar with and an option to modernize the existing applications.

Available as both a CLI Template and a VS Extension. Here’s the command to install the CLI part.

dotnet new install VijayAnand.BlazorTemplates

To install as VSIX, download and install from VS Marketplace or use the Extension Manager (shortcut: Alt+X+M) from within the Visual Studio IDE, search with blazorwebview keyword with the Online Tab in focus and look for Blazor Desktop Templates.

Blazor Desktop Templates for Windows Forms and WPF by Vijay Anand E G
Blazor Desktop Templates for Windows Forms and WPF

The pack hosts the following:

Project Templates:

  • Windows Forms Blazor App
    • And is named as winforms-blazor
  • WPF Blazor App
    • And is named as wpf-blazor

Both of these templates support creating projects for Target Frameworks .NET 6.NET 7, .NET 8, (the default value) and .NET 9.

On CLI, available as a parameter -f / --framework.

And within the IDE, as a drop-down list to select.

Windows Forms:

dotnet new winforms-blazor -o MyApp
dotnet new winforms-blazor -o MyApp -f net7.0

On .NET 9 Preview:

dotnet new winforms-blazor -o MyApp -f net9.0

WPF:

dotnet new wpf-blazor -o MyApp
dotnet new wpf-blazor -o MyApp -f net7.0

On .NET 9 Preview:

dotnet new wpf-blazor -o MyApp -f net9.0

Item Templates

Ensure the project is restored before making use of the item templates.

  • Windows Form with BlazorWebView
    • dotnet new winforms-bwv -n MyForm
  • WPF Window with BlazorWebView
    • dotnet new wpf-bwv -n MyWindow

Salient Features:

  • Option to use NuGet Central Package Management (CPM) feature (only on CLI for now)
    • dotnet new winforms-blazor -o MyApp -cpm
    • dotnet new wpf-blazor -o MyApp -cpm
  • Option to abstract Razor components as Razor Class Library (RCL) thus allowing for better reuse by adding them as a reference in other projects (also as a Checkbox in the IDE)
    • dotnet new winforms-blazor -o MyApp -rcl
    • dotnet new wpf-blazor -o MyApp -rcl
  • Option to restore/build Windows desktop projects on a non-Windows machine (only on CLI for now)
    • -ewt / --enable-windows-targeting

All these Project options can also be used in combination.

Documentation is available here. If you find any issues or features to suggest, feel free to raise an issue with appropriate details here. Ideas are most welcome.

If you find these extensions useful, kindly support the work by adding your review to the VS Marketplace and also by adding a Star to the GitHub repository where it’s actively cooked. Also, share the word with your team and inner circle.

And a considerable amount of my time is spent on adding new features to the templates pack if you would like to recognize the work and sustain the momentum, kindly consider sponsoring the project in GitHub here. Thanks in advance.

Happy coding. Stay connected as we continue to learn and share the experiences from this exciting journey of being a .NET developer.

By Vijay Anand E G

A software professional with over a decade long industry experience in developing products that spans across desktop, mobile, and web.