diff --git a/Directory.Build.targets b/Directory.Build.targets index f0c700ee2e..6d96423635 100644 --- a/Directory.Build.targets +++ b/Directory.Build.targets @@ -4,7 +4,18 @@ <_NetFrameworkHostedCompilersVersion Condition="'$(_NetFrameworkHostedCompilersVersion)' == ''">4.11.0-3.24280.3 - + + + $(DefineConstants);IS_VSTEST_REPO + + $(MSBuildWarningsAsMessages);MSB3277 + + diff --git a/eng/Versions.props b/eng/Versions.props index 65d997fd1f..f3ef3e1262 100644 --- a/eng/Versions.props +++ b/eng/Versions.props @@ -70,7 +70,7 @@ <_MicrosoftVSSDKBuildToolsVersion_>17.14.2119 5.0.0 13.0.3 - 9.0.11 + 10.0.0 4.5.5 8.0.0 18.0.0-preview-1-10911-061 diff --git a/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj b/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj index 866225a77c..6776a4de05 100644 --- a/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj +++ b/src/Microsoft.TestPlatform.CoreUtilities/Microsoft.TestPlatform.CoreUtilities.csproj @@ -19,6 +19,7 @@ + diff --git a/src/Microsoft.TestPlatform.ObjectModel/Microsoft.TestPlatform.ObjectModel.csproj b/src/Microsoft.TestPlatform.ObjectModel/Microsoft.TestPlatform.ObjectModel.csproj index 1675d4cb00..0d20b23a19 100644 --- a/src/Microsoft.TestPlatform.ObjectModel/Microsoft.TestPlatform.ObjectModel.csproj +++ b/src/Microsoft.TestPlatform.ObjectModel/Microsoft.TestPlatform.ObjectModel.csproj @@ -37,6 +37,7 @@ + diff --git a/src/datacollector/app.config b/src/datacollector/app.config index d464fe4c5d..3b5c8143b9 100644 --- a/src/datacollector/app.config +++ b/src/datacollector/app.config @@ -22,11 +22,21 @@ - + + + + + + + + + + + - + diff --git a/src/package/Microsoft.TestPlatform.CLI/Microsoft.TestPlatform.CLI.csproj b/src/package/Microsoft.TestPlatform.CLI/Microsoft.TestPlatform.CLI.csproj index 696cb68cbf..f3ad7825d0 100644 --- a/src/package/Microsoft.TestPlatform.CLI/Microsoft.TestPlatform.CLI.csproj +++ b/src/package/Microsoft.TestPlatform.CLI/Microsoft.TestPlatform.CLI.csproj @@ -37,7 +37,7 @@ Sometimes NU1702 is not suppressed correctly, so force reducing severity of the warning. See https://github.com/NuGet/Home/issues/9147 --> - NU1702 + $(MSBuildWarningsAsMessages);NU1702 diff --git a/src/package/Microsoft.TestPlatform.Portable/Microsoft.TestPlatform.Portable.csproj b/src/package/Microsoft.TestPlatform.Portable/Microsoft.TestPlatform.Portable.csproj index 33fde7df1b..f17f680575 100644 --- a/src/package/Microsoft.TestPlatform.Portable/Microsoft.TestPlatform.Portable.csproj +++ b/src/package/Microsoft.TestPlatform.Portable/Microsoft.TestPlatform.Portable.csproj @@ -12,7 +12,7 @@ Sometimes NU1702 is not suppressed correctly, so force reducing severity of the warning. See https://github.com/NuGet/Home/issues/9147 --> - NU1702 + $(MSBuildWarningsAsMessages);NU1702 diff --git a/src/package/Microsoft.TestPlatform/Microsoft.TestPlatform.csproj b/src/package/Microsoft.TestPlatform/Microsoft.TestPlatform.csproj index 540e0910ea..6739984bbd 100644 --- a/src/package/Microsoft.TestPlatform/Microsoft.TestPlatform.csproj +++ b/src/package/Microsoft.TestPlatform/Microsoft.TestPlatform.csproj @@ -11,7 +11,7 @@ Sometimes NU1702 is not suppressed correctly, so force reducing severity of the warning. See https://github.com/NuGet/Home/issues/9147 --> - NU1702;NETSDK1023 + $(MSBuildWarningsAsMessages);NU1702;NETSDK1023 diff --git a/src/testhost.x86/app.config b/src/testhost.x86/app.config index ff5d13c675..84cb676f80 100644 --- a/src/testhost.x86/app.config +++ b/src/testhost.x86/app.config @@ -35,11 +35,21 @@ - + + + + + + + + + + + - + diff --git a/src/vstest.console/app.config b/src/vstest.console/app.config index 115518cc51..de2fe51c34 100644 --- a/src/vstest.console/app.config +++ b/src/vstest.console/app.config @@ -27,11 +27,11 @@ - + - + @@ -40,7 +40,12 @@ - + + + + + + @@ -55,7 +60,7 @@ - + diff --git a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DiscoveryTests.cs b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DiscoveryTests.cs index 3680b3c9bc..05e4040b95 100644 --- a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DiscoveryTests.cs +++ b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DiscoveryTests.cs @@ -93,6 +93,7 @@ public void DiscoverTestsShouldShowProperWarningIfNoTestsOnTestCaseFilter(Runner } [TestMethod] + [Ignore("SCI 10.0.0.0 cannot be loaded in .NET 9 test host — covered by DtaLikeHost acceptance test instead")] public void TypesToLoadAttributeTests() { var extensionsDirectory = IntegrationTestEnvironment.ExtensionsDirectory; diff --git a/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DistributedTestAgentScenarioTests.cs b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DistributedTestAgentScenarioTests.cs new file mode 100644 index 0000000000..610867c3bb --- /dev/null +++ b/test/Microsoft.TestPlatform.Acceptance.IntegrationTests/DistributedTestAgentScenarioTests.cs @@ -0,0 +1,124 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System.IO; + +using Microsoft.TestPlatform.TestUtilities; +using Microsoft.VisualStudio.TestTools.UnitTesting; + +namespace Microsoft.TestPlatform.AcceptanceTests; + +/// +/// Reproduces the binding-redirect scenario experienced by Azure DevOps' Distributed +/// Test Agent (DTAExecutionHost) and any Visual Studio host that picks up +/// Microsoft.VisualStudio.TestPlatform.Common.dll without the in-box +/// vstest.console.exe.config binding redirects. +/// +/// The test loads Common.dll inside a net472 host that has no binding +/// redirects in its app.config and calls +/// , +/// which triggers FastFilter.Builder and forces +/// System.Collections.Immutable / System.Reflection.Metadata to load. +/// +/// It runs the scenario twice: +/// 1. Against the Microsoft.TestPlatform nupkg's +/// tools/net462/Common7/IDE/Extensions/TestPlatform/ layout (as DTA consumes it). +/// 2. Against the flat layout of the Microsoft.VisualStudio.TestTools.TestPlatform.V2.CLI +/// VSIX (as Visual Studio consumes it). +/// +/// Regression guard: if Common.dll's compiled metadata references for SCI/SRM drift +/// away from the versions we ship next to it, the test fails with the same +/// FileLoadException customers see. Both layouts must stay self-consistent. +/// +[TestClass] +public class DistributedTestAgentScenarioTests : AcceptanceTestBase +{ + [TestMethod] + [TestCategory("Windows-Review")] + public void LoadingCommonDllFromMicrosoftTestPlatformPackageWithoutBindingRedirectsDoesNotThrow() + { + // Nupkg layout: DTA-style consumption of the Microsoft.TestPlatform nupkg. + RunDtaLikeHost(toolsDirOverride: null); + } + + [TestMethod] + [TestCategory("Windows-Review")] + public void LoadingCommonDllFromCliV2VsixLayoutWithoutBindingRedirectsDoesNotThrow() + { + // VSIX layout: flat folder with Common.dll + SCI + SRM at the root, as shipped + // in Microsoft.VisualStudio.TestTools.TestPlatform.V2.CLI.vsix and consumed by + // Visual Studio. The VSIX is unzipped into PublishDirectory by Build.cs. + var extractedVsixDir = Path.Combine( + IntegrationTestEnvironment.PublishDirectory, + Path.GetFileName(IntegrationTestEnvironment.LocalVsixInsertion)); + + Assert.IsTrue( + Directory.Exists(extractedVsixDir), + $"Extracted VSIX directory not found at '{extractedVsixDir}'. " + + "Build.cs is expected to unzip the V2.CLI VSIX before acceptance tests run."); + + Assert.IsTrue( + File.Exists(Path.Combine(extractedVsixDir, "Microsoft.VisualStudio.TestPlatform.Common.dll")), + $"Expected Common.dll at the root of the extracted VSIX ('{extractedVsixDir}')."); + + RunDtaLikeHost(toolsDirOverride: extractedVsixDir); + } + + private void RunDtaLikeHost(string? toolsDirOverride) + { + var projectPath = GetIsolatedTestAsset("DtaLikeHost.csproj", Net472TargetFramework); + var workingDir = Path.GetDirectoryName(projectPath)!; + + var dotnetPath = GetPatchedDotnetPath(); + + var buildArgs = + $@"build ""{projectPath}"" -c {IntegrationTestEnvironment.BuildConfiguration} " + + $@"/p:PackageVersion={IntegrationTestEnvironment.LatestLocallyBuiltNugetVersion} " + + @"/nodeReuse:false"; + + if (toolsDirOverride is not null) + { + buildArgs += $@" /p:TestPlatformToolsDirOverride=""{toolsDirOverride}"""; + } + + ExecuteApplication(dotnetPath, buildArgs, out var buildOut, out var buildErr, out var buildExit, workingDirectory: workingDir); + + Assert.AreEqual( + 0, + buildExit, + $"dotnet build of DtaLikeHost failed (exit {buildExit}).\nSTDOUT:\n{buildOut}\nSTDERR:\n{buildErr}"); + + var exePath = Path.Combine( + workingDir, + "artifacts", "bin", "TestAssets", "DtaLikeHost", + IntegrationTestEnvironment.BuildConfiguration, + Net472TargetFramework, + "DtaLikeHost.exe"); + + Assert.IsTrue(File.Exists(exePath), $"Expected DtaLikeHost.exe at '{exePath}'."); + + // With the fix in place, Common.dll's compiled metadata references for + // System.Collections.Immutable and System.Reflection.Metadata match the DLLs + // shipped next to it, so the host exe completes normally even without any + // binding redirects in its app.config. + ExecuteApplication(exePath, args: null, out var runOut, out var runErr, out var runExit); + + Assert.AreEqual( + 0, + runExit, + "DtaLikeHost.exe exited non-zero, which means Common.dll's compiled metadata " + + "references for System.Collections.Immutable / System.Reflection.Metadata do " + + "not match the versions shipped next to it. DTA-style hosts (no binding " + + "redirects) will FileLoadException on FastFilter.Builder.\n" + + $"Tools dir: {toolsDirOverride ?? ""}\n" + + $"STDOUT:\n{runOut}\nSTDERR:\n{runErr}"); + + Assert.Contains("OK - no binding exception.", runOut); + } + + private static string GetPatchedDotnetPath() + { + var executable = OSUtils.IsWindows ? "dotnet.exe" : "dotnet"; + return Path.GetFullPath(Path.Combine(IntegrationTestEnvironment.RepoRootDirectory, "artifacts", "tmp", ".dotnet", executable)); + } +} \ No newline at end of file diff --git a/test/TestAssets/DtaLikeHost/DtaLikeHost.csproj b/test/TestAssets/DtaLikeHost/DtaLikeHost.csproj new file mode 100644 index 0000000000..e05f807a2d --- /dev/null +++ b/test/TestAssets/DtaLikeHost/DtaLikeHost.csproj @@ -0,0 +1,74 @@ + + + + + + DtaLikeHost + net472 + Exe + + false + false + true + + false + false + + + + + + + + + <_TestPlatformToolsDir>$(PkgMicrosoft_TestPlatform)\tools\net462\Common7\IDE\Extensions\TestPlatform + + + + + <_TestPlatformToolsDir>$(TestPlatformToolsDirOverride) + + + + + + $(_TestPlatformToolsDir)\Microsoft.VisualStudio.TestPlatform.Common.dll + true + + + $(_TestPlatformToolsDir)\Microsoft.VisualStudio.TestPlatform.ObjectModel.dll + true + + + + + + + + + + + + \ No newline at end of file diff --git a/test/TestAssets/DtaLikeHost/Program.cs b/test/TestAssets/DtaLikeHost/Program.cs new file mode 100644 index 0000000000..7999bed8a5 --- /dev/null +++ b/test/TestAssets/DtaLikeHost/Program.cs @@ -0,0 +1,53 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +using System; +using System.Reflection; + +using Microsoft.VisualStudio.TestPlatform.Common.Filtering; + +namespace DtaLikeHost; + +internal static class Program +{ + private static int Main() + { + // Report what Common.dll expects and what we ship next to it, so the mismatch + // (or agreement) is visible in the console output regardless of whether the + // CLR actually fails to bind. + var commonAsm = typeof(FilterExpressionWrapper).Assembly; + Console.WriteLine($"Common.dll path: {commonAsm.Location}"); + Console.WriteLine($"Common.dll version: {commonAsm.GetName().Version}"); + foreach (var r in commonAsm.GetReferencedAssemblies()) + { + if (r.Name == "System.Collections.Immutable" || r.Name == "System.Reflection.Metadata") + { + Console.WriteLine($" Common.dll references {r.Name}, Version={r.Version}"); + } + } + + try + { + // A simple equality filter produces a FastFilter, which triggers + // FastFilter.Builder.ctor -> ImmutableDictionary.CreateBuilder(...) + // -> forces the CLR to resolve System.Collections.Immutable at the version + // baked into Common.dll's metadata. + var wrapper = new FilterExpressionWrapper("TestCategory=Foo"); + Console.WriteLine($"FilterExpressionWrapper constructed: FilterString='{wrapper.FilterString}', ParseError='{wrapper.ParseError}'"); + + // Reflect on the private FastFilter field to prove it was actually built. + var fastFilterField = typeof(FilterExpressionWrapper).GetField("FastFilter", BindingFlags.Instance | BindingFlags.NonPublic); + var fastFilter = fastFilterField?.GetValue(wrapper); + Console.WriteLine($"FastFilter built: {fastFilter is not null}"); + } + catch (Exception ex) + { + Console.Error.WriteLine("REPRO HIT: exception constructing FilterExpressionWrapper:"); + Console.Error.WriteLine(ex); + return 1; + } + + Console.WriteLine("OK - no binding exception."); + return 0; + } +}