There are a bunch of dotnet templates readily available for use. To list out all the templates, open up the command prompt and type in the following command,
dotnet new --list
That's all fine and dandy! But what about creating your templates? Say, for example, you are bootstrapping a multi-project (e.g. Web, Domain, Infrastructure) microservice-based solution and find it super helpful for others to use as well. You can easily ship your template to NuGet or other sources following some easy steps.
- I've to use
dotnet new blazorserveror
dotnet new blazorwasmto create a new project.
Fluxor.Balzor.Weband wire it up in the
- Add a
Storefolder and add necessary code files for
Effects, so on and so forth
- Initialize the
- Import the
I figured out that it would be easier if I just create some custom templates where all of this boilerplate stuff is already in place for me. Speaking of creating custom templates for
Blazor + Fluxor, here's a shameless plug
The project structure I'm going for is following
There are a couple of ways you can use to pack up a template into a NuGet package,
The dotnet pack command and a
.csprojfile. Alternatively, nuget pack command along with a
I'm going for the second route, hence I have a
.nuspec file at the root of the project folder. To run
nuget pack command, you would need the
Nuget.exe. No worries! Just download it from, nuget.org/downloads.
So, I have two project folders under the
Content folder, each one containing a different flavor of
Blazor wired up with
Fluxor. You can get a better look at those here,
.NET template engine expects that you have a
.template.config folder on the root of your runnable project. To turn that runnable project into a template with some desired configurations, you better have a
template.json file under the
Pretty much everything is self-explanatory in the configuration file. To know more about what each of these flags does, refer to this official doc.
At this point, you are ready to install the templates locally using the following command,
> dotnet new --install .\BlazorFluxorTemplates\Content\ Template Name Short Name Language Tags -------------------------------- ------------------ -------- ----------------------------- Blazor Fluxor Server Application blazorfluxorserver [C#] Web/Blazor/Fluxor Blazor Fluxor Wasm Application blazorfluxorwasm [C#] Web/Blazor/Fluxor/WebAssembly
Time for creating the
The important thing to notice here is the
<files> node; You have to include the location of the template files here.
All done! Time to run the
nuget pack command to create a Nuget package (
.nupkg). I have downloaded
C:\ drive, so first I've to go inside the directory and then specify the location of the
.nuspec file following the
Now that you have the Nuget package (
.nupkg), you can upload it the nuget.org so that the rest of the world can use your template.