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.6k stars 1.03k forks source link

.NET 7.0.100 `dotnet test` cannot parse MSBuild switches from .rsp or command line if .NET CLI language is not `en` #28975

Closed mchechulnikov closed 1 year ago

mchechulnikov commented 1 year ago

Description

dotnet test command cannot parse parameters from provided .rsp file if .NET CLI language is de or ru but works fine with en on .NET SDK 7.0.100. It leads to an error Unrecognized command or argument ...

This bug is not reproducible on the .NET SDK 6.0.402.

To Reproduce

  1. Create any test project in my case it's xUnit project targeting net7.0. (please, check test project detail below)
  2. Create any 1.rsp file with at least one switch, for example
    -p:abc=123
  3. Set environment variable DOTNET_CLI_UI_LANGUAGE to value de (German). In PowerShell
    PS > $env:DOTNET_CLI_UI_LANGUAGE = 'de'
  4. Running the following command
    PS > dotnet test .\xUnit.Tests.csproj `@1.rsp

    gives

    
    Befehl oder Argument "-p:abc=123" nicht erkannt
    Description:
    .NET-Testtreiber

Usage: dotnet test [<PROJECT | SOLUTION>] [options] [[--] ...]]

Arguments: <PROJECT | SOLUTION> Das Projekt oder die Projektmappendatei, die verwendet werden soll. Wenn keine Datei angegeben ist, durchsucht der Befehl das aktuelle Verzeichnis nach einer Datei.

Options: ...

`Befehl oder Argument "-p:abc=123" nicht erkannt` relates to `Unrecognized command or argument "-p:abc=123"` in English.

5. Set environment variable `DOTNET_CLI_UI_LANGUAGE` to value `en` (English):
``` PowerShell
PS > $env:DOTNET_CLI_UI_LANGUAGE = 'en'
  1. Running the following command
    PS > dotnet test .\xUnit.Tests.csproj `@1.rsp

    gives

    
    Determining projects to restore...
    Restored C:\Users\Maxim.Chechulnikov\sources\small-amount-of-dotnet-tests\mixed\xUnit.Tests\xUnit.Tests.csproj (in 274 ms).
    xUnit.Tests -> C:\Users\Maxim.Chechulnikov\sources\small-amount-of-dotnet-tests\mixed\xUnit.Tests\bin\Debug\net7.0\xUnit.Tests.dl
    l
    Test run for C:\Users\Maxim.Chechulnikov\sources\small-amount-of-dotnet-tests\mixed\xUnit.Tests\bin\Debug\net7.0\xUnit.Tests.dll (.NETCoreApp,Version=v7.0)
    Microsoft (R) Test Execution Command Line Tool Version 17.4.0 (x64)
    Copyright (c) Microsoft Corporation.  All rights reserved.

Starting test execution, please wait... A total of 1 test files matched the specified pattern.

Passed! - Failed: 0, Passed: 100, Skipped: 0, Total: 100, Duration: 13 ms - xUnit.Tests.dll (net7.0)


#### An example of simplest test project 
<details>
<summary>xUnit.Tests.csproj content</summary>
Content

``` xml
<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <TargetFramework>net7.0</TargetFramework>
        <ImplicitUsings>enable</ImplicitUsings>
        <Nullable>enable</Nullable>

        <IsPackable>false</IsPackable>
    </PropertyGroup>

    <ItemGroup>
        <PackageReference Include="Microsoft.NET.Test.Sdk" Version="17.1.0" />
        <PackageReference Include="xunit" Version="2.4.1" />
        <PackageReference Include="xunit.runner.visualstudio" Version="2.4.3">
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
            <PrivateAssets>all</PrivateAssets>
        </PackageReference>
        <PackageReference Include="coverlet.collector" Version="3.1.2">
            <IncludeAssets>runtime; build; native; contentfiles; analyzers; buildtransitive</IncludeAssets>
            <PrivateAssets>all</PrivateAssets>
        </PackageReference>
    </ItemGroup>

</Project>

UnitTests0.cs content Content ``` C# namespace xUnit.Tests; public class UnitTest0 { [Fact] public void Test0() { Assert.True(true); } ... // I have 100 same tests } ```
Usings.cs content Content ``` c# global using Xunit; ```
1.rsp content Content ``` -p:abc=123 ```

Further technical details

`dotnet --info` output: ``` .NET SDK: Version: 7.0.100 Commit: e12b7af219 Runtime Environment: OS Name: Windows OS Version: 10.0.22621 OS Platform: Windows RID: win10-x64 Base Path: C:\Program Files\dotnet\sdk\7.0.100\ Host: Version: 7.0.0 Architecture: x64 Commit: d099f075e4 .NET SDKs installed: 3.1.424 [C:\Program Files\dotnet\sdk] 6.0.401 [C:\Program Files\dotnet\sdk] 6.0.402 [C:\Program Files\dotnet\sdk] 7.0.100 [C:\Program Files\dotnet\sdk] .NET runtimes installed: Microsoft.AspNetCore.App 3.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App] Microsoft.NETCore.App 3.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0-rc.2.22472.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App] Microsoft.WindowsDesktop.App 3.1.30 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Microsoft.WindowsDesktop.App 7.0.0 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App] Other architectures found: x86 [C:\Program Files (x86)\dotnet] Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download ```
Evangelink commented 1 year ago

Hi @mchechulnikov, thanks for reporting this issue. I will check if that's a duplicate of the linked issue or another problem that we missed. Please stay tuned.

mchechulnikov commented 1 year ago

I'm able to reproduce it also without .rsp files but just using MSBuild switches in command line using .NET SDK 7.0.101 on macOS.

Using de

❯ dotnet test -p:abc=123
Befehl oder Argument "-p:abc=123" nicht erkannt

with en everything works well

❯ dotnet test -p:abc=123
Determining projects to restore...
All projects are up-to-date for restore.
...
dotnet --info Content ``` ❯ dotnet --info .NET SDK: Version: 7.0.101 Commit: bb24aafa11 Runtime Environment: OS Name: Mac OS X OS Version: 13.0 OS Platform: Darwin RID: osx.13-arm64 Base Path: /usr/local/share/dotnet/sdk/7.0.101/ Host: Version: 7.0.1 Architecture: arm64 Commit: 97203d38ba .NET SDKs installed: 6.0.100 [/usr/local/share/dotnet/sdk] 6.0.106 [/usr/local/share/dotnet/sdk] 6.0.200 [/usr/local/share/dotnet/sdk] 6.0.300 [/usr/local/share/dotnet/sdk] 6.0.301 [/usr/local/share/dotnet/sdk] 6.0.401 [/usr/local/share/dotnet/sdk] 6.0.403 [/usr/local/share/dotnet/sdk] 7.0.100-preview.5.22307.18 [/usr/local/share/dotnet/sdk] 7.0.100-rc.1.22431.12 [/usr/local/share/dotnet/sdk] 7.0.101 [/usr/local/share/dotnet/sdk] .NET runtimes installed: Microsoft.AspNetCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.9 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0-preview.5.22303.8 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.0-rc.1.22427.2 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.AspNetCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App] Microsoft.NETCore.App 6.0.0 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.2 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.5 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.6 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.9 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 6.0.11 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0-preview.5.22301.12 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.0-rc.1.22426.10 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Microsoft.NETCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.NETCore.App] Other architectures found: x64 [/usr/local/share/dotnet/x64] Environment variables: Not set global.json file: Not found Learn more: https://aka.ms/dotnet/info Download .NET: https://aka.ms/dotnet/download ```
FlorianHockmann commented 1 year ago

Maybe this is a duplicate of #29543 (or the other way around as this one is older, but #29543 is a bit more generic)? The error message seems to be the same and it also only occurs if the language is not en.

mchechulnikov commented 1 year ago

Not sure because we have faced with an original issue in 7.0.100, not 7.0.101.

But looks like these problems could have the same origin.

mchechulnikov commented 1 year ago

But also it looks like #29559 could help 🤞

Evangelink commented 1 year ago

We confirm that this is the same issue as #29543 and that it will be fixed by #29559

MarcoRossignoli commented 1 year ago

cc: @baronfel

baronfel commented 1 year ago

Copying the text from the latest PR update here:

I think we're in a good space now with the algorithm and the tests for this check. I'll want to get another check from @dsplaisted to make sure he's comfortable with the implementation, but then we're ready to go.

A note about the timing of this fix: we are already beyond the merge window for the January servicing release of .NET 7 (which would be 7.0.102) due to the holiday season. As a result, this fix (when approved and merged) will only be available in the Februrary servicing release at earliest (so 7.0.103). This feels really bad, and isn't a great response time given the very fast time to reporting that users had, but it's the best I can do.

In the meantime, the best thing I can suggest for users that are hitting this error is to force the CLI to the English local for dotnet test. The easiest way to do that is to set the DOTNET_CLI_UI_LANGUAGE environment variable in your shell to en-US for the duration of the test command. e.g. in Bash you'd run DOTNET_CLI_UI_LANGUAGE='en-us' dotnet test ...... Full documentation for this environment variable can be found here.

MarcoRossignoli commented 1 year ago

I'm going to close as duplicate of https://github.com/dotnet/sdk/issues/29543