From d8797c2a1fbaab307bba5f083fa3daf58162f904 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 9 Oct 2026 17:36:36 +1100 Subject: [PATCH 1/2] Stop treating WSL as a build server --- src/DiffEngine/BuildServerDetector.cs | 1 - src/Directory.Build.props | 2 +- 2 files changed, 1 insertion(+), 2 deletions(-) diff --git a/src/DiffEngine/BuildServerDetector.cs b/src/DiffEngine/BuildServerDetector.cs index d0e92fd24..485c70da0 100644 --- a/src/DiffEngine/BuildServerDetector.cs +++ b/src/DiffEngine/BuildServerDetector.cs @@ -65,7 +65,6 @@ static BuildServerDetector() IsMyGet || IsGoDc || IsDocker || - IsWsl || IsAppVeyor || IsBitbucketPipelines; } diff --git a/src/Directory.Build.props b/src/Directory.Build.props index 0d39a80b3..69ab8b7d9 100644 --- a/src/Directory.Build.props +++ b/src/Directory.Build.props @@ -1,7 +1,7 @@ - 20.7.2 + 20.8.0 1.0.0 Testing, Snapshot, Diff, Compare Launches diff tools based on file extensions. Designed to be consumed by snapshot testing libraries. From 7b841dc854e2212f8c7342314e35caca11644983 Mon Sep 17 00:00:00 2001 From: Simon Cropp Date: Fri, 9 Oct 2026 17:41:53 +1100 Subject: [PATCH 2/2] Document detecting a build that runs under WSL --- readme.md | 28 ++++++++++++++++++++++++++++ readme.source.md | 27 +++++++++++++++++++++++++++ 2 files changed, 55 insertions(+) diff --git a/readme.md b/readme.md index e355c757f..1d62ff03b 100644 --- a/readme.md +++ b/readme.md @@ -44,6 +44,7 @@ DiffEngine manages launching and cleanup of diff tools. It is designed to be use * [Closing a tool](#closing-a-tool) * [File type detection](#file-type-detection) * [BuildServerDetector](#buildserverdetector) + * [WSL](#wsl) * [Override in tests](#override-in-tests) * [Automatic AI detection](#automatic-ai-detection) * [Programmatic usage](#programmatic-usage) @@ -193,6 +194,33 @@ var isBitbucketPipelines = BuildServerDetector.IsBitbucketPipelines; +### WSL + +Running under [WSL](https://learn.microsoft.com/en-us/windows/wsl/about) is not treated as a build server, since a WSL session is usually a developer machine. `BuildServerDetector.IsWsl` reports it, and `BuildServerDetector.Detected` ignores it. + +A build that runs its tests inside WSL from a Windows build agent is the case to watch. The variables the build server sets exist on the Windows side, and WSL only passes across the ones named in [WSLENV](https://learn.microsoft.com/en-us/windows/wsl/filesystems#share-environment-variables-between-windows-and-wsl-with-wslenv). So inside WSL nothing is detected, and diff tools are launched on the build agent. + +To have such a build detected, either name the build server's variable in `WSLENV` on the Windows side, for example on Azure DevOps: + +``` +set WSLENV=TF_BUILD:%WSLENV% +``` + +or set one of the detected variables on the command that starts the tests: + +``` +wsl -- env TF_BUILD=True dotnet test +``` + +To treat every WSL run as a build server, in a test: + +```cs +BuildServerDetector.Detected = BuildServerDetector.Detected || BuildServerDetector.IsWsl; +``` + +That value is scoped to the current async context, as described below. + + ### Override in tests `BuildServerDetector.Detected` can be set at test time. The value is stored in an `AsyncLocal`, so it is scoped to the current async context and does not leak to other threads or tests running in parallel. diff --git a/readme.source.md b/readme.source.md index 23206ecf6..9ac3d547b 100644 --- a/readme.source.md +++ b/readme.source.md @@ -89,6 +89,33 @@ There are also individual properties to check for each specific build system snippet: BuildServerDetectorProps +### WSL + +Running under [WSL](https://learn.microsoft.com/en-us/windows/wsl/about) is not treated as a build server, since a WSL session is usually a developer machine. `BuildServerDetector.IsWsl` reports it, and `BuildServerDetector.Detected` ignores it. + +A build that runs its tests inside WSL from a Windows build agent is the case to watch. The variables the build server sets exist on the Windows side, and WSL only passes across the ones named in [WSLENV](https://learn.microsoft.com/en-us/windows/wsl/filesystems#share-environment-variables-between-windows-and-wsl-with-wslenv). So inside WSL nothing is detected, and diff tools are launched on the build agent. + +To have such a build detected, either name the build server's variable in `WSLENV` on the Windows side, for example on Azure DevOps: + +``` +set WSLENV=TF_BUILD:%WSLENV% +``` + +or set one of the detected variables on the command that starts the tests: + +``` +wsl -- env TF_BUILD=True dotnet test +``` + +To treat every WSL run as a build server, in a test: + +```cs +BuildServerDetector.Detected = BuildServerDetector.Detected || BuildServerDetector.IsWsl; +``` + +That value is scoped to the current async context, as described below. + + ### Override in tests `BuildServerDetector.Detected` can be set at test time. The value is stored in an `AsyncLocal`, so it is scoped to the current async context and does not leak to other threads or tests running in parallel.