Skip to content

egvijayanand/blazor-project-templates

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Blazor Desktop Project Templates

Blazor desktop project templates for Windows Forms and WPF

App Model Stable Channel Preview Channel
Unified Package Blazor NuGet Stable Package
Blazor Desktop Templates - VS Marketplace
-
Windows Forms WinForms Blazor Stable Package -
WPF WPF Blazor Stable Package -

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.

Visual Studio – Manage Extensions (Blazor Desktop Templates in focus)

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

Project names referenced by these templates:

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 8.

To create projects targeting different supported version of .NET, make use of the Framework parameter (--framework | -f) that takes net6.0 / net7.0 / net8.0 / net9.0 as its options (with net8.0 being the default value, if not specified).

WinForms:

Being the default value, framework parameter is optional for .NET 8.

dotnet new winforms-blazor -f net8.0
dotnet new winforms-blazor -f net9.0
dotnet new winforms-blazor -f net7.0
dotnet new winforms-blazor -f net6.0

WPF:

Being the default value, framework parameter is optional for .NET 8.

dotnet new wpf-blazor -f net8.0
dotnet new wpf-blazor -f net9.0
dotnet new wpf-blazor -f net7.0
dotnet new wpf-blazor -f net6.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
  • WPF Window with BlazorWebView
    • Named as wpf-bwv

Both of these templates require a parameter:

  • -n | --name - The Name of the Item to create

Note:

Ensure the project dependencies are restored before creating 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.

Templates within Visual Studio

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.

Blazor Desktop Project Templates within Visual Studio 2022