question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet test does not find any tests if environment variable is set that ends with dll

See original GitHub issue

Describe the bug

We use environment variables in some integration test solutions. During our testing we encountered a strange behavior of the dotnet test command. If you provide any environment variable using the -e, --environmentoption where the value ends on dll, the whole test scripts stops working and the cli does not find any tests anymore.

I assume that for some reason the cli interprets the ending dll as solution/project/library in which to search for tests instead of the given solution or project. Funny enough csproj or sln at the end of any environment variable does not cause any issues.

Command Result
`dotnet test -t OK
dotnet test -t -e foo=bar OK
dotnet test -t -e foo=bardll FAIL
dotnet test -t -e foodll=bar OK
dotnet test -t -e foo=barsln OK
dotnet test -t -e foo=barcsproj OK

To Reproduce

  1. Create a bare-bone test project
  2. Run tests using dotnet test with any environment variable option whose value ends with dll
  3. No tests will be found

Setup

dotnet new xunit -o Example.Tests
cd Example.Tests

Normal Behavior

dotnet test -t
# also this one is fine
dotnet test -t -e foo=bar
C:\Temp\tests\Example.Tests> dotnet test -t
  Determining projects to restore...
  All projects are up-to-date for restore.
  Example.Tests -> C:\Temp\tests\Example.Tests\bin\Debug\net6.0\Example.Tests.dll
Test run for C:\Temp\tests\Example.Tests\bin\Debug\net6.0\Example.Tests.dll (.NETCoreApp,Version=v6.0)
Microsoft (R) Test Execution Command Line Tool Version 17.1.0
Copyright (c) Microsoft Corporation.  All rights reserved.

The following Tests are available:
    Example.Tests.UnitTest1.Test1

Failing Cases

dotnet test -t -e foo=bardll
C:\Temp\tests\Example.Tests> dotnet test -t -e foo=bardll
Microsoft (R) Test Execution Command Line Tool Version 17.1.0
Copyright (c) Microsoft Corporation.  All rights reserved.

No test source files were specified.

Exceptions (if any)

Further technical details

.NET SDK (reflecting any global.json):
 Version:   6.0.203
 Commit:    a20feadf6d

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19044
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\6.0.203\

global.json file:
  Not found

Host:
  Version:      6.0.9
  Architecture: x64
  Commit:       163a63591c

.NET SDKs installed:
  3.1.423 [C:\Program Files\dotnet\sdk]
  5.0.214 [C:\Program Files\dotnet\sdk]
  5.0.402 [C:\Program Files\dotnet\sdk]
  5.0.408 [C:\Program Files\dotnet\sdk]
  6.0.200 [C:\Program Files\dotnet\sdk]
  6.0.203 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.All 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 3.1.29 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.11 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 5.0.17 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.2 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.30 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 3.1.29 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 5.0.11 [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.2 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 3.1.20 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 3.1.29 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 5.0.11 [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.2 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.9 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

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

Learn about .NET Runtimes and SDKs:
  https://aka.ms/dotnet/runtimes-sdk-info

Issue Analytics

  • State:closed
  • Created a year ago
  • Comments:5 (4 by maintainers)

github_iconTop GitHub Comments

1reaction
jcoeltjencommented, Oct 24, 2022

Hi @MarcoRossignoli , this is currently not a blocking issue for us as we restructured our code in a way that we currently do not use the environment variable that caused issues anymore.

I am looking forward to trying the fix anyway. Thanks for the swift response and the quick PR!

0reactions
MarcoRossignolicommented, Oct 25, 2022

Thanks @jcoeltjen for the quick response, the fix will be released on 7.0.200 version of the SDK won’t be shipped for 7.0.100 GA.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Passing the ASP.NET Core Environment to the Dotnet Test ...
On Windows you can set environment variable for Process, User or Machine, but not for current command. Workarounds exists, but they require ...
Read more >
dotnet test command - .NET CLI
Creates the variable if it does not exist, overrides if it does exist. Use of this option will force the tests to be...
Read more >
Configure unit tests by using a .runsettings file
Runsettings files can be used to configure tests that are run from the command line, from the IDE, or in a build workflow...
Read more >
dotnet test with XUnit fails because of the wrongly resolved ...
I'm using "Previous Visual Studio 2017" image and XUnit was working fine for ... The test source file ... Tests.dll" provided was not...
Read more >
Environment.GetEnvironmentVariable Method (System)
Retrieves the value of an environment variable. ... bool toDelete = false; // Check whether the environment variable exists. value = Environment.
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found