dotnet / sdk

Core functionality needed to create .NET Core projects, that is shared between Visual Studio and CLI
https://dot.net/core
MIT License
2.69k stars 1.06k forks source link

CLI parsing error in .net 7 handling #29295

Closed ghost closed 8 months ago

ghost commented 1 year ago

Describe the bug

Invoking a new project template from CLI fails with certain parameters passed to the template. This is a regression from previous version of the cli. There doesn't appear to be a clear workaround.

To Reproduce

  1. ensure you have dotnet sdk 6.0 and 7.0 installed. (See repro results for exact versions used when reporting this issue)
  2. copy the following folder from this repo: https://github.com/erinlah-ms/bug-repros/tree/main/repro-new-parsing
  3. run simple_template\install.cmd to install the custom template
  4. run bad-v7\repro.cmd to invoke the template providing the -t option

Expected: The command dotnet new xyzzy -t Jane should succeed, as -t should match the tortoise parameter to the xyzzy template. This is the result on dotnet sdk 6.0

Actual: The command dotnet new xyzzy -t Jane on net sdk 7.0 fails with invalid arg, indicating that -t must be project. The -t argument was inappropriately gobbled up by the dotnet new command, when it should have been a parameter to the xyzzy template instead.

Exceptions (if any)

Further technical details

Example console output from running good-v6\repro.cmd and bad-v7.cmd, illustrating reproing the bug. Note that only commands ending in .cmd were user entered commands.

$ simple_template\install.cmd

$ dotnet new --install w:\repos\github-erinlah-ms\bug-repros\repro-new-parsing\simple_template\\ext
The following template packages will be installed:
   w:\repos\github-erinlah-ms\bug-repros\repro-new-parsing\simple_template\ext

Success: w:\repos\github-erinlah-ms\bug-repros\repro-new-parsing\simple_template\ext installed the following templates:
Template Name               Short Name  Language  Tags
--------------------------  ----------  --------  -------
Contoso Sample 02 modified  xyzzy       [C#]      Console

$ good-v6\repro.cmd

$ dotnet --version
6.0.403

$ if EXIST obj\test rd /s /q obj\test

$ mkdir obj\test

$ cd obj\test   || exit /b 1

$ dotnet new xyzzy -t "Jane"   || exit /b 1
The template "Contoso Sample 02 modified" was created successfully.

$ type example.txt
This is an example template

Parameters:
- Flubber=A bouncy material
- Tortoise=Jane

$ bad-v7\repro.cmd

$ dotnet --version
7.0.100

$ if EXIST obj\test rd /s /q obj\test

$ mkdir obj\test

$ cd obj\test   || exit /b 1

$ dotnet new xyzzy -t "Jane"   || exit /b 1
Error: Invalid option(s):
-t Jane
   'Jane' is not a valid value for -t. The possible values are:
      project

For more information, run:
   dotnet new xyzzy -h

For details on the exit code, refer to https://aka.ms/templating-exit-codes#127

$
NickCraver commented 1 year ago

For what it's worth, we're hitting this with dotnet test and what would generate a binlog in .NET 6, e.g.

dotnet test /bl:LogFile=unittests.binlog

In .NET 7.0.100, no binlog is generated, which began breaking our builds when we were expecting to move some binlogs around for artifacts afterwards.

baronfel commented 8 months ago

I believe we fixed this in 7.0.101's servicing release.