dotnet / dotnet/msbuild

TestEnvironment.SetEnvironmentVariable should auto-invalidate MSBuild static caches

Open
#13,742 1 comment 0 reactions 0 assignees View on GitHub
Area: Tests triaged
Dominant language
C#
Stars
5.5k
Forks
1.5k
Avg merge
1d 8h
Merged PRs (30d)
141

Description

`TestEnvironment` is the shared test-isolation helper used across the MSBuild test suite. It already resets `ChangeWaves` and `BuildEnvironmentHelper` on dispose, so the next test starts clean.

However, when a test sets an environment variable that MSBuild reads through a cached static helper (the canonical case is `MSBUILDDISABLEFEATURESFROMVERSION`, which `ChangeWaves` reads once and caches), the new value is not observed by code under test in the same test method unless the test additionally calls:
```
ChangeWaves.ResetStateForTests();
BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly();
```

Make `TestEnvironment.SetEnvironmentVariable` invalidate the relevant static helpers automatically when the value is set. Then the manual `ChangeWaves.ResetStateForTests()` and `BuildEnvironmentHelper.ResetInstance_ForUnitTestsOnly()` calls inside test bodies (the sites listed above) can be removed.

Contributor guide

No contributing guide indexed for this repository

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.