Introducing CleanBlazor 🧽🧼🧹
Problem
- You want to start a new Blazor project from scratch.
- You want the bare minimum amount of code to get started.
- That means no Counter.razor, SurverPrompt.razor, Boostrap, extra css files, etc.
- You use the Visual Studio or dotnet CLI out-of-the-box Blazor project templates to create a new project.
- Now you have to strip out all of the sample code the template provides.
- You waste time ⏱. You get older 👴.
Solution
CLEAN BLAZOR! 🧽🧼🧹
TLDR
Create Blazor projects with the bare-minimum amount of code in no time.
Install CleanBlazor
dotnet new — install FriscoVInc.DotNet.Templates.CleanBlazor
Create a Blazor project (dotnet CLI)
dotnet new — install FriscoVInc.DotNet.Templates.CleanBlazordotnet new cleanblazorserver --output <my file path>cd <my file path>dotnet run
Done! 🎉. And for the Blazor wasm template, you can also use:
dotnet new cleanblazorwasm
Create a Blazor project (Visual Studio 2022)
- Open Visual Studio
- CTRL+SHIFT+N
- Start your project with any CleanBlazor project template.
About the out of the box .NET Blazor Project Templates
When you start any .NET project you’ll usually use the .NET SDK’s out of the box project templates.
dotnet CLI
dotnet new blazorserver
dotnet new blazorwasm
Visual Studio
Now notice some of the “bloatware”
Using CleanBlazor!
CleanBlazor is listed in Microsoft’s official dotnet Github repository under the Available templates for dotnet new section.
Additionally, CleanBlazor is a dotnet template pack available on nuget.org. 👉 LINK
As such it is easily installable. The dotnet cli will automatically pull these templates from nuget.org. You just need to run the install command on your terminal:
dotnet new --install FriscoVInc.DotNet.Templates.CleanBlazor
Checkout the Getting Started section in the repo for any pre-requisites you might be missing.
dotnet cli
Very similar to how you create the out of the box Blazor projects, create your new project from any terminal or the vs code terminal:
dotnet new cleanblazorserver
or
dotnet new cleanblazorwasm
Same as with the out of the box templates, you can optionally include the output folder and/or project name:
--output <path to folder> --name <project name>
Visual Studio 2022
- Open Visual Studio.
- Open the New Project Dialog. CTRL + SHIFT + N.
- Search for Clean Blazor.
- Select either the Clean Blazor Server of Clean Blazor Wasm project.
- Create your project.
- Done!
*At time of writing, Visual Studio 2022 is in preview. If the above steps didn’t work for you, try updating to the latest version of Visual Studio, repair it, or simply use the dotnet cli option in the section above.
Now notice, no “bloatware”!
Gotcha’s
These project templates target .NET 6 onwards (.NET 6 preview 7 at time of writing).
Every time a new .NET version comes out, the project templates will be updated accordingly to match the newest version of .NET.
Checkout the nuget page for different versions of these templates if by any chance you want/need to target a specific .NET version.
Tips
- Use Visual Studio 2022 and keep it updated.
- If not using an IDE, make sure you have the latest version of .NET
- Keep your project templates updated. Simply run:
dotnet new --update-apply
Uninstall
dotnet new --uninstall FriscoVInc.DotNet.Templates.CleanBlazor
Or if you want to uninstall a specific version:
dotnet new --uninstall
You now get a list of commands to uninstall any custom templates on your PC. Copy the command you want and run it.
Conclusion
Happy coding, and feel free to contribute!
Learning Resources
- [Github] DotNet templating wiki
- [Github] Available templates for dotnet new
- [Microsoft] Custom templates for dotnet new
- [Microsoft] Tutorial: Create an item template
- [Microsoft] .NET CLI Templates in Visual Studio