App Model | Stable Channel | Preview Channel |
---|---|---|
Unified Package | - | |
Windows Forms | - | |
WPF | - |
Templates made available for working with Blazor components in desktop applications such as Windows Forms and WPF.
Also available in an unified template package.
Join me on Developer Thoughts, an exclusive blog for .NET MAUI and Blazor, for articles on working with these templates and much more.
Now published as Visual Studio 2022 Extension, can be downloaded from the VS Marketplace and then installed with VSIX installer or even an easy way, install and manage directly from within Visual Studio IDE itself (Extensions -> Manage Extensions or Alt + X + M
shortcut). To find this extension, search with the blazorwebview
keyword. Refer to the below screenshot.
The Blazor Desktop Templates Pack VS extension (v4.3.0.0 or higher) is now supported on both x64 and ARM64 installations of Visual Studio 2022. Happy coding!
Consequently, the minimum supported version of Visual Studio 2022 will be v17.6 or higher.
For CLI users, commands to install the project template:
Unified Template:
dotnet new install VijayAnand.BlazorTemplates
Can also be installed separately.
dotnet new install VijayAnand.WindowsForms.Blazor
dotnet new install VijayAnand.Wpf.Blazor
To update the template package:
dotnet new update --check-only
dotnet new update
And from v4.3.0 of the template package, support for XML-based solution file (slnx) format.
-
SLNX Solution File Format (Short notation:
-slnx
):Introduces support for the new, simplified, and easily understandable XML-based solution file format.
This would be an explicit option since the SLNX feature is currently in the preview stage and is only supported on VS2022.
-slnx
|--use-slnx
- Default value isfalse
.dotnet new winforms-blazor -o MyApp -slnx
dotnet new wpf-blazor -o MyApp -slnx
And from v4.4.0 of the template package, support for adding a reference to the MVVM toolkit.
-
Include MVVM Toolkit (Short notation:
-imt
):Introduces an option to add a reference to the CommunityToolkit.Mvvm NuGet package to work with MVVM.
-imt
|--include-mvvm-toolkit
- Default value isfalse
.dotnet new winforms-blazor -o MyApp -imt
dotnet new wpf-blazor -o MyApp -imt
Windows Forms: winforms-blazor
WPF: wpf-blazor
So, .NET CLI command to create a new project from your favorite terminal would be as follows:
By default, this creates a project that targets .NET 9
.
To create projects targeting different supported version of .NET, make use of the Framework parameter (--framework
| -f
) that takes net8.0
/ net9.0
as its options (with net9.0
being the default value, if not specified).
WinForms:
Being the default value, framework parameter is optional for .NET 9
.
dotnet new winforms-blazor
dotnet new winforms-blazor -f net8.0
WPF:
Being the default value, framework parameter is optional for .NET 9
.
dotnet new wpf-blazor
dotnet new wpf-blazor -f net8.0
Optionally, to abstract Razor components as a separate Razor Class Library (RCL), pass the below parameter while creating the project:
-rcl
| --razor-class-library
- Default value is false
For WinForms:
dotnet new winforms-blazor -rcl
For WPF:
dotnet new wpf-blazor -rcl
Optionally, to make use of NuGet Central Package Management (CPM) feature, pass the below parameter while creating the project (Supported from v3.5.0 onwards):
-cpm
| --central-pkg-mgmt
- Default value is false
For WinForms:
dotnet new winforms-blazor -cpm
For WPF:
dotnet new wpf-blazor -cpm
Project options can also be used in combination like -rcl
and -cpm
.
Has support for Item Templates too:
- Windows Form with BlazorWebView
- Named as
winforms-bwv
- Named as
- WPF Window with BlazorWebView
- Named as
wpf-bwv
- Named as
Both of these templates require a parameter:
-n
|--name
- The Name of the Item to create
Note:
Make sure the project dependencies are restored before creating a new item from these templates.
dotnet new winforms-bwv -n MyForm
dotnet new wpf-bwv -n MyWindow
To uninstall the template package:
dotnet new uninstall VijayAnand.BlazorTemplates
To run the project, it does depend on the WebView2 runtime, which can be downloaded from here:
https://developer.microsoft.com/en-us/microsoft-edge/webview2/#download-section
Or can easily be installed with Maui Check tool.
After installing the CLI template, optionally, this can be made available in the New Project
dialog within Visual Studio for an integrated experience.
Pro Tip: Search/Filter with the Blazor keyword to quickly locate these template in the VS Create Project dialog.