-
Notifications
You must be signed in to change notification settings - Fork 328
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
Cannot define environment variables in .runsettings file #2819
Comments
@danielcor, can you share the version of the Test Platform you're using? A quick repro would be great to investigate this; if not, please run your tests enabling diagnostic logs and share them with us. |
I just checked and it is true. We do not read |
dotnet --version returns 5.0.200 and I'm running on Microsoft Windows I'm using the same version of the mstest nugets in both:
I tried creating a test case, and the environment variable was set as they should be, but the diagnostic file, showed the same error, which is peculiar. TpTrace Warning: 0 : 29356, 4, 2021/03/11, 17:09:17.457, 297788799430, testhost.dll, Invalid settings 'RunConfiguration'. Unexpected XmlElement: 'EnvironmentVariables'. diag.host.21-03-11_17-09-16_12753_6.txt Unfortunately my unit test is much more complicated, and I can't share it.. So will continue to try see what the difference is that causes it not to read this Xml section. |
That isn't true. The EnvironmentArgumentProcessor and other code paths read the environment variables from the runsettings file:
|
That explains the error message. What it doesn't explain is why it works sometimes and not other times. A new test project I created in my solution that uses the same .runsettings, set solution wide in Test/ConfigureRunsettings is able to read an environment variable, and another can't. The test case that created the diagnostic above, I shared below. Works but produces an error in the diagnostics when run from the command line like: dotnet test -d diag.txt -s .\test.runsettings . |
OK, I figured out why my complex unit tests weren't doing as expected. I left out the line of code where I read in the environment variables to be included in Configuration. However, could someone fix the incorrect error message? It led me to troubleshoot the wrong thing! |
@ViktorHofer You are right I missed that part. For
@danielcor We can think about fixing error message for |
dotnet/vscode-csharp#5131 (comment) Another example of how to properly set runsettings. |
.runsettings is supposed to have an XML section for environment variables, and while Microsoft has documented that, it doesn't seem to work, and I find almost nothing on it:
A unit test in this repository has:
but that gives me:
TpTrace Warning: 0 : 12628, 4, 2021/03/11, 16:23:38.052, 270394899679, testhost.dll, Invalid settings 'RunConfiguration'. Unexpected XmlElement: 'EnvironmentVariables'.
Thoughts? I want something that runs in Visual Studio as well as something I can run in Jenkins.
Originally posted by @danielcor in #669 (comment)
The text was updated successfully, but these errors were encountered: