Missing "No templates found matching:..."-message when using `-minimal` option with `dotnet new`
Describe the bug
When using dotnet new with the -minimal option, no "No templates found matching:..."-message is shown to the user, if no matching template exists. Instead a generic "For more information, run:..."-message is shown.
To Reproduce
The issue can be reproduced by running dotnet new with the -minimal option, and a combination of template and language that doesn't exist. The example below uses the webapi template with -lang option "F#", since no minimal webapi-template exists for F#:
$> dotnet new webapi -minimal -o TodoApi -lang F#
For more information, run:
dotnet new webapi -h
I was expecting to see a "No templates found matching:..."-message, informing me that no F#-version of this template exists, but was instead shown a "For more information..."-message.
Expected behavior
To illustrate the expected behavior, I'm including an example of trying to create a new project without the -minimal option, using the grpc template with -lang option "F#", another combination for which no template exists:
$> dotnet new grpc -o TodoApi -lang F#
No templates found matching: 'grpc', language='F#'.
To list installed templates, run:
dotnet new --list
To search for the templates on NuGet.org, run:
dotnet new grpc --search
As expected, a "No templates found matching:..."-message is printed to the console, and I would expect the behavior of dotnet new to be similar to this when using the -minimal option.
Further technical details
I'm using Ubuntu 20.04.3 LTS (64-bit version), and running the dotnet command straight from the default terminal (gnome-terminal).
The output from dotnet --info is as follows:
$> dotnet --info
.NET SDK (reflecting any global.json):
Version: 6.0.101
Commit: ef49f6213a
Runtime Environment:
OS Name: ubuntu
OS Version: 20.04
OS Platform: Linux
RID: ubuntu.20.04-x64
Base Path: /usr/share/dotnet/sdk/6.0.101/
Host (useful for support):
Version: 6.0.1
Commit: 3a25a7f1cc
.NET SDKs installed:
3.1.416 [/usr/share/dotnet/sdk]
5.0.404 [/usr/share/dotnet/sdk]
6.0.101 [/usr/share/dotnet/sdk]
.NET runtimes installed:
Microsoft.AspNetCore.App 3.1.22 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 5.0.13 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 6.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 3.1.22 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 5.0.13 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 6.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
To install additional .NET runtimes or SDKs:
https://aka.ms/dotnet-download
Background
Discovered this bug following the Microsoft Tutorial: Create a minimal web API with ASP.NET Core. This tutorial also introduced me to the -minimal option in .NET CLI.
I see a few things to fix here after reproducing this:
- the aspnetcore templates for F# could have a
-minimaloption added. This work would need to be logged and tracked over at dotnet/aspnetcore where those templates live. - the
newcommand should have better error reporting for the case where an option is provided that the template has no knowledge of. This work would need to be logged and tracked in dotnet/templating, where thenewcommand implementation lives. - tab-completion for
dotnet newshould take language (and other options that help determine the actual template that's being instanciated) into account - as soon as you specify-lang F#, that should restrict tab-completion to the options available on that template. This also needs to be logged and tracked in dotnet/templating, as the tab-completion logic fordotnet newlives there.
@teodoran to be precise, there is an F# version of the webapi template, but the minimal option doesn't exist for the F# version. Templates can have the same short name ('webapi'), but typically they are authored as separate templates per-language, and so the options declared on each template can (and often are!) completely different. An example of this might be top-level namespaces in C# - an option enabling those makes no sense for F#.
Thanks for taking the time to explain the relation between short names, the -minimal option and the templates @baronfel :+1:
Love the additional improvements you've identified. Especially having language aware tab-completion would be really cool! Would you like me to create the issues in dotnet/aspnetcore and dotnet/templating, or is that something that's handled on your end?
I'll take care of it all, no worries :) I was brain-dumping partially for documentation purposes as I went about my workday.
Alright :smiley: I'll be crossing my fingers and keeping an eye out for these features in the future then :crossed_fingers:
This was fixed in dotnet new, removing the label
Closing. Please follow https://github.com/dotnet/aspnetcore/issues/40161 for ASP.NET template update.