'How to install templates from nuget package?

I know I can install nuget packages from templates:

https://docs.microsoft.com/en-us/nuget/visual-studio-extensibility/visual-studio-templates

But I'd like to do the opposite, I'd like to install templates - provided by the nuget package - after the package was installed.

I read I could create a powershell script and run that after the package's been installed. Is that the only way? What are my options here?

Thanks.



Solution 1:[1]

For .NET Core it can be done using

dotnet new --install <id of your template package>

See docs for the CLI

Solution 2:[2]

I have the same problem, found that:

  1. Dotnet 5.0 can't load templates from my nuget server by id, but dotnet 6.0 can, and puts .nupkg file to %USERPROFILE%.templateengine\packages
  2. VS 2022 and new Rider view these templates.
  3. Dotnet 5.0 can install template by .nupkg local path, and puts it to %USERPROFILE%.templateengine\dotnetcli\v5.0.404\packages
  4. After step 3 you can use templates in Visual Studio 2019, but I also have ide.host.json in .template.config folder https://github.com/sayedihashimi/template-sample#supporting-visual-studio-2019

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 Alex Buyny
Solution 2 Sergey Bannikov