Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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 #8558

Open
asos-lewish opened this issue Nov 21, 2024 · 0 comments

Comments

@asos-lewish
Copy link

asos-lewish commented Nov 21, 2024

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 <template-name> --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
  1. Add the following to the template.json file under .template.config folder.
  {
    "$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"
      }
    }
  }
  1. Add the following to the README.md file
  Here is the value for CustomParameterReplacement
  1. Install the template by calling dotnet new install <path to your template root folder> --force

  2. Execute the template by calling dotnet new testtemplate --name test1 --output <your-output-path> --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 <template name> 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 [<template-name>] [options]

Arguments:
  <template-name>  If specified, only the templates matching the name will be shown.

Options:
  --author <author>                      Filters the templates based on the template author.
  -lang, --language <language>           Filters templates based on language.
  --type <type>                          Filters templates based on available types. Predefined values are "project" and "item".
  --tag <tag>                            Filters the templates based on the tag.
  --package <package>                    Filters the templates based on NuGet package ID.
  --columns-all                          Displays all columns in the output.
  --columns <author|language|tags|type>  Specifies the columns to display in the output.
  -v, --verbosity <LEVEL>                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 <template name> instead then everything seems to work correctly and the template is executed. e.g. dotnet new create testtemplate --name test1 --output <your-output-path> --force --customParameter "search"

@asos-lewish asos-lewish changed the title Passing a value to a template parameter which is one of the dotnet new commands causes the cli to try and run that command Passing a value to a template parameter that is one of the dotnet new commands causes the cli to try and run that command Nov 21, 2024
@asos-lewish asos-lewish changed the title Passing a value to a template parameter that is one of the dotnet new commands causes the cli to try and run that command 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 Nov 21, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant