From 32109bd3a38414095b1639038bfdfdcb2c7b3fc1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Tue, 23 Jun 2026 15:24:11 +0200 Subject: [PATCH 1/2] Drop Mono fallback, run .NET Framework tests on Windows only The .NET Framework test host (testhost.exe) only runs on Windows. On Linux and macOS vstest launched it through Mono, but Mono is no longer supported and the .NET SDK on Linux no longer ships the TestHostNetFramework folder, so dotnet test on a net462 project failed with an opaque Mono error: Cannot open assembly '.../TestHostNetFramework/testhost.exe': No such file or directory. DefaultTestHostManager now throws a clear TestPlatformException when asked to run on a non-Windows OS instead of falling back to Mono. .NET tests are unaffected, they go through DotnetTestHostManager. Breaking change: running .NET Framework tests on Linux or macOS is no longer supported. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Hosting/DefaultTestHostManager.cs | 38 +++++++-------- .../Resources/Resources.Designer.cs | 9 ++++ .../Resources/Resources.resx | 5 ++ .../Resources/xlf/Resources.cs.xlf | 9 ++++ .../Resources/xlf/Resources.de.xlf | 9 ++++ .../Resources/xlf/Resources.es.xlf | 9 ++++ .../Resources/xlf/Resources.fr.xlf | 9 ++++ .../Resources/xlf/Resources.it.xlf | 9 ++++ .../Resources/xlf/Resources.ja.xlf | 9 ++++ .../Resources/xlf/Resources.ko.xlf | 9 ++++ .../Resources/xlf/Resources.pl.xlf | 9 ++++ .../Resources/xlf/Resources.pt-BR.xlf | 9 ++++ .../Resources/xlf/Resources.ru.xlf | 9 ++++ .../Resources/xlf/Resources.tr.xlf | 9 ++++ .../Resources/xlf/Resources.zh-Hans.xlf | 9 ++++ .../Resources/xlf/Resources.zh-Hant.xlf | 9 ++++ .../FrameworkTests.cs | 36 ++++++++++++-- .../Hosting/DefaultTestHostManagerTests.cs | 48 ++++++------------- 18 files changed, 195 insertions(+), 58 deletions(-) diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index 87a84e36d7..cc634dae73 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -56,7 +56,6 @@ public class DefaultTestHostManager : ITestRuntimeProvider2 private readonly IProcessHelper _processHelper; private readonly IFileHelper _fileHelper; private readonly IEnvironment _environment; - private readonly IDotnetHostHelper _dotnetHostHelper; private readonly IEnvironmentVariableHelper _environmentVariableHelper; private bool _disableAppDomain; private Architecture _architecture; @@ -78,7 +77,6 @@ public DefaultTestHostManager() : this( new ProcessHelper(), new FileHelper(), - new DotnetHostHelper(), new PlatformEnvironment(), new EnvironmentVariableHelper()) { @@ -91,17 +89,14 @@ public DefaultTestHostManager() /// File helper instance. /// Instance of platform environment. /// The environment helper. - /// Instance of dotnet host helper. internal DefaultTestHostManager( IProcessHelper processHelper, IFileHelper fileHelper, - IDotnetHostHelper dotnetHostHelper, IEnvironment environment, IEnvironmentVariableHelper environmentVariableHelper) { _processHelper = processHelper; _fileHelper = fileHelper; - _dotnetHostHelper = dotnetHostHelper; _environment = environment; _environmentVariableHelper = environmentVariableHelper; } @@ -210,28 +205,27 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( EqtTrace.Verbose("DefaultTestHostmanager.GetTestHostProcessStartInfo: Trying to use {0} from {1}", originalTestHostProcessName, testhostProcessPath); + // .NET Framework tests run through testhost.exe, which can only run on Windows. + // Running them on other operating systems previously relied on Mono, which is no + // longer supported. Fail with a clear message instead of launching Mono. + if (!_environment.OperatingSystem.Equals(PlatformOperatingSystem.Windows)) + { + throw new TestPlatformException( + string.Format(CultureInfo.CurrentCulture, Resources.NetFrameworkTestsNotSupportedOnNonWindows)); + } + var launcherPath = testhostProcessPath; var processName = _processHelper.GetCurrentProcessFileName(); if (processName is not null) { - if (!_environment.OperatingSystem.Equals(PlatformOperatingSystem.Windows) - && !processName.EndsWith(DotnetHostHelper.MONOEXENAME, StringComparison.OrdinalIgnoreCase)) - { - launcherPath = _dotnetHostHelper.GetMonoPath(); - argumentsString = testhostProcessPath.AddDoubleQuote() + " " + argumentsString; - } - else + // Patching the relative path for IDE scenarios. + if (!(processName.EndsWith("dotnet", StringComparison.OrdinalIgnoreCase) + || processName.EndsWith("dotnet.exe", StringComparison.OrdinalIgnoreCase)) + && !File.Exists(testhostProcessPath)) { - // Patching the relative path for IDE scenarios. - if (_environment.OperatingSystem.Equals(PlatformOperatingSystem.Windows) - && !(processName.EndsWith("dotnet", StringComparison.OrdinalIgnoreCase) - || processName.EndsWith("dotnet.exe", StringComparison.OrdinalIgnoreCase)) - && !File.Exists(testhostProcessPath)) - { - testhostProcessPath = Path.Combine(currentWorkingDirectory, "..", originalTestHostProcessName); - EqtTrace.Verbose("DefaultTestHostmanager.GetTestHostProcessStartInfo: Could not find {0} in previous location, now using {1}", originalTestHostProcessName, testhostProcessPath); - launcherPath = testhostProcessPath; - } + testhostProcessPath = Path.Combine(currentWorkingDirectory, "..", originalTestHostProcessName); + EqtTrace.Verbose("DefaultTestHostmanager.GetTestHostProcessStartInfo: Could not find {0} in previous location, now using {1}", originalTestHostProcessName, testhostProcessPath); + launcherPath = testhostProcessPath; } } diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.Designer.cs b/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.Designer.cs index 4b3c612666..98248f73dd 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.Designer.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.Designer.cs @@ -111,5 +111,14 @@ internal static string NoDotnetMuxerFoundForArchitecture } } + /// + /// Looks up a localized string similar to Running .NET Framework tests is supported on Windows only.. + /// + internal static string NetFrameworkTestsNotSupportedOnNonWindows { + get { + return ResourceManager.GetString("NetFrameworkTestsNotSupportedOnNonWindows", resourceCulture); + } + } + } } diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.resx b/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.resx index a5850f83c6..9aafbc4eda 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.resx +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/Resources.resx @@ -147,4 +147,9 @@ The specified framework can be found at: '{0}' is the placeholder for 'dotnet.exe' or 'dotnet' value and depends on platform Windows/Unix, '{1}' is the placeholder for the architeture name like ARM64, X64 etc... + + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + \ No newline at end of file diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.cs.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.cs.xlf index 1246ba96df..8fe92b0e8a 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.cs.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.cs.xlf @@ -26,6 +26,15 @@ Ověřte, že: {0} + + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + + Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk". Nejde najít {0}. Ujistěte se, že testovací projekt má odkaz na balíček nuget Microsoft.NET.Test.Sdk. diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.de.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.de.xlf index 8333c34568..a4a148e621 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.de.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.de.xlf @@ -26,6 +26,15 @@ Bestätigen Sie, dass: {0} + + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + + Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk". "{0}" wurde nicht gefunden. Stellen Sie sicher, dass das Testprojekt einen NuGet-Verweis des Pakets "Microsoft.NET.Test.Sdk" aufweist. diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.es.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.es.xlf index 44c79eb54f..9f44a85e41 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.es.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.es.xlf @@ -26,6 +26,15 @@ Compruebe que: {0} + + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + + Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk". No se encuentra {0}. Asegúrese de que el proyecto de prueba tenga una referencia NuGet del paquete "Microsoft.NET.Test.Sdk". diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.fr.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.fr.xlf index 01c65b16c6..8027a007c6 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.fr.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.fr.xlf @@ -26,6 +26,15 @@ Vérifiez ce qui suit : {0} + + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + + Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk". {0} est introuvable. Vérifiez que le projet de test a une référence nuget du package "Microsoft.NET.Test.Sdk". diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.it.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.it.xlf index 2a27a568f0..cc456effc7 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.it.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.it.xlf @@ -26,6 +26,15 @@ Verificare che: {0} + + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + + Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk". Non è possibile trovare {0}. Assicurarsi che il progetto di test includa un riferimento NuGet del pacchetto "Microsoft.NET.Test.Sdk". diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ja.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ja.xlf index 09a00dd654..19326baa58 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ja.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ja.xlf @@ -26,6 +26,15 @@ Verify that: {0} + + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + + Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk". {0} を見つけることができません。テスト プロジェクトにパッケージ "Microsoft.NET.Test.Sdk" の NuGet 参照があることを確認してください。 diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ko.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ko.xlf index 88773a5784..5818e27d28 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ko.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ko.xlf @@ -26,6 +26,15 @@ Verify that: {0} + + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + + Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk". {0}을(를) 찾을 수 없습니다. 테스트 프로젝트에 "Microsoft.NET.Test.Sdk" 패키지의 nuget 참조가 포함되어 있는지 확인하세요. diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pl.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pl.xlf index 4959e232ca..0376620b20 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pl.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pl.xlf @@ -26,6 +26,15 @@ Sprawdź, czy: {0} + + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + + Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk". Nie można znaleźć elementu {0}. Upewnij się, że projekt testowy ma odwołanie nuget do pakietu „Microsoft.NET.Test.Sdk”. diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pt-BR.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pt-BR.xlf index 5a61e3e934..a2a8567eeb 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pt-BR.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.pt-BR.xlf @@ -26,6 +26,15 @@ Verifique se: {0} + + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + + Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk". Não foi possível localizar {0}. Certifique-se de que o projeto de teste tem uma referência nuget do pacote "Microsoft.NET.Test.Sdk". diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ru.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ru.xlf index 4262a63f6f..eccc6af287 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ru.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.ru.xlf @@ -26,6 +26,15 @@ Verify that: {0} + + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + + Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk". Не удается найти {0}. Убедитесь, что в тестовом проекте есть ссылка NuGet на пакет "Microsoft.NET.Test.Sdk". diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.tr.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.tr.xlf index 8372c3a1a0..daef6fcd2b 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.tr.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.tr.xlf @@ -26,6 +26,15 @@ Verify that: {0} + + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + + Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk". {0} bulunamıyor. Test projesinin "Microsoft.NET.Test.Sdk" paketinde nuget başvurusu olduğundan emin olun. diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hans.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hans.xlf index 6aced291ad..fde22fbdda 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hans.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hans.xlf @@ -26,6 +26,15 @@ Verify that: {0} + + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + + Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk". 无法找到 {0}。确保测试项目具有包 "Microsoft.NET.Test.Sdk" 的 nuget 引用。 diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hant.xlf b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hant.xlf index 9cdad4d9b6..d9bf964ed0 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hant.xlf +++ b/src/Microsoft.TestPlatform.TestHostProvider/Resources/xlf/Resources.zh-Hant.xlf @@ -27,6 +27,15 @@ Verify that: {0} + + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + Running .NET Framework tests is supported on Windows only. + +Running .NET Framework tests on this operating system relied on Mono, which is no longer supported. To run these tests, run them on Windows, or change the test project to target .NET instead of .NET Framework. + + Unable to find {0}. Make sure test project has a nuget reference of package "Microsoft.NET.Test.Sdk". 找不到 {0}。請確認測試專案有 "Microsoft.NET.Test.Sdk "套件的 nuget 參考。 diff --git a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/FrameworkTests.cs b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/FrameworkTests.cs index c08561abe9..5d9dbefb88 100644 --- a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/FrameworkTests.cs +++ b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/FrameworkTests.cs @@ -87,10 +87,14 @@ public void RunSpecificTestsShouldWorkWithFrameworkInCompatibleWarning(RunnerInf // but the settings requested .NET Framework 4.0. The test will still run because .NET Framework is compatible, and in reality // the system has .NET Framework 481 or newer installed, which runs even if we ask for .NET Framework 4.0 testhost. // - // On Linux and Mac we execute only net11.0 tests, and even though we force .NET Framework, we end up running on mono - // which is suprisingly able to run the .NET CoreApp dll, so we still just see a warning and 1 completed test. + // This test is Windows-Review only, so it does not run on Linux or Mac in CI. If it is run there manually, + // forcing .NET Framework now fails fast, because the .NET Framework test host is no longer launched through Mono. var isWindows = Environment.OSVersion.Platform.ToString().StartsWith("Win"); - if (runnerInfo.TargetFramework.Contains("net11") && isWindows) + if (!isWindows) + { + StdErrorContains("Running .NET Framework tests is supported on Windows only"); + } + else if (runnerInfo.TargetFramework.Contains("net11")) { StdOutputContains("No test is available"); } @@ -100,4 +104,30 @@ public void RunSpecificTestsShouldWorkWithFrameworkInCompatibleWarning(RunnerInf ValidateSummaryStatus(1, 0, 0); } } + + [TestMethod] + [NetCoreTargetFrameworkDataSource] + public void RunningNetFrameworkTestsOnNonWindowsShouldFailWithClearError(RunnerInfo runnerInfo) + { + SetTestEnvironment(_testEnvironment, runnerInfo); + + // Force the run to use the .NET Framework test host (testhost.exe). That host exists only on + // Windows. On other operating systems we used to fall back to Mono, which is no longer supported, + // so the run should fail fast with a clear, actionable message instead of an opaque Mono error. + var arguments = PrepareArguments(GetSampleTestAssembly(), string.Empty, string.Empty, string.Empty, resultsDirectory: TempDirectory.Path); + arguments = string.Concat(arguments, " ", "/Framework:Framework40"); + + InvokeVsTest(arguments); + + var isWindows = Environment.OSVersion.Platform.ToString().StartsWith("Win"); + if (isWindows) + { + // On Windows the .NET Framework test host is available, so the "Windows only" error must not appear. + StdErrorDoesNotContains("Running .NET Framework tests is supported on Windows only"); + } + else + { + StdErrorContains("Running .NET Framework tests is supported on Windows only"); + } + } } diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs index 68bf9ab331..59167b151a 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs @@ -37,7 +37,6 @@ public class DefaultTestHostManagerTests private readonly Mock _mockMessageLogger; private readonly Mock _mockProcessHelper; private readonly Mock _mockFileHelper; - private readonly Mock _mockDotnetHostHelper; private readonly Mock _mockEnvironment; private readonly Mock _mockEnvironmentVariable; private readonly DefaultTestHostManager _testHostManager; @@ -54,13 +53,12 @@ public DefaultTestHostManagerTests() _mockProcessHelper = new Mock(); _mockFileHelper = new Mock(); _mockProcessHelper.Setup(ph => ph.GetCurrentProcessFileName()).Returns("vstest.console.exe"); - _mockDotnetHostHelper = new Mock(); _mockEnvironment = new Mock(); _mockEnvironmentVariable = new Mock(); _mockMessageLogger = new Mock(); - _testHostManager = new DefaultTestHostManager(_mockProcessHelper.Object, _mockFileHelper.Object, _mockDotnetHostHelper.Object, _mockEnvironment.Object, _mockEnvironmentVariable.Object); + _testHostManager = new DefaultTestHostManager(_mockProcessHelper.Object, _mockFileHelper.Object, _mockEnvironment.Object, _mockEnvironmentVariable.Object); _testHostManager.Initialize(_mockMessageLogger.Object, $" {Architecture.X64} {Framework.DefaultFramework} {false} "); _startInfo = _testHostManager.GetTestHostProcessStartInfo([], null, default); } @@ -177,38 +175,22 @@ public void GetTestHostProcessStartInfoShouldIncludeTestSourcePathInArgumentsIfN } [TestMethod] - public void GetTestHostProcessStartInfoShouldUseMonoAsHostOnNonWindowsIfNotStartedWithMono() + [DataRow(PlatformOperatingSystem.Unix, "/usr/bin/dotnet")] + [DataRow(PlatformOperatingSystem.Unix, "/usr/bin/mono")] + [DataRow(PlatformOperatingSystem.OSX, "/usr/local/share/dotnet/dotnet")] + [DataRow(PlatformOperatingSystem.OSX, "/usr/local/bin/mono")] + public void GetTestHostProcessStartInfoShouldThrowWhenRunningNetFrameworkTestsOnNonWindows(PlatformOperatingSystem operatingSystem, string currentProcessFileName) { - _mockProcessHelper.Setup(p => p.GetCurrentProcessFileName()).Returns("/usr/bin/dotnet"); - _mockEnvironment.Setup(e => e.OperatingSystem).Returns(PlatformOperatingSystem.Unix); - _mockDotnetHostHelper.Setup(d => d.GetMonoPath()).Returns("/usr/bin/mono"); - var source = @"C:\temp\a.dll"; - - var info = _testHostManager.GetTestHostProcessStartInfo( - new List() { source }, - null, - default); - - Assert.AreEqual("/usr/bin/mono", info.FileName); - Assert.Contains(Path.Combine("TestHostNetFramework", "testhost.exe"), info.Arguments!); - } + // .NET Framework tests can only run on Windows. On other operating systems we no longer + // fall back to Mono and instead fail with a clear, actionable message. + _mockProcessHelper.Setup(p => p.GetCurrentProcessFileName()).Returns(currentProcessFileName); + _mockEnvironment.Setup(e => e.OperatingSystem).Returns(operatingSystem); + var source = "/tmp/a.dll"; - [TestMethod] - public void GetTestHostProcessStartInfoShouldNotUseMonoAsHostOnNonWindowsIfStartedWithMono() - { - _mockProcessHelper.Setup(p => p.GetCurrentProcessFileName()).Returns("/usr/bin/mono"); - _mockEnvironment.Setup(e => e.OperatingSystem).Returns(PlatformOperatingSystem.Unix); - _mockDotnetHostHelper.Setup(d => d.GetMonoPath()).Returns("/usr/bin/mono"); - var source = @"C:\temp\a.dll"; - - var info = _testHostManager.GetTestHostProcessStartInfo( - new List() { source }, - null, - default); + var exception = Assert.ThrowsExactly( + () => _testHostManager.GetTestHostProcessStartInfo(new List() { source }, null, default)); - var testHostPath = Path.Combine("TestHostNetFramework", "testhost.exe"); - Assert.EndsWith(testHostPath, info.FileName); - Assert.DoesNotContain(testHostPath, info.Arguments!); + Assert.Contains("Windows", exception.Message); } [TestMethod] @@ -656,7 +638,7 @@ public TestableTestHostManager( IProcessHelper processHelper, bool shared, IMessageLogger logger) - : base(processHelper, new FileHelper(), new DotnetHostHelper(), new PlatformEnvironment(), new EnvironmentVariableHelper()) + : base(processHelper, new FileHelper(), new PlatformEnvironment(), new EnvironmentVariableHelper()) { Initialize(logger, $" {architecture} {framework} {!shared} "); } From 88d59ce6a4ee427f323b1cfd8f2b0ea39b2e9ad8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Jakub=20Jare=C5=A1?= Date: Tue, 23 Jun 2026 17:45:52 +0200 Subject: [PATCH 2/2] Address review: stricter assertions, drop no-op string.Format - Throw the resource string directly instead of string.Format with no args (avoids a latent FormatException if a translation ever adds braces). - Unit test asserts the full "supported on Windows only" sentence, not just "Windows". - Acceptance test asserts ExitCodeEquals(1) on non-Windows to prove the run fails fast, not just logs a warning. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com> --- .../Hosting/DefaultTestHostManager.cs | 3 +-- .../FrameworkTests.cs | 2 ++ .../Hosting/DefaultTestHostManagerTests.cs | 2 +- 3 files changed, 4 insertions(+), 3 deletions(-) diff --git a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs index cc634dae73..0452489908 100644 --- a/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs +++ b/src/Microsoft.TestPlatform.TestHostProvider/Hosting/DefaultTestHostManager.cs @@ -210,8 +210,7 @@ public virtual TestProcessStartInfo GetTestHostProcessStartInfo( // longer supported. Fail with a clear message instead of launching Mono. if (!_environment.OperatingSystem.Equals(PlatformOperatingSystem.Windows)) { - throw new TestPlatformException( - string.Format(CultureInfo.CurrentCulture, Resources.NetFrameworkTestsNotSupportedOnNonWindows)); + throw new TestPlatformException(Resources.NetFrameworkTestsNotSupportedOnNonWindows); } var launcherPath = testhostProcessPath; diff --git a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/FrameworkTests.cs b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/FrameworkTests.cs index 5d9dbefb88..0062597245 100644 --- a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/FrameworkTests.cs +++ b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/FrameworkTests.cs @@ -127,7 +127,9 @@ public void RunningNetFrameworkTestsOnNonWindowsShouldFailWithClearError(RunnerI } else { + // The run must fail fast with a clear message, not merely log a warning. StdErrorContains("Running .NET Framework tests is supported on Windows only"); + ExitCodeEquals(1); } } } diff --git a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs index 59167b151a..b8d8102b9a 100644 --- a/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs +++ b/test/Microsoft.TestPlatform.TestHostProvider.UnitTests/Hosting/DefaultTestHostManagerTests.cs @@ -190,7 +190,7 @@ public void GetTestHostProcessStartInfoShouldThrowWhenRunningNetFrameworkTestsOn var exception = Assert.ThrowsExactly( () => _testHostManager.GetTestHostProcessStartInfo(new List() { source }, null, default)); - Assert.Contains("Windows", exception.Message); + Assert.Contains("Running .NET Framework tests is supported on Windows only", exception.Message); } [TestMethod]