Ecosyste.ms: Awesome

An open API service indexing awesome lists of open source software.

Awesome Lists | Featured Topics | Projects

https://github.com/egvijayanand/blazor-project-templates

.NET Blazor Hybrid Windows desktop project templates
https://github.com/egvijayanand/blazor-project-templates

blazor blazorwebview client csharp desktop dotnet dotnet6 dotnet7 dotnet8 dotnet9 hybrid modernization razor templates web windows windowsforms winforms wpf

Last synced: 5 days ago
JSON representation

.NET Blazor Hybrid Windows desktop project templates

Awesome Lists containing this project

README

        

## Blazor Desktop Project Templates

### Blazor desktop project templates for Windows Forms and WPF

|App Model|Stable Channel|Preview Channel|
|:---:|:---:|:---:|
|[Unified Package](https://www.nuget.org/packages/VijayAnand.BlazorTemplates/)|[![Blazor NuGet Stable Package](https://badgen.net/nuget/v/VijayAnand.BlazorTemplates/?icon=nuget&foo=bar)](https://www.nuget.org/packages/VijayAnand.BlazorTemplates/)
[![Blazor Desktop Templates - VS Marketplace](https://badgen.net/vs-marketplace/v/egvijayanand.blazor-desktop-templates?icon=visualstudio&foo=bar)](https://marketplace.visualstudio.com/items?itemName=egvijayanand.blazor-desktop-templates)| - |
|[Windows Forms](https://www.nuget.org/packages/VijayAnand.WindowsForms.Blazor/)|[![WinForms Blazor Stable Package](https://badgen.net/nuget/v/VijayAnand.WindowsForms.Blazor/?icon=nuget&foo=bar)](https://www.nuget.org/packages/VijayAnand.WindowsForms.Blazor/)| - |
|[WPF](https://www.nuget.org/packages/VijayAnand.Wpf.Blazor/)|[![WPF Blazor Stable Package](https://badgen.net/nuget/v/VijayAnand.Wpf.Blazor/?icon=nuget&foo=bar)](https://www.nuget.org/packages/VijayAnand.Wpf.Blazor/)| - |

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**](https://egvijayanand.in/), 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](https://marketplace.visualstudio.com/items?itemName=egvijayanand.blazor-desktop-templates) 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.*

![Visual Studio – Manage Extensions (Blazor Desktop Templates in focus)](./images/vs-manage-extensions.png)

For CLI users, commands to install the project template:

Unified Template:

```shell
dotnet new install VijayAnand.BlazorTemplates
```

Can also be installed separately.

```shell
dotnet new install VijayAnand.WindowsForms.Blazor
```

```shell
dotnet new install VijayAnand.Wpf.Blazor
```

To update the template package:

```shell
dotnet new update --check-only
```
```shell
dotnet new update
```

And from [v4.3.0](https://www.nuget.org/packages/VijayAnand.BlazorTemplates/4.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 is `false`.

```shell
dotnet new winforms-blazor -o MyApp -slnx
```

```shell
dotnet new wpf-blazor -o MyApp -slnx
```

And from [v4.4.0](https://www.nuget.org/packages/VijayAnand.BlazorTemplates/4.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](https://www.nuget.org/packages/CommunityToolkit.Mvvm) NuGet package to work with MVVM.

`-imt` | `--include-mvvm-toolkit` - Default value is `false`.

```shell
dotnet new winforms-blazor -o MyApp -imt
```

```shell
dotnet new wpf-blazor -o MyApp -imt
```

#### 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`.

```shell
dotnet new winforms-blazor -f net8.0
```

```shell
dotnet new winforms-blazor -f net9.0
```

```shell
dotnet new winforms-blazor -f net7.0
```

```shell
dotnet new winforms-blazor -f net6.0
```

WPF:

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

```shell
dotnet new wpf-blazor -f net8.0
```

```shell
dotnet new wpf-blazor -f net9.0
```

```shell
dotnet new wpf-blazor -f net7.0
```

```shell
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:

```shell
dotnet new winforms-blazor -rcl
```

For WPF:

```shell
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:

```shell
dotnet new winforms-blazor -cpm
```

For WPF:

```shell
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.*

```shell
dotnet new winforms-bwv -n MyForm
```

```shell
dotnet new wpf-bwv -n MyWindow
```

To uninstall the template package:

```shell
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](https://github.com/Redth/dotnet-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](./images/blazor-desktop-templates.png)