{"id":29674,"date":"2020-09-02T12:37:11","date_gmt":"2020-09-02T19:37:11","guid":{"rendered":"https:\/\/devblogs.microsoft.com\/dotnet\/?p=29674"},"modified":"2020-09-02T12:37:11","modified_gmt":"2020-09-02T19:37:11","slug":"net-cli-templates-in-visual-studio","status":"publish","type":"post","link":"https:\/\/devblogs.microsoft.com\/dotnet\/net-cli-templates-in-visual-studio\/","title":{"rendered":".NET CLI Templates in Visual Studio"},"content":{"rendered":"<p>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\u2019ve seen developers and companies deliver these bootstrapping efforts is via templates.\u00a0 Templates serve as a useful tool to start projects and add items to existing projects for .NET developers.<\/p>\n<p>Visual Studio has had templates for a long time and .NET Core\u2019s command-line interface (CLI) has also had the ability to install templates and use them via `dotnet new` commands.\u00a0 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.\u00a0 We\u2019ve seen template authors navigate to ensuring one works better and that sometimes leaves the other without visibility.\u00a0 We wanted to change that.<\/p>\n<p>Starting in <a href=\"https:\/\/devblogs.microsoft.com\/visualstudio\/visual-studio-2019-v16-8-preview-2\/\">Visual Studio 16.8 Preview 2<\/a> we\u2019ve 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.\u00a0 To enable this option visit the Preview Features options in the Tools\u2026Options menu and look for the <em>\u201cShow all .NET Core templates in the New Project dialog\u201d<\/em> (we\u2019re awesome at naming) checkbox and check it:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-29675\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-enable.png\" alt=\"Image of Preview Features dialog\" width=\"1053\" height=\"710\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-enable.png 1053w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-enable-300x202.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-enable-1024x690.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-enable-768x518.png 768w\" sizes=\"(max-width: 1053px) 100vw, 1053px\" \/><\/p>\n<p>After enabling you need to restart the Visual Studio instance to get this capability.\u00a0 After restarting and choosing to create a new project you\u2019ll see some slight differences in the experience.\u00a0 The full list of templates is shown and the names are now being driven from the manifest data in the template\u2019s <a href=\"https:\/\/docs.microsoft.com\/dotnet\/core\/tools\/custom-templates#templatejson\">template.json<\/a> file.<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-29676\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-newproj.png\" alt=\"Image of New Project Dialog with templates listed\" width=\"1536\" height=\"1020\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-newproj.png 1536w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-newproj-300x199.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-newproj-1024x680.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-newproj-768x510.png 768w\" sizes=\"(max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<p>Previously as an example we had a special dialog for ASP.NET projects.\u00a0 When the new experience is enabled, this no longer exists, and all project templates use the same infrastructure.\u00a0 This new model reads the options to be exposed to the dialog and renders the UI to enable the selection.\u00a0 Here is the example of an ASP.NET Core web application:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-29677\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-projoptions.png\" alt=\"Image of template options being presented\" width=\"1536\" height=\"1020\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-projoptions.png 1536w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-projoptions-300x199.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-projoptions-1024x680.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-projoptions-768x510.png 768w\" sizes=\"(max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<p>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.\u00a0 We want to surface those better and provide more attribution to the authors when they are.\u00a0 For example, .NET Boxed templates provide a set of starter templates but are installed only via CLI.\u00a0 Here you see them now showing in Visual Studio with author attribution:<\/p>\n<p><img decoding=\"async\" class=\"aligncenter size-full wp-image-29678\" src=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-attribution.png\" alt=\"Image showing community templates with author attribution\" width=\"1536\" height=\"1020\" srcset=\"https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-attribution.png 1536w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-attribution-300x199.png 300w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-attribution-1024x680.png 1024w, https:\/\/devblogs.microsoft.com\/dotnet\/wp-content\/uploads\/sites\/10\/2020\/09\/clitemplates-option-attribution-768x510.png 768w\" sizes=\"(max-width: 1536px) 100vw, 1536px\" \/><\/p>\n<p>We\u2019ve just enabled this capability in this release and are refining it based on our own findings but also hopefully from feedback from template authors.\u00a0 <strong>If you are a template author please turn this on and try it out!<\/strong> 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&#8217;d like.\u00a0 We&#8217;ve already identified a few tips to make your templates a great experience:<\/p>\n<ul>\n<li>Make sure sourceName is in template.json (should be required to show in Visual Studio), <a href=\"https:\/\/github.com\/aspnet\/Templating\/blob\/0af2acd6fff0f51ec42183f5a5b01f8f0712af5f\/src\/Microsoft.DotNet.Web.ProjectTemplates\/content\/EmptyWeb-CSharp\/.template.config\/template.json#L19\">here is an example<\/a><\/li>\n<li>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 <a href=\"https:\/\/github.com\/aspnet\/Templating\/blob\/0af2acd6fff0f51ec42183f5a5b01f8f0712af5f\/src\/Microsoft.DotNet.Web.ProjectTemplates\/content\/EmptyWeb-CSharp\/.template.config\/template.json#L122\">an example<\/a><\/li>\n<li>Add an icon via adding a host file, here is <a href=\"https:\/\/github.com\/aspnet\/Templating\/blob\/1f2e966454d34aa823d667658a399e3162ca50f8\/src\/Microsoft.DotNet.Web.Spa.ProjectTemplates\/content\/Angular-CSharp\/.template.config\/vs-2017.3.host.json#L14\">an example<\/a><\/li>\n<\/ul>\n<p>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.<\/p>\n<p>There are a few other experience things to note when enabling this option:<\/p>\n<ul>\n<li>For now, this support is for Project Templates, but we are exploring the options to enable this for Item Templates as well.<\/li>\n<li>Not all the Authentication options are enabled for ASP.NET Core projects but will be added later.<\/li>\n<li>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.<\/li>\n<\/ul>\n<p>Please give this a try and use the <a href=\"https:\/\/docs.microsoft.com\/visualstudio\/ide\/how-to-report-a-problem-with-visual-studio?view=vs-2019\">Visual Studio Feedback Tool<\/a> to report issues you may find in your experiences.\u00a0 If you can provide the specific template you are using that will be useful as well.<\/p>\n<p>On behalf of the Visual Studio and .NET teams, thanks for reading and happy coding!<\/p>\n","protected":false},"excerpt":{"rendered":"<p>If you are a template author for .NET Core templates and have been wanting to show up for Visual Studio users as well with little effort we have enabled a new preview feature for you! Visual Studio now has an option in preview to enable CLI-installed .NET Core templates to display as options in the New Project Dialog experience. <\/p>\n","protected":false},"author":1328,"featured_media":58792,"comment_status":"open","ping_status":"closed","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[685,196,197,646],"tags":[9,7174,147],"class_list":["post-29674","post","type-post","status-publish","format-standard","has-post-thumbnail","hentry","category-dotnet","category-dotnet-core","category-aspnet","category-visual-studio","tag-net-core","tag-cli","tag-visual-studio"],"acf":[],"blog_post_summary":"<p>If you are a template author for .NET Core templates and have been wanting to show up for Visual Studio users as well with little effort we have enabled a new preview feature for you! Visual Studio now has an option in preview to enable CLI-installed .NET Core templates to display as options in the New Project Dialog experience. <\/p>\n","_links":{"self":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/29674","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/users\/1328"}],"replies":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/comments?post=29674"}],"version-history":[{"count":0,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/posts\/29674\/revisions"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media\/58792"}],"wp:attachment":[{"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/media?parent=29674"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/categories?post=29674"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/devblogs.microsoft.com\/dotnet\/wp-json\/wp\/v2\/tags?post=29674"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}