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

dotnet new results in exception "maximumNumberOfValues must be greater than or equal to minimumNumberOfValues" #5964

Closed
markcandelora opened this issue Jan 20, 2023 · 4 comments
Assignees
Labels
Iteration:2023February need-customer-info Requires feedback from author size:4.0 triaged The issue was evaluated by the triage team, placed on correct area, next action defined.

Comments

@markcandelora
Copy link

Product

dotnet CLI (dotnet new)

Describe The Bug

Using dotnet new on custom project template results in following error.
Full error below:

maximumNumberOfValues must be greater than or equal to minimumNumberOfValues
   at System.CommandLine.ArgumentArity..ctor(Int32 minimumNumberOfValues, Int32 maximumNumberOfValues)
   at Microsoft.TemplateEngine.Cli.ChoiceTemplateParameter.GetBaseOption(IReadOnlySet`1 aliases)
   at Microsoft.TemplateEngine.Cli.CliTemplateParameter.GetOption(IReadOnlySet`1 aliases)
   at Microsoft.TemplateEngine.Cli.Commands.TemplateCommand.AddTemplateOptionsToCommand(CliTemplateInfo templateInfo)
   at Microsoft.TemplateEngine.Cli.Commands.TemplateCommand..ctor(BaseCommand instantiateCommand, IEngineEnvironmentSettings environmentSettings, TemplatePackageManager templatePackageManager, TemplateGroup templateGroup, CliTemplateInfo template, Boolean buildDefaultLanguageValidation)
   at Microsoft.TemplateEngine.Cli.Commands.InstantiateCommand.ReparseForTemplate(InstantiateCommandArgs args, IEngineEnvironmentSettings environmentSettings, TemplatePackageManager templatePackageManager, TemplateGroup templateGroup, CliTemplateInfo template, Boolean validateDefaultLanguage)
   at Microsoft.TemplateEngine.Cli.Commands.InstantiateCommand.ReparseForTemplate(InstantiateCommandArgs args, IEngineEnvironmentSettings environmentSettings, TemplatePackageManager templatePackageManager, TemplateGroup templateGroup, IEnumerable`1 templatesToReparse, Boolean& languageOptionSpecified)
   at Microsoft.TemplateEngine.Cli.Commands.InstantiateCommand.GetTemplateCommand(InstantiateCommandArgs args, IEngineEnvironmentSettings environmentSettings, TemplatePackageManager templatePackageManager, TemplateGroup templateGroup)
   at Microsoft.TemplateEngine.Cli.Commands.InstantiateCommand.HandleTemplateInstantationAsync(InstantiateCommandArgs args, IEngineEnvironmentSettings environmentSettings, TemplatePackageManager templatePackageManager, TemplateGroup templateGroup, CancellationToken cancellationToken)
   at Microsoft.TemplateEngine.Cli.Commands.InstantiateCommand.ExecuteIntAsync(InstantiateCommandArgs instantiateArgs, IEngineEnvironmentSettings environmentSettings, TemplatePackageManager templatePackageManager, InvocationContext context)
   at Microsoft.TemplateEngine.Cli.Commands.BaseCommand`1.InvokeAsync(InvocationContext context)

template.json:

{
    "$schema": "http://json.schemastore.org/template",
    "author": "Mark Candelora",
    "classifications": [ "Sample", "WebApi", "Common" ],
    "identity": "Sample.WebApi.Common",
    "name": "Sample WebApi Common",
    "shortName": "SampleWebApi",
    "tags": {
        "language": "C#",
        "type": "project"
    },
    "sourceName": "SampleWebApi",
    "symbols": {
        "Auth": { "datatype": "choice", "choices": [ "None", "AAD", "ApiKey" ], "type": "parameter", "allowMultipleValues": true, "defaultValue": "AAD|ApiKey" }
    }
}

projtemplate.csproj:

<Project Sdk="Microsoft.NET.Sdk">
    <PropertyGroup>
      <PackageType>Template</PackageType>
      <PackageVersion>1.0</PackageVersion>
      <PackageId>Sample.WebApi</PackageId>
      <Title>Sample WebApi Project Template</Title>
      <Authors>Mark Candelora</Authors>
      <Description>Project Template</Description>
      <PackageTags>dotnet-new;Template;Sample</PackageTags>
      <TargetFramework>net7.0</TargetFramework>
      <IncludeContentInPack>true</IncludeContentInPack>
      <IncludeBuildOutput>false</IncludeBuildOutput>
      <ContentTargetFolders>content</ContentTargetFolders>
      <SuppressDependenciesWhenPacking>true</SuppressDependenciesWhenPacking>
    </PropertyGroup>
  
    <ItemGroup>
      <Content Include="**\*" Exclude="**\bin\**;**\obj\**;projTemplate.csproj" />
      <Compile Remove="**\*" />
    </ItemGroup>

  </Project>

Commenting out the symbols node in the template.json prevents the error.

To Reproduce

Steps:

  1. create ./src folder
  2. dotnet new webapi -n Sample.WebApi -o ./src/Sample.WebApi
  3. dotnet new mstest -n Sample.WebApi.Test -o ./src/Sample.WebApi.Test
  4. place template.json in ./src/.template.config/
  5. place projtemplate.csproj in ./src/
  6. dotnet pack -c packRelease ./src
  7. dotnet new install ./src/bin/packRelease/Sample.WebApi.1.0.0.nupkg
  8. dotnet new SampleWebApi -n ThisProducesAnError -o ./test

dotnet Info

output

.NET SDK:
Version: 7.0.102
Commit: 4bbdd14480

Runtime Environment:
OS Name: debian
OS Version: 11
OS Platform: Linux
RID: debian.11-x64
Base Path: /usr/share/dotnet/sdk/7.0.102/

Host:
Version: 7.0.2
Architecture: x64
Commit: d037e070eb

.NET SDKs installed:
7.0.102 [/usr/share/dotnet/sdk]

.NET runtimes installed:
Microsoft.AspNetCore.App 7.0.2 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 7.0.2 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

Other architectures found:
None

Environment variables:
Not set

global.json file:
Not found

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

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

Visual Studio Version

Using VS Code devContainer

Additional context

devcontainer.json

{
	"name": "C# (.NET)",
	"build": {
		"dockerfile": "Dockerfile"
	},
	"features": {
		"ghcr.io/devcontainers/features/docker-in-docker:2": {},
		"ghcr.io/devcontainers/features/powershell:1": {}
	},
	"customizations": {
		"vscode": {
			"extensions": [
				"ms-vscode.powershell",
				"pspester.pester-test",
				"formulahendry.dotnet-test-explorer",
				"DotJoshJohnson.xml",
				"k--kato.docomment"
			],
			"settings": {
				"[csharp]": {
					"editor.maxTokenizationLineLength": 2500,
					"editor.formatOnSave": true,
					"editor.formatOnSaveMode": "file"
				}
			}
		}
	},
	"postCreateCommand": [
		"sudo pwsh -Command 'Install-Module Pester -Force -Scope AllUsers;'"
	]
	// Use 'forwardPorts' to make a list of ports inside the container available locally.
	// "forwardPorts": [5000, 5001],
	// "portsAttributes": {
	//		"5001": {
	//			"protocol": "https"
	//		}
	// }
	// Uncomment to connect as root instead. More info: https://aka.ms/dev-containers-non-root.
	// "remoteUser": "root"
}

Dockerfile

FROM mcr.microsoft.com/devcontainers/dotnet:0-7.0
@YuliiaKovalova
Copy link
Member

Hi @markcandelora ,

Thank you for reporting the issue and providing details.
We are investigating it and when more information is available we will return back to you.

@maridematte maridematte self-assigned this Jan 25, 2023
@YuliiaKovalova YuliiaKovalova added the triaged The issue was evaluated by the triage team, placed on correct area, next action defined. label Jan 25, 2023
@GangWang01
Copy link
Member

GangWang01 commented Feb 7, 2023

Root cause is wrong definition of choices in the symbol auth in template.json. It should be an array of the elements:

  • choice: possible value of the symbol.
  • description: human readable text describing the meaning of the choice. This has no effect on template generation.

Correct one looks like below.

    "symbols": {
        "Auth": {
            "datatype": "choice",
            "choices": [
                {
                    "choice": "None",
                    "description": "No Authentication"
                },
                {
                    "choice": "AAD",
                    "description": "Azure Active Directory"
                },
                {
                    "choice": "ApiKey",
                    "description": "API Key"
                }
            ],
            "type": "parameter",
            "allowMultipleValues": true,
            "defaultValue": "AAD|ApiKey"
        }
    }

Parameter symbol has more details and an example for Multi-choice symbols specifics

@vlada-shubina vlada-shubina added the need-customer-info Requires feedback from author label Feb 7, 2023
@vlada-shubina
Copy link
Member

@markcandelora please confirm if suggestion provided by @GangWang01 works at your end.

I know that the error message is not great, but we plan to improve it in scope of bigger task #2623.

@markcandelora
Copy link
Author

I've confirmed this works. I went back to the documentation and also confirmed that looks correct (I could have sworn I got the syntax I used from the docs, but obviously not).

Also, I'm a huge fan of good error messages, so good to know that's being worked on as well!

Thank you for the assistance!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Iteration:2023February need-customer-info Requires feedback from author size:4.0 triaged The issue was evaluated by the triage team, placed on correct area, next action defined.
Projects
None yet
Development

No branches or pull requests

6 participants