dotnet / dotnet/templating

Passing a value to a template parameter that is one of the dotnet new commands causes the cli to try and run that command instead

Open
#8,558 0 comments 0 reactions 0 assignees View on GitHub
triage:transfer-to-sdk
Dominant language
No language data
Stars
1.7k
Forks
399
Avg merge
3d 5h
Merged PRs (30d)
39

Description

### Product

dotnet CLI (dotnet new)

### Describe The Bug

Consider you have a custom .net template which has a parameter of type string. If you try and pass a value to this parameter when running `dotnet new ` --myParam "my-value" where that value is also one of the dotnet new commands like (search, install, list, details etc) then the dotnet cli tries to run that command instead of executing the template.

### To Reproduce

Steps:
1. Create a new dotnet template with following folder structure and files.
```
/test-template
- /.template.config/
template.json
- /template/
ReadMe.md
```
2. Add the following to the `template.json` file under `.template.config` folder.

```json
{
"$schema": "http://json.schemastore.org/template",
"author": "Lewis",
"classifications": [ "Common", "Console" ],
"identity": "Lewis",
"name": "Test Template",
"shortName": "testtemplate",
"symbols": {
"customParameter": {
"type": "parameter",
"datatype": "string",
"defaultValue": "",
"replaces": "CustomParameterReplacement",
"description": "A custom parameter"
}
}
}
```

3. Add the following to the README.md file

```
Here is the value for CustomParameterReplacement
```

4. Install the template by calling `dotnet new install --force`

5. Execute the template by calling `dotnet new testtemplate --name test1 --output --force --customParameter "search"`

You get an error with the following output as it appears that the cli is trying to execute the `dotnet new search ` command instead.

This will also happen if you pass a string value matching any of the other `dotnet new` commands to the customParameter template parameter.

```
Unrecognized command or argument(s): 'testtemplate'.
Unrecognized command or argument(s): '--customParameter'.

Description:
Searches for the templates on NuGet.org.

Usage:
dotnet new search [] [options]

Arguments:
If specified, only the templates matching the name will be shown.

Options:
--author Filters the templates based on the template author.
-lang, --language Filters templates based on language.
--type Filters templates based on available types. Predefined values are "project" and "item".
--tag Filters the templates based on the tag.
--package Filters the templates based on NuGet package ID.
--columns-all Displays all columns in the output.
--columns Specifies the columns to display in the output.
-v, --verbosity Sets the verbosity level. Allowed values are q[uiet], m[inimal], n[ormal], and diag[nostic]. [default: normal]
-d, --diagnostics Enables diagnostic output.
-?, -h, --help Show command line help.
```

### dotnet Info

output
.NET SDK:
Version: 8.0.202
Commit: 25674bb2f4
Workload version: 8.0.200-manifests.4e94be9c

Runtime Environment:
OS Name: Mac OS X
OS Version: 14.7
OS Platform: Darwin
RID: osx-arm64
Base Path: /usr/local/share/dotnet/sdk/8.0.202/

.NET workloads installed:
There are no installed workloads to display.

Host:
Version: 8.0.3
Architecture: arm64
Commit: 9f4b1f5d66

.NET SDKs installed:
7.0.408 [/usr/local/share/dotnet/sdk]
8.0.202 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.18 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 8.0.3 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.29 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.18 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 8.0.3 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
DOTNET_ROOT [/usr/local/share/dotnet]

global.json file:
Not found

Learn more:
https://aka.ms/dotnet/info

Download .NET:
https://aka.ms/dotnet/download


### Visual Studio Version

_No response_

### Additional context

Interestingly, if you execute `dotnet new create ` instead then everything seems to work correctly and the template is executed. e.g. `dotnet new create testtemplate --name test1 --output --force --customParameter "search"`

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.