Prathamesh
Prathamesh

Reputation: 95

Create C# Project Templates in Visual Studio 2022 (.NET6)

I have VS 2022 with dotnet 6. I want to create custom project templates.

  1. How do I package it, so that my peers can just use it in their machine ? (I tried VSIX but I think it does not support dotnet 6 yet)
  2. Also, I want to use custom variables. e.g. if I create a project with name XYZ,enter image description here the controller name should be 'XYZController'. and I want to use this variable value across multiple places within the project.

Upvotes: 2

Views: 2386

Answers (1)

Alireza Ahmadi
Alireza Ahmadi

Reputation: 9953

There is a comprehensive documentation for creating a custom template. Here is the steps for packageing:

A custom template is packed with the dotnet pack command and a .csproj file. Alternatively, NuGet can be used with the nuget pack command along with a .nuspec file. However, NuGet requires the .NET Framework on Windows and Mono on Linux and macOS.

The .csproj file is slightly different from a traditional code-project .csproj file. Note the following settings:

  1. The setting is added and set to Template.
  2. The setting is added and set to a valid NuGet version number.
  3. The setting is added and set to a unique identifier. This identifier is used to uninstall the template pack and is used by NuGet feeds to register your template pack.
  4. Generic metadata settings should be set: , , , and .
  5. The setting must be set, even though the binary produced by the template process isn't used. In the example below it's set to netstandard2.0.

See this for a working example.

Upvotes: 3

Related Questions