sdk icon indicating copy to clipboard operation
sdk copied to clipboard

dotnet new --install should have more information than "No templates were found in the package"

Open Vaccano opened this issue 3 years ago • 1 comments

Is your feature request related to a problem? Please describe.

I am trying to create a custom template for a solution. I have created a .template.config folder in my solution folder and in the .template.config folder I created a file called template.json. I filled out template.json using online documentation, but when I run dotnet new --install all I get is:

PS E:\src\Framework\NoteKeeperService> dotnet new --install .
The following template packages will be installed: E:\src\Framework\NoteKeeperService

No templates were found in the package E:\src\Framework\NoteKeeperService.

I have tried running this from the solution folder, from the .template.config folder and directly referencing the template.json file. I can't seem to figure out why its thinks no templates were found.

Describe the solution you'd like

I would like to suggest that if it can't find a template that it give more information. Optionally this could be behind a --verbose flag.

Some questions the --verbose flag could answer are:

  • Where did it look?
  • Did it find any files?
  • What name was it expecting?
  • Was there a problem with the file(s) it found?

Additional context

I ended up here from this issue https://github.com/dotnet/docs/issues/27778, where others are having the same issue.

This is a frustrating issue because it is a bit of a dead end. I will be heading to the dotnet CLI source code to see if I can deduce why it can't find the template file, or if that message is output for some other reason, but sometimes finding answers like that from the code is difficult. Please consider this upgrade to the dotnet new --install feature.

And thank you for all the amazing features in .Net!

Vaccano avatar Sep 29 '22 16:09 Vaccano

I couldn't figure out the best area label to add to this issue. If you have write-permissions please help me learn by adding exactly one area label.

Was a solution found for this issue?

GaTechThomas avatar Mar 13 '23 22:03 GaTechThomas

I faced a similar issue and have found a way to get it to work.

Here's my folder strucutre (I it on the example from here):

C:\temp\template_example
│   TemplateExample.sln
│
└───templates
    └───AdatumConsole
        │   AdatumConsole.csproj
        │   Program.cs
        │
        └───.template.config
                template.json

template.json:

{
    "$schema": "http://json.schemastore.org/template",
    "author": "Travis Chau",
    "classifications": [ "Console" ],
    "identity": "AdatumConsole",
    "shortName": "adatumconsole",
    "sourceName": "AdatumConsole",
    "name": "Adatum Corporation Console Application"
}

You should open a terminal in this example at C:\temp\template_example and run:

dotnet new install .\templates\AdatumConsole\

This should result in:

The following template packages will be installed:
   C:\temp\template_example\templates\AdatumConsole

Success: C:\temp\template_example\templates\AdatumConsole installed the following templates:
Template Name                           Short Name     Language  Tags
--------------------------------------  -------------  --------  -------
Adatum Corporation Console Application  adatumconsole            Console

Then if you use the template like so: dotnet new adatumconsole -n "MyTemplateUsed" -o "MyTemplateUsed"

You should get:

C:\temp\template_example
├───MyTemplateUsed
│       MyTemplateUsed.csproj
│       Program.cs
│
└───templates
    └───AdatumConsole
        │   AdatumConsole.csproj
        │   Program.cs
        │
        └───.template.config
                template.json

I hope this will help.

bothzoli avatar Dec 13 '23 11:12 bothzoli

This is a good suggestion - I've added it to the backlog for the templating team, but we'd gladly accept a PR giving more details about the way template packages are probed during installation.

baronfel avatar Jan 30 '24 20:01 baronfel