﻿# dotnet new Templates

<!-- Version variant: templates_2; default: [/nservicebus/dotnet-templates/index.md](/nservicebus/dotnet-templates/index.md) -->


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
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 Windows Service

This template makes it easier to create a [Windows Service](https://learn.microsoft.com/en-us/dotnet/framework/windows-services/introduction-to-windows-service-applications) host for an NServiceBus endpoint.

The template can be used via the following command:

<!-- snippet: nsbservice-usage -->

```txt
dotnet new nsbwinservice --name MyWindowsService
```

<!-- endsnippet -->

This will create a new directory named `MyWindowsService` containing a Windows Service `.csproj` also named `MyWindowsService`.

To add to an existing solution:

<!-- snippet: nsbservice-addToSolution -->

```txt
dotnet new nsbwinservice --name MyWindowsService
dotnet sln add "MyWindowsService/MyWindowsService.csproj"
```

<!-- endsnippet -->


### Options

<!-- snippet: nsbservice-options -->

```txt
dotnet new nsbwinservice --help
```

<!-- endsnippet -->

#### Target Framework

The target framework for the project.

`-f|--framework`

Default: `net462`




Supported: `net471`, `net47`, `net462`, `net461`, `net452`


> [!NOTE]
> When installing an endpoint created from this template as a service, the `--run-as-service` parameter must be set on the command line. See [Windows Service Installation](/nservicebus/hosting/windows-service.md) for details.
## ServiceControl Transport Adapter Windows Service

> [!WARNING]
> [ServiceControl.TransportAdapter](/nservicebus/upgrades/supported-versions.md#other-packages-servicecontrol-transportadapter) is obsolete. Instead, use the [`NServiceBus.Transport.Bridge`](/nservicebus/bridge/index.md).

This template makes it easier to create a [Windows Service](https://learn.microsoft.com/en-us/dotnet/framework/windows-services/introduction-to-windows-service-applications) host for a [ServiceControl Transport Adapter](/servicecontrol/transport-adapter.md).

The template can be used via the following command:

<!-- snippet: scadapterservice-usage -->

```txt
dotnet new scadapterwinservice --name MyAdapter
```

<!-- endsnippet -->

This will create a new directory named `MyAdapter` containing a Windows service `.csproj` also named `MyAdapter`.

To add to an existing solution:

<!-- snippet: scadapterservice-addToSolution -->

```txt
dotnet new scadapterwinservice --name MyAdapter
dotnet sln add "MyAdapter/MyAdapter.csproj"
```

<!-- endsnippet -->


### Options

<!-- snippet: scadapterservice-options -->

```txt
dotnet new scadapterwinservice --help
```

<!-- endsnippet -->

partial: target-framework

> [!NOTE]
> When installing an endpoint created from this template as a service, the `--run-as-service` parameter must be set on the command line. See [Windows Service Installation](/nservicebus/hosting/windows-service.md) for details.

## NServiceBus Docker Container

This template makes it easier to create a [Docker](https://www.docker.com/) container host for an NServiceBus endpoint. The template follows the approach outlined in [Docker Container Host](/nservicebus/hosting/docker-host/index.md).

The template can be used via the following command:

<!-- snippet: docker-usage -->

```txt
dotnet new nsbdockercontainer --name MyEndpoint
```

<!-- endsnippet -->

This will create a new directory named `MyEndpoint` containing a `.csproj` also named `MyEndpoint`.

To add to an existing solution:

<!-- snippet: docker-addToSolution -->

```txt
dotnet new nsbdockercontainer --name MyEndpoint
dotnet sln add "MyEndpoint/MyEndpoint.csproj"
```

<!-- endsnippet -->

To build the Docker image, open the command line, change to the directory containing the endpoint's `.csproj`, and run the following command:

<!-- snippet: docker-build -->

```txt
docker build -f Dockerfile -t MyEndpoint ./..
```

<!-- endsnippet -->
