Skip to content
This repository was archived by the owner on Dec 5, 2022. It is now read-only.
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
32 changes: 32 additions & 0 deletions RFCs/0027-Specify-Environment-Variables-In-Runsettings.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,32 @@
# 0027 Specifying Environment Variables In RunSettings File

## Summary
Specifying environment variables in the runsettings file. The environment variables can be set which can directly interact with the test host.

## Motivation
Specifying environment variables in the runsettings file is necessary to support non-trivial projects that require settings env vars like DOTNET_ROOT. These variables are set while spawning the test host process, thus will be available in the host.

## Usage
The runsettings contains a "EnvironmentVariables" node in the RunConfiguration section.
The different environment variables can be specified as element name and it's value.
Below is a sample runsettings for passing environment variables.

```csharp

<?xml version="1.0" encoding="utf-8"?>
<!-- File name extension must be .runsettings -->
<RunSettings>
<RunConfiguration>
<EnvironmentVariables>
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: do you usually use plural or singular? I.e. you have RunSettings (plural) but also RunConfiguration (singular).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

For the EnvironmentVariables, it made sense to use plural to infer that multiple values are allowed.

<!-- List of environment variables we want to set-->
<DOTNET_ROOT>C:\ProgramFiles\dotnet</DOTNET_ROOT>
<SDK_PATH>C:\Codebase\Sdk</SDK_PATH>
</EnvironmentVariables>
</RunConfiguration>
</RunSettings>


```
Since these environment variables should always be set when the test host is started, the tests should always run in a separate process.
For this, the `/InIsolation` flag will be set when there are environment variables so that the test host is always invoked.
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it makes sense to not set the InIsolation flag when env vars are set as others who aren't running in isolation want to use this feature as well, not for the testhost invocation but inside the test app.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In certain specific cases, we run the tests inside vstest.console process without starting the testhost process. Since we are planning to set the environment variables when starting the test host, these cases will not be encountered for. This flag will insure that the test host is launched with the correct variables.

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we support both cases?

  1. Set env vars before the testhost process is started
  2. If tests are executed directly in vstest.console, set the env vars before invoking the tests.