﻿# dotnet new Templates


The Particular [dotnet new](https://learn.microsoft.com/dotnet/core/tools/dotnet-new) templates make it easier to bootstrap a variety of common project and code-related scenarios.

> [!NOTE]
> The `dotnet new` command creates a new project, configuration file, or solution based on the specified template. The command provides a convenient way to initialize a valid SDK-style project. The command calls the template engine to create the artifacts on disk based on the specified template and options. More information is available in the [dotnet-new documentation](https://learn.microsoft.com/dotnet/core/tools/dotnet-new).

## Installation

Install using the following command:

<!-- snippet: install -->

```txt
// install latest version
dotnet new install ParticularTemplates
```

<!-- endsnippet -->

If a specific version is needed, follow the guidance in the [dotnet new install documentation](https://learn.microsoft.com/en-us/dotnet/core/tools/dotnet-new-install#examples).

## NServiceBus Endpoint

The `nsbendpoint` template creates a C# project for an NServiceBus endpoint. By selecting options, the endpoint is preconfigured with choices of:

*  Target framework
*  [Message transport](/transports/index.md)
*  [Persistence](/persistence/index.md)
*  [Hosting model](/nservicebus/hosting/index.md), which can be one of:
   * Console Application
   * [Windows service hosting](/nservicebus/hosting/windows-service.md)
   * [Docker container hosing](/nservicebus/hosting/docker-host/index.md)

Once the package is installed, the template can be found in the Visual Studio **New Project** dialog:

![NServiceBus endpoint template in the Visual Studio New Project dialog](new-project.png)

After naming the project and selecting a location for it on disk, the **Additional information** screen will allow customizing the template:

![Customing endpoint properties in the additional information dialog](endpoint-additional-info.png)

### Command-line usage

The default usage will create a Console Application using [Learning Transport](/transports/learning/index.md), [Learning Persistence](/persistence/learning/index.md):

<!-- snippet: endpointdefault -->

```txt
dotnet new nsbendpoint --name MyEndpoint [options]
dotnet sln add "MyEndpoint/MyEndpoint.csproj"
```

<!-- endsnippet -->

Parameters allow the selection of message transport, persistence, and hosting model, including [Windows Service](/nservicebus/hosting/windows-service.md) or [Docker container](/nservicebus/hosting/docker-host/index.md) hosting.

### Options

| Option | Description |
|-|-|
| `-n`,<br/>`--name` | The name of the endpoint to create. |
| `-f`,<br/>`--framework` | The target framework for the project.<br/>One of: `net9.0` (default), `net8.0` |
| `-t`,<br/>`--transport` | The message queue (transport) to use.<br/>One of `LearningTransport` (default), `AzureServiceBus`, `AzureStorageQueues`, `SQS`, `RabbitMQ`, `SQL`. |
| `-p`,<br/>`--persistence` | Where to store data. This should be the same place business data is stored.<br/>One of `LearningPersistence` (default), `MSSQL`, `MySQL`, `PostgreSQL`, `Oracle`, `CosmosDB`, `AzureTable`, `RavenDB`, `MongoDB`, `DynamoDB` |
| `-hm`,<br/>`--hosting` | The hosting model to use.<br/>One of: `ConsoleApp` (default), `WindowsService`, `Docker`|

For more details on available options and choices, use this command to get help:

<!-- snippet: endpointhelp -->

```txt
dotnet new nsbendpoint --help
```

<!-- endsnippet -->

## NServiceBus Handler

The `nsbhandler` item template creates a C# class for a message handler.

Message handlers can be created using the Visual Studio New Item dialogue or the command line.

![Create a message handler in Visual Studio using the item template](handler-from-item-template.png)

To create a message handler class that implements `IHandleMessages<MyMessage>`:

<!-- snippet: handlerdefault -->

```txt
dotnet new nsbhandler --name ClassName --messagetype MyMessage
```

<!-- endsnippet -->

### Options

| Option | Description |
|-|-|
| `-n`,<br/>`--name` | The name of the message handler class to create. |
| `-mt`,<br/>`--messagetype` | The message type for the handler to implement. Default: `MessageType` |

For more details on available options and choices, use this command to get help:

<!-- snippet: handlerhelp -->

```txt
dotnet new nsbhandler --help
```

<!-- endsnippet -->

## NServiceBus Saga

The `nsbsaga` item template creates a C# class for a saga that includes the saga class, saga data class, handlers for two message types, a custom timeout class, and the `ConfigureHowToFindSaga` method.

Message handlers can be created using the Visual Studio New Item dialogue or the command line.

![Create a saga in Visual Studio using the item template](saga-from-item-template.png)

To create a saga:

<!-- snippet: sagadefault -->

```txt
dotnet new nsbsaga --name ClassName --messagetype1 Message1 --messagetype2 Message2
```

<!-- endsnippet -->

### Options

| Option | Description |
|-|-|
| `-n`,<br/>`--name` | The name of the saga class to create. |
| `-mt2`,<br/>`--messagetype` | The first message type that will be handled by the saga. Default: `MessageType1` |
| `-mt1`,<br/>`--messagetype` | The second message type that will be handled by the saga. Default: `MessageType2` |

For more details on available options and choices, use this command to get help:

<!-- snippet: sagahelp -->

```txt
dotnet new nsbsaga --help
```

<!-- endsnippet -->





