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

Config for unitTestDebuggingOptions is Ignored Since Change to Roslyn default #6104

Closed
rtablada opened this issue Aug 10, 2023 · 3 comments
Closed

Comments

@rtablada
Copy link

Environment data

dotnet --info output:

 Version:   7.0.101
 Commit:    bb24aafa11

Runtime Environment:
 OS Name:     Mac OS X
 OS Version:  13.3
 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:
  7.0.101 [/usr/local/share/dotnet/sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 7.0.1 [/usr/local/share/dotnet/shared/Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 7.0.1 [/usr/local/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

VS Code version:
C# Extension version: 2.0.328

OmniSharp log

Steps to reproduce

  1. Create a .env file with value set that is not set in global path (ex MY_TEST_VAR=this-should-display
  2. In VSCode settings set "csharp.unitTestDebuggingOptions": { "envFile": "${workspaceFolder}/.testing.env" }
  3. Create XUnit Fact with System.Environment.GetEnvironmentVariable<string>("MY_TEST_VAR")
  4. Add Breakpoint after getting this env var
  5. Run Debug Test
  6. Check value at breakpoint (should be set but is null

Expected behavior

With the Roslyn editor there should still be a way to set and change environment variables for test runs/debugging. Ideally existing config from previous versions of vscode-csharp would be able to be migrated or configs would still work with existing keys. Otherwise, the replacement or changes to this behavior should be documented (previously documented in the wiki)

Actual behavior

The envFile value from csharp.unitTestDebuggingOptions is no longer loaded for unit tests with version >2.0.320 and when using Roslyn language server.

Additional context

This config has been working and is still documented in the Wiki with no replacement docs or functionality: https://github.com/dotnet/vscode-csharp/wiki/How-to-run-and-debug-unit-tests

@dibarbet
Copy link
Member

Thanks - yup csharp.unitTestDebuggingOptions is one of the reasons #5719 is not closed. Added a mention of these here - #5719 (comment)

Note - technically csharp.unitTestDebuggingOptions doesn't list support for an envFile option as a valid property - it happened to work in O# due to how O# started test debugging, but it will not work in the new version (O# launched the test host process itself so could set env vars, in the new version we delegate that work to the dotnet test platform).

Instead, the correct way to specify environment variables for tests would be via a .runsettings file - see https://learn.microsoft.com/en-us/visualstudio/test/configure-unit-tests-by-using-a-dot-runsettings-file?view=vs-2022#specify-environment-variables-in-the-runsettings-file
(though .runsettings support is also still pending).

Going to close this issue as a duplicate of #5719

@rtablada
Copy link
Author

rtablada commented Aug 15, 2023

@dibarbet when the release versions of this and devkit support runsettings for tests: is there a .envFile equivalent for only tests in a full SLN using .runsettings?

Our team has been on Netcore with Rider and VScode exclusively for the lifecycle of our project and making a 1:1 comparison with OG VS docs can sometimes be tricky.

For more context, our team has committed VSCode config but we use an extensive set of non-committed .env files to make sure we're not committing secrets or configs that may vary between individual team members

@dibarbet
Copy link
Member

Ah if you're using devkit, then I think there's likely a different way of configuring unit test settings (my change only applies if you're using C# w/out devkit).

Tagging @peterwald to advise on how to configure unit test settings in devkit

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants