.NET CLI Templates in Visual Studio

Tim Heuer

One of the values of using tools for development is the productivity they provide in helping start projects, bootstrapping dependencies, etc. One way that we’ve seen developers and companies deliver these bootstrapping efforts is via templates.  Templates serve as a useful tool to start projects and add items to existing projects for .NET developers.

Visual Studio has had templates for a long time and .NET Core’s command-line interface (CLI) has also had the ability to install templates and use them via `dotnet new` commands.  However, if you were an author of a template and wanted to have it available in the CLI as well as Visual Studio you had to do extra work to enable the set of manifest files and installers to make them visible in both places.  We’ve seen template authors navigate to ensuring one works better and that sometimes leaves the other without visibility.  We wanted to change that.

Starting in Visual Studio 16.8 Preview 2 we’ve enabled a preview feature that you can turn on that enables all templates that are installed via CLI to now show as options in Visual Studio as well.  To enable this option visit the Preview Features options in the Tools…Options menu and look for the “Show all .NET Core templates in the New Project dialog” (we’re awesome at naming) checkbox and check it:

Image of Preview Features dialog

After enabling you need to restart the Visual Studio instance to get this capability.  After restarting and choosing to create a new project you’ll see some slight differences in the experience.  The full list of templates is shown and the names are now being driven from the manifest data in the template’s template.json file.

Image of New Project Dialog with templates listed

Previously as an example we had a special dialog for ASP.NET projects.  When the new experience is enabled, this no longer exists, and all project templates use the same infrastructure.  This new model reads the options to be exposed to the dialog and renders the UI to enable the selection.  Here is the example of an ASP.NET Core web application:

Image of template options being presented

We know the .NET ecosystem has a lot of commercial and community projects that create templates and have instructions for developers to install them from their NuGet packages.  We want to surface those better and provide more attribution to the authors when they are.  For example, .NET Boxed templates provide a set of starter templates but are installed only via CLI.  Here you see them now showing in Visual Studio with author attribution:

Image showing community templates with author attribution

We’ve just enabled this capability in this release and are refining it based on our own findings but also hopefully from feedback from template authors.  If you are a template author please turn this on and try it out! Try enhancing template.json in your CLI template to offer the Target Framework selection and let us know how your template options look in the new dialog. This is one step in our journey to a better template ecosystem; let us know how we are doing and what other changes you’d like.  We’ve already identified a few tips to make your templates a great experience:

  • Make sure sourceName is in template.json (should be required to show in Visual Studio), here is an example
  • Add a defaultName to the template.json (defaultName is the value that is displayed for the project name in VS, for example WebApplication1), here is an example
  • Add an icon via adding a host file, here is an example

As we evolve this integration we will continue to provide guidance and update our templating documentation to reflect the best practices for authors to deliver a great experience in CLI and Visual Studio before we turn this on by default.

There are a few other experience things to note when enabling this option:

  • For now, this support is for Project Templates, but we are exploring the options to enable this for Item Templates as well.
  • Not all the Authentication options are enabled for ASP.NET Core projects but will be added later.
  • Templates with CLI and Visual Studio installer (VSIX) manifests with different IDs will show duplicates. Changing to a single identity for the template is recommended.

Please give this a try and use the Visual Studio Feedback Tool to report issues you may find in your experiences.  If you can provide the specific template you are using that will be useful as well.

On behalf of the Visual Studio and .NET teams, thanks for reading and happy coding!

16 comments

Discussion is closed. Login to edit/delete existing comments.

  • Meir Blachman 0

    So does this mean that the old visual studio templating system will be deprecated in favor of the modern cli engine? really great news!

    • Sayed Ibrahim HashimiMicrosoft employee 0

      The existing Visual Studio templating support (vstemplate) will continue to exist. It’s used by a lot of 1st party and 3rd party templates. This is an alternative to using that technology.

  • SuperCocoLoco . 0

    One of the values of using tools for development is the productivity they provide in helping start projects, but the “New Project Dialog” and the new “Start Page” are garbage that is clearly a step back and antiproductivity tools that they provide frustration, irritability and chaos not helping in start projects.

    The vast mayority of users don’t want the “New Project Dialog” or the “New Start Page” and ALL the feedback are claiming LOUD and CLEAR to restore the old tree based “New Project Dialog” and “Start Page”. See the comments in: https://devblogs.microsoft.com/visualstudio/redesigning-the-new-project-dialog or https://developercommunity.visualstudio.com/idea/401508/vs-2019-preview-new-project-dialog-is-unstructured-1.html.

    Most users stick with Visual Studio 2017 for at least create New Projects with the tree based dialog and then open it with Visual Studio 2019 to continue working. Others uses thrid party extensions to hability the old “New Project Dialog” in Visual Studio 2019, but i’m sure in the future Microsoft blocks this extensions in order to continue destroying usability and productivit in the way line that Microsoft is following lately in recent years in its developments as well as Windows 10 or Office..

    Why is Microsoft not hearing his user base feedback? Why all feedback tools if then Microsoft does what it wants without caring about its users? Why insist in the “New Project Dialog” or “Start Page that nobody want and nobody request? Why destroy well-functioning tools that all users like and that have proven to be efficient and productive? Why not, at least, bring an option to allow the old “New Project Dialog” or the old “Start Page” in order to mantain the new garbage dialogs and bring users choices to select what they prefer? Is this the new Microsoft?

    Things like this remind me of Microsoft’s imposition of ALL CAPS MENU, that nobody wanted; the Windows 8 interface, that nobody wanted, but Microsoft insisted on, forcing users with a shoehorn, and in the end it had to change.

  • Rehan Saeed 0

    The project templates in the screenshot above are from a project called .NET Boxed. You can install .NET Boxed by running:

    dotnet new --install Boxed.Templates

    Going by the blog post, installing templates is not supported yet, only displaying them?

    • Sayed Ibrahim HashimiMicrosoft employee 0

      We will be working to hopefully add a Search and Install feature, but we are not there yet. We first need to iron out the issues with using installed templates, and then we will circle back to enable Search and Install.

  • Rehan Saeed 0

    For template developers, is any of this documented anywhere?

    • Sayed Ibrahim HashimiMicrosoft employee 0

      We will be working on guidance, but we don’t have all the info to get that published today. The purpose of this blog post is to ask template authors to try their templates in Visual Studio and then report the issues they have run into. There will be some issues that we can fix on our side, but there will also be a class of issues that require changes to the templates. Once we have the data for the latter, we will publish some guidance for what specifically needs to be set to appear in Visual Studio and have a good experience.

  • Daniel Smith 0

    Are there any plans to have a nice UI experience for acquiring and updating templates in the IDE like we have for NuGet packages? It would be great to just be able to see an indicator on the templates in the New Project dialog to show if there’s updates available, and to be able to update them directly from there without dropping to the command line.

    • Sayed Ibrahim HashimiMicrosoft employee 0

      We will be working to hopefully add a Search and Install feature, but we are not there yet. We first need to iron out the issues with using installed templates, and then we will circle back to enable Search and Install.

      • احسان هاشمی اصفهانی 0

        How long do you think your program will be added for a good and better UI user experience to get the update and the ability to search and install that you mentioned?
        How long does it take to install the templates and fix the problems?
        I think the issue of a good UI user experience without the possibility of searching and adding is necessary.
        Thanks for sharing this useful article.
        thank you.

        Ehsan Hashemi

        • Sayed Ibrahim HashimiMicrosoft employee 0

          I cannot say how long it will take for us to implement that functionality. We are still in the investigation phase, and we have identified some open issues that need to be resolved before we can move forward. For example, how can we make sure that we don’t show templates that have project types that the currently installed version of Visual Studio doesn’t support?
          When we add features to Visual Studio, it has a higher quality bar for the user experience than the CLI has. So we have to be a bit careful to make sure that we have all the things in place so that we can provide a good experience.

  • Eric Williams 0

    I really, really hope the notion of

    dotnet new --install path/to/my/repo

    comes back!

    • Sayed Ibrahim HashimiMicrosoft employee 0

      Hi Eric, as far as I know that should still work. I just tried it locally (on Windows), and it showed my template. What problems are you running into?

      • Greg Ingram 0

        I’m having similar issues as I can install locally, but appears to not show up in the New Dialog. You can see my template created for the .NET System.Device.Gpio project below:

        https://github.com/dotnet/iot/issues/1173

        Thanks for any feedback/help.

        • Sayed Ibrahim HashimiMicrosoft employee 0

          Hi Greg, the issue that you are running into is that Visual Studio only supports templates that are installed via a NuGet package. I looked through the link, and the repo, and it seems like you are installing using a folder path. I have replied back to the issue you created to clear it up the issue. Let’s continue the discussion there.

  • Tsahi 0

    Who are you, people who start a new project from CLI?

Feedback usabilla icon