From 51457e73fbb982343390f33e5bb5c884361625ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 12 Nov 2026 16:43:42 +0100 Subject: [PATCH 1/3] Replace Extensions with explicit MSTest.Uwp and MSTest.WinUI packages Make TestFramework the shared core package owner and isolate each Windows application model's UI attributes, adapters, build assets and satellites. Update SDK/helper, metapackage, sample and native-build consumers while preserving historical API snapshots and existing app activation ownership. Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .github/copilot-instructions.md | 2 +- BUILD.bazel | 3 - MSTest.slnf | 3 +- NonWindowsTests.slnf | 1 - TestFx.slnx | 3 +- docs/decisions/bazel-build.md | 152 +++++ docs/decisions/mstest-platform-packages.md | 279 ++++++++++ eng/bazel/SdkPackageTool.cs | 12 +- eng/bazel/compatibility.bzl | 2 - eng/bazel/defs.bzl | 2 +- eng/bazel/extensions.bzl | 2 +- .../mstest-consumer/NativePackageTests.cs | 38 +- eng/bazel/mstest-packages.bzl | 112 +++- eng/bazel/mstest.bzl | 23 +- eng/bazel/reference-alias-tests.bzl | 3 +- eng/bazel/samples.bzl | 14 +- eng/bazel/sdk-packages.bzl | 4 +- eng/bazel/tests.bzl | 6 +- eng/bazel/validate-mstest-packages.ps1 | 132 +++-- eng/bazel/validate-packages.ps1 | 2 +- eng/bazel/validate-sdk-packages.ps1 | 19 +- eng/bazel/validate.ps1 | 2 +- eng/bazel/windows.bzl | 70 +-- eng/bazel/windows/AppModelHost.cs | 9 +- eng/bazel/windows/LibraryProbe.cs | 58 +- eng/bazel/windows/targeting_tests.bzl | 45 +- eng/bazel/windows/validate-app-model.ps1 | 25 +- eng/bazel/windows/validate.ps1 | 37 +- eng/mutation-testing/modules.json | 21 +- eng/verify-nupkgs.ps1 | 6 +- .../ClassicUwpMtpApp/ClassicUwpMtpApp.csproj | 6 +- .../public/UwpVSTestApp/UwpVSTestApp.csproj | 3 +- .../WinUIVSTestApp/WinUIVSTestApp.csproj | 3 +- .../MSTest.Extensions.Hosting.csproj | 4 +- .../MSTest.TestAdapter.csproj | 86 +-- src/Adapter/MSTest.TestAdapter/PACKAGE.md | 15 +- .../PackageDependencies.props | 18 + .../build/uap10.0/MSTest.TestAdapter.props | 3 - .../build/uap10.0/MSTest.TestAdapter.targets | 3 - .../common/MSTest.TestAdapter.props | 13 +- .../common/MSTest.TestAdapter.targets | 45 +- .../uwp/MSTest.TestAdapter.props | 20 - .../uwp/MSTest.TestAdapter.targets | 23 +- .../Execution/TestMethodRunner.cs | 18 + .../InternalAPI/InternalAPI.Unshipped.txt | 8 + .../MSTestAdapter.PlatformServices.csproj | 2 +- .../Resources/Resource.resx | 4 + .../Resources/xlf/Resource.cs.xlf | 5 + .../Resources/xlf/Resource.de.xlf | 5 + .../Resources/xlf/Resource.es.xlf | 5 + .../Resources/xlf/Resource.fr.xlf | 5 + .../Resources/xlf/Resource.it.xlf | 5 + .../Resources/xlf/Resource.ja.xlf | 5 + .../Resources/xlf/Resource.ko.xlf | 5 + .../Resources/xlf/Resource.pl.xlf | 5 + .../Resources/xlf/Resource.pt-BR.xlf | 5 + .../Resources/xlf/Resource.ru.xlf | 5 + .../Resources/xlf/Resource.tr.xlf | 5 + .../Resources/xlf/Resource.zh-Hans.xlf | 5 + .../Resources/xlf/Resource.zh-Hant.xlf | 5 + .../Services}/AppModel.cs | 0 .../TestContextImplementation.Properties.cs | 20 + src/Package/MSTest.Sdk/PACKAGE.md | 19 +- src/Package/MSTest.Sdk/README.md | 27 +- .../Sdk/Runner/ClassicEngine.targets | 4 +- .../MSTest.Sdk/Sdk/Runner/Common.targets | 10 +- .../MSTest.Sdk/Sdk/Runner/NativeAOT.targets | 6 +- src/Package/MSTest.Sdk/Sdk/Sdk.targets | 57 +- .../MSTest.Sdk/Sdk/VSTest/VSTest.targets | 4 +- src/Package/MSTest/MSTest.csproj | 7 +- src/Package/MSTest/PACKAGE.md | 8 +- .../InternalAPI.Shipped.txt.history} | 0 .../InternalAPI.Unshipped.txt.history} | 0 .../InternalAPI.Shipped.txt.history} | 0 .../InternalAPI.Unshipped.txt.history} | 0 .../InternalAPI.Shipped.txt.history} | 0 .../InternalAPI.Unshipped.txt.history} | 0 .../net10.0/InternalAPI.Shipped.txt.history} | 0 .../InternalAPI.Unshipped.txt.history} | 0 .../net462/InternalAPI.Shipped.txt.history} | 0 .../net462/InternalAPI.Unshipped.txt.history} | 0 .../InternalAPI.Shipped.txt.history} | 0 .../InternalAPI.Unshipped.txt.history} | 0 .../InternalAPI.Shipped.txt.history} | 0 .../InternalAPI.Unshipped.txt.history} | 0 .../PublicAPI/PublicAPI.Shipped.txt.history} | 0 .../PublicAPI.Unshipped.txt.history} | 0 .../PublicAPI.Shipped.txt.history} | 0 .../PublicAPI.Unshipped.txt.history} | 0 .../PublicAPI.Shipped.txt.history} | 0 .../PublicAPI.Unshipped.txt.history} | 0 .../net10.0/PublicAPI.Shipped.txt.history} | 0 .../net10.0/PublicAPI.Unshipped.txt.history} | 0 .../net462/PublicAPI.Shipped.txt.history} | 0 .../net462/PublicAPI.Unshipped.txt.history} | 0 .../PublicAPI.Shipped.txt.history} | 0 .../PublicAPI.Unshipped.txt.history} | 0 .../PublicAPI.Shipped.txt.history} | 0 .../PublicAPI.Unshipped.txt.history} | 0 .../TestFramework.Extensions/README.md | 13 + .../Attributes/UITestMethodAttribute.cs} | 0 .../InternalAPI/InternalAPI.Shipped.txt | 1 + .../InternalAPI/InternalAPI.Unshipped.txt | 3 + .../MSTest.Uwp/MSTest.Uwp.csproj | 30 + src/TestFramework/MSTest.Uwp/PACKAGE.md | 26 + .../Properties/AssemblyInfo.cs | 6 - .../Properties/MSTest.Uwp.rd.xml} | 2 +- .../PublicAPI/PublicAPI.Shipped.txt | 1 + .../PublicAPI/PublicAPI.Unshipped.txt | 4 + .../Attributes/UITestMethodAttribute.cs} | 0 .../Attributes/WinUITestTargetAttribute.cs | 0 .../InternalAPI/InternalAPI.Shipped.txt | 1 + .../InternalAPI/InternalAPI.Unshipped.txt | 4 + .../MSTest.WinUI/MSTest.WinUI.csproj | 25 + src/TestFramework/MSTest.WinUI/PACKAGE.md | 25 + .../MSTest.WinUI/Properties/AssemblyInfo.cs | 4 + .../PublicAPI/PublicAPI.Shipped.txt | 1 + .../PublicAPI/PublicAPI.Unshipped.txt | 9 + .../FrameworkExtensionsMessages.resx | 0 .../xlf/FrameworkExtensionsMessages.cs.xlf | 0 .../xlf/FrameworkExtensionsMessages.de.xlf | 0 .../xlf/FrameworkExtensionsMessages.es.xlf | 0 .../xlf/FrameworkExtensionsMessages.fr.xlf | 0 .../xlf/FrameworkExtensionsMessages.it.xlf | 0 .../xlf/FrameworkExtensionsMessages.ja.xlf | 0 .../xlf/FrameworkExtensionsMessages.ko.xlf | 0 .../xlf/FrameworkExtensionsMessages.pl.xlf | 0 .../xlf/FrameworkExtensionsMessages.pt-BR.xlf | 0 .../xlf/FrameworkExtensionsMessages.ru.xlf | 0 .../xlf/FrameworkExtensionsMessages.tr.xlf | 0 .../FrameworkExtensionsMessages.zh-Hans.xlf | 0 .../FrameworkExtensionsMessages.zh-Hant.xlf | 0 .../PlatformPackage/MSTest.Platform.props | 10 + .../PlatformPackage/PlatformPackage.props | 25 + .../PlatformPackage/PlatformPackage.targets | 28 + .../TestFramework.Extensions.csproj | 257 --------- .../net10.0/MSTest.TestFramework.targets | 3 - .../net11.0/MSTest.TestFramework.targets | 3 - .../build/net462/MSTest.TestFramework.targets | 3 - .../MSTest.TestFramework.targets | 3 - .../uap10.0/MSTest.TestFramework.targets | 3 - .../MSTest.TestFramework.targets | 54 -- .../TestFramework.Windows.UIAutomation.csproj | 2 +- .../Attributes/DeploymentItemAttribute.cs | 4 +- .../MSTest.TestFramework.targets | 0 .../PACKAGE.md | 22 +- .../TestFramework/TestContext.cs | 15 +- .../TestFramework/TestFramework.csproj | 49 +- test/Directory.Build.targets | 1 - .../ClassicUwpTests.cs | 27 +- .../CoreFrameworkAssemblyTests.cs | 103 ++-- .../CppCliMtpTests.cs | 3 - .../CppCliVSTestTests.cs | 3 - .../FrameworkTargetingTests.cs | 3 +- .../ModernUwpTests.cs | 106 +++- .../SdkTests.Composition.cs | 522 ++++++++++++++++++ .../SdkTests.cs | 137 +++-- .../SourceGenerationNonAotTests.cs | 2 +- .../UnpackagedWinUITests.cs | 28 +- .../WinUITests.cs | 129 ++++- .../WindowsApplicationModelPackageTests.cs | 162 +++--- .../WindowsApplicationModelTestTools.cs | 43 +- .../PackagedWinUITests.cs | 38 +- .../SdkPackageTests.cs | 27 +- .../MSTest.Analyzers.UnitTests.csproj | 2 +- .../MSTest.SourceGeneration.UnitTests.csproj | 2 +- ...tAdapter.PlatformServices.UnitTests.csproj | 3 +- .../MSTestAdapter.UnitTests.csproj | 1 - .../Extensions/TestContextTests.cs | 4 - .../Extensions/WinUIExtensionTests.cs | 2 +- .../TestFramework.UnitTests.csproj | 5 +- .../AcceptanceSourceGen.cs | 4 +- 172 files changed, 2565 insertions(+), 1016 deletions(-) create mode 100644 docs/decisions/mstest-platform-packages.md create mode 100644 src/Adapter/MSTest.TestAdapter/PackageDependencies.props delete mode 100644 src/Adapter/MSTest.TestAdapter/build/uap10.0/MSTest.TestAdapter.props delete mode 100644 src/Adapter/MSTest.TestAdapter/build/uap10.0/MSTest.TestAdapter.targets delete mode 100644 src/Adapter/MSTest.TestAdapter/buildTransitive/uwp/MSTest.TestAdapter.props rename src/{TestFramework/TestFramework.Extensions => Adapter/MSTestAdapter.PlatformServices/Services}/AppModel.cs (100%) rename src/TestFramework/{TestFramework.Extensions/InternalAPI/InternalAPI.Shipped.txt => APIHistory/TestFramework.Extensions/InternalAPI/InternalAPI.Shipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/InternalAPI/InternalAPI.Unshipped.txt => APIHistory/TestFramework.Extensions/InternalAPI/InternalAPI.Unshipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/InternalAPI/net10.0-windows10.0.17763.0/InternalAPI.Shipped.txt => APIHistory/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.17763.0/InternalAPI.Shipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/InternalAPI/net10.0-windows10.0.17763.0/InternalAPI.Unshipped.txt => APIHistory/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.17763.0/InternalAPI.Unshipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/InternalAPI/net10.0-windows10.0.18362.0/InternalAPI.Shipped.txt => APIHistory/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.18362.0/InternalAPI.Shipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/InternalAPI/net10.0-windows10.0.18362.0/InternalAPI.Unshipped.txt => APIHistory/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.18362.0/InternalAPI.Unshipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/InternalAPI/net10.0/InternalAPI.Shipped.txt => APIHistory/TestFramework.Extensions/InternalAPI/net10.0/InternalAPI.Shipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/InternalAPI/net10.0/InternalAPI.Unshipped.txt => APIHistory/TestFramework.Extensions/InternalAPI/net10.0/InternalAPI.Unshipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/InternalAPI/net462/InternalAPI.Shipped.txt => APIHistory/TestFramework.Extensions/InternalAPI/net462/InternalAPI.Shipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/InternalAPI/net462/InternalAPI.Unshipped.txt => APIHistory/TestFramework.Extensions/InternalAPI/net462/InternalAPI.Unshipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/InternalAPI/netstandard2.0/InternalAPI.Shipped.txt => APIHistory/TestFramework.Extensions/InternalAPI/netstandard2.0/InternalAPI.Shipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/InternalAPI/netstandard2.0/InternalAPI.Unshipped.txt => APIHistory/TestFramework.Extensions/InternalAPI/netstandard2.0/InternalAPI.Unshipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/InternalAPI/uap10.0.16299/InternalAPI.Shipped.txt => APIHistory/TestFramework.Extensions/InternalAPI/uap10.0.16299/InternalAPI.Shipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/InternalAPI/uap10.0.16299/InternalAPI.Unshipped.txt => APIHistory/TestFramework.Extensions/InternalAPI/uap10.0.16299/InternalAPI.Unshipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/PublicAPI/PublicAPI.Shipped.txt => APIHistory/TestFramework.Extensions/PublicAPI/PublicAPI.Shipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/PublicAPI/PublicAPI.Unshipped.txt => APIHistory/TestFramework.Extensions/PublicAPI/PublicAPI.Unshipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/PublicAPI/net10.0-windows10.0.17763.0/PublicAPI.Shipped.txt => APIHistory/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.17763.0/PublicAPI.Shipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/PublicAPI/net10.0-windows10.0.17763.0/PublicAPI.Unshipped.txt => APIHistory/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.17763.0/PublicAPI.Unshipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/PublicAPI/net10.0-windows10.0.18362.0/PublicAPI.Shipped.txt => APIHistory/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.18362.0/PublicAPI.Shipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/PublicAPI/net10.0-windows10.0.18362.0/PublicAPI.Unshipped.txt => APIHistory/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.18362.0/PublicAPI.Unshipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/PublicAPI/net10.0/PublicAPI.Shipped.txt => APIHistory/TestFramework.Extensions/PublicAPI/net10.0/PublicAPI.Shipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/PublicAPI/net10.0/PublicAPI.Unshipped.txt => APIHistory/TestFramework.Extensions/PublicAPI/net10.0/PublicAPI.Unshipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/PublicAPI/net462/PublicAPI.Shipped.txt => APIHistory/TestFramework.Extensions/PublicAPI/net462/PublicAPI.Shipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/PublicAPI/net462/PublicAPI.Unshipped.txt => APIHistory/TestFramework.Extensions/PublicAPI/net462/PublicAPI.Unshipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/PublicAPI/netstandard2.0/PublicAPI.Shipped.txt => APIHistory/TestFramework.Extensions/PublicAPI/netstandard2.0/PublicAPI.Shipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt => APIHistory/TestFramework.Extensions/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/PublicAPI/uap10.0.16299/PublicAPI.Shipped.txt => APIHistory/TestFramework.Extensions/PublicAPI/uap10.0.16299/PublicAPI.Shipped.txt.history} (100%) rename src/TestFramework/{TestFramework.Extensions/PublicAPI/uap10.0.16299/PublicAPI.Unshipped.txt => APIHistory/TestFramework.Extensions/PublicAPI/uap10.0.16299/PublicAPI.Unshipped.txt.history} (100%) create mode 100644 src/TestFramework/APIHistory/TestFramework.Extensions/README.md rename src/TestFramework/{TestFramework.Extensions/Attributes/UWP_UITestMethodAttribute.cs => MSTest.Uwp/Attributes/UITestMethodAttribute.cs} (100%) create mode 100644 src/TestFramework/MSTest.Uwp/InternalAPI/InternalAPI.Shipped.txt create mode 100644 src/TestFramework/MSTest.Uwp/InternalAPI/InternalAPI.Unshipped.txt create mode 100644 src/TestFramework/MSTest.Uwp/MSTest.Uwp.csproj create mode 100644 src/TestFramework/MSTest.Uwp/PACKAGE.md rename src/TestFramework/{TestFramework.Extensions => MSTest.Uwp}/Properties/AssemblyInfo.cs (50%) rename src/TestFramework/{TestFramework.Extensions/Properties/Extension.UWP.rd.xml => MSTest.Uwp/Properties/MSTest.Uwp.rd.xml} (97%) create mode 100644 src/TestFramework/MSTest.Uwp/PublicAPI/PublicAPI.Shipped.txt create mode 100644 src/TestFramework/MSTest.Uwp/PublicAPI/PublicAPI.Unshipped.txt rename src/TestFramework/{TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs => MSTest.WinUI/Attributes/UITestMethodAttribute.cs} (100%) rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Attributes/WinUITestTargetAttribute.cs (100%) create mode 100644 src/TestFramework/MSTest.WinUI/InternalAPI/InternalAPI.Shipped.txt create mode 100644 src/TestFramework/MSTest.WinUI/InternalAPI/InternalAPI.Unshipped.txt create mode 100644 src/TestFramework/MSTest.WinUI/MSTest.WinUI.csproj create mode 100644 src/TestFramework/MSTest.WinUI/PACKAGE.md create mode 100644 src/TestFramework/MSTest.WinUI/Properties/AssemblyInfo.cs create mode 100644 src/TestFramework/MSTest.WinUI/PublicAPI/PublicAPI.Shipped.txt create mode 100644 src/TestFramework/MSTest.WinUI/PublicAPI/PublicAPI.Unshipped.txt rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Resources/FrameworkExtensionsMessages.resx (100%) rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Resources/xlf/FrameworkExtensionsMessages.cs.xlf (100%) rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Resources/xlf/FrameworkExtensionsMessages.de.xlf (100%) rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Resources/xlf/FrameworkExtensionsMessages.es.xlf (100%) rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Resources/xlf/FrameworkExtensionsMessages.fr.xlf (100%) rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Resources/xlf/FrameworkExtensionsMessages.it.xlf (100%) rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Resources/xlf/FrameworkExtensionsMessages.ja.xlf (100%) rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Resources/xlf/FrameworkExtensionsMessages.ko.xlf (100%) rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Resources/xlf/FrameworkExtensionsMessages.pl.xlf (100%) rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Resources/xlf/FrameworkExtensionsMessages.pt-BR.xlf (100%) rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Resources/xlf/FrameworkExtensionsMessages.ru.xlf (100%) rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Resources/xlf/FrameworkExtensionsMessages.tr.xlf (100%) rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Resources/xlf/FrameworkExtensionsMessages.zh-Hans.xlf (100%) rename src/TestFramework/{TestFramework.Extensions => MSTest.WinUI}/Resources/xlf/FrameworkExtensionsMessages.zh-Hant.xlf (100%) create mode 100644 src/TestFramework/PlatformPackage/MSTest.Platform.props create mode 100644 src/TestFramework/PlatformPackage/PlatformPackage.props create mode 100644 src/TestFramework/PlatformPackage/PlatformPackage.targets delete mode 100644 src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj delete mode 100644 src/TestFramework/TestFramework.Extensions/build/net10.0/MSTest.TestFramework.targets delete mode 100644 src/TestFramework/TestFramework.Extensions/build/net11.0/MSTest.TestFramework.targets delete mode 100644 src/TestFramework/TestFramework.Extensions/build/net462/MSTest.TestFramework.targets delete mode 100644 src/TestFramework/TestFramework.Extensions/build/netstandard2.0/MSTest.TestFramework.targets delete mode 100644 src/TestFramework/TestFramework.Extensions/build/uap10.0/MSTest.TestFramework.targets delete mode 100644 src/TestFramework/TestFramework.Extensions/buildTransitive/net10.0AndLater/MSTest.TestFramework.targets rename src/TestFramework/{TestFramework.Extensions/buildTransitive/others => TestFramework}/MSTest.TestFramework.targets (100%) rename src/TestFramework/{TestFramework.Extensions => TestFramework}/PACKAGE.md (86%) create mode 100644 test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.Composition.cs diff --git a/.github/copilot-instructions.md b/.github/copilot-instructions.md index 8317b80038..305089dd6a 100644 --- a/.github/copilot-instructions.md +++ b/.github/copilot-instructions.md @@ -7,7 +7,7 @@ This is a .NET based repository that contains the MSTest testing framework and M The codebase ships several distinct (but related) products. Knowing which product a change belongs to is essential because they have different conventions, target frameworks, and public API surfaces: - `src/Platform/Microsoft.Testing.Platform` — Microsoft.Testing.Platform (MTP), a lightweight, in-process test host that replaces VSTest. Most other folders under `src/Platform/` are MTP extensions (`TrxReport`, `CrashDump`, `HangDump`, `HotReload`, `Retry`, `Telemetry`, `HtmlReport`, `AzureDevOpsReport`, `MSBuild`, `VSTestBridge`, …). -- `src/TestFramework` — MSTest itself: the public `Microsoft.VisualStudio.TestTools.UnitTesting` API (attributes, `Assert`, `TestContext`, …) plus `TestFramework.Extensions`. +- `src/TestFramework` — MSTest itself: the shared `Microsoft.VisualStudio.TestTools.UnitTesting` API (attributes, `Assert`, `TestContext`, …), plus the explicit `MSTest.Uwp` and `MSTest.WinUI` application-model packages. - `src/Adapter` — bridges MSTest to test hosts: `MSTest.TestAdapter` (VSTest adapter) and `MSTestAdapter.PlatformServices` (platform-services abstraction shared by both hosts). - `src/Analyzers` — Roslyn analyzers and code fixes shipped as `MSTest.Analyzers`. - `src/Package/MSTest.Sdk` — the MSBuild project SDK that wires the pieces together for consumers. diff --git a/BUILD.bazel b/BUILD.bazel index 4251bd8993..c89953e146 100644 --- a/BUILD.bazel +++ b/BUILD.bazel @@ -82,7 +82,6 @@ filegroup( ":crashdump", ":ctrf", ":framework", - ":framework_extensions", ":github_report", ":globalconfigs_generator", ":hangdump", @@ -179,7 +178,6 @@ testfx_binary( ":adapter", ":ctrf", ":framework", - ":framework_extensions", ":html", ":junit", ":trx", @@ -210,7 +208,6 @@ testfx_binary( deps = [ ":assert_generator", ":framework", - ":framework_extensions", ":internal_test_framework", ":trx", "@paket.source//awesomeassertions", diff --git a/MSTest.slnf b/MSTest.slnf index 382d2ad51a..e33d073ebc 100644 --- a/MSTest.slnf +++ b/MSTest.slnf @@ -18,7 +18,8 @@ "src\\Package\\MSTest\\MSTest.csproj", "src\\Platform\\Microsoft.Testing.Extensions.PackagedApp.Controller\\Microsoft.Testing.Extensions.PackagedApp.Controller.csproj", "src\\Platform\\Microsoft.Testing.Extensions.PackagedApp.MSBuild\\Microsoft.Testing.Extensions.PackagedApp.MSBuild.csproj", - "src\\TestFramework\\TestFramework.Extensions\\TestFramework.Extensions.csproj", + "src\\TestFramework\\MSTest.Uwp\\MSTest.Uwp.csproj", + "src\\TestFramework\\MSTest.WinUI\\MSTest.WinUI.csproj", "src\\TestFramework\\TestFramework.Windows.UIAutomation\\TestFramework.Windows.UIAutomation.csproj", "src\\TestFramework\\TestFramework.SourceGeneration\\TestFramework.SourceGeneration.csproj", "src\\TestFramework\\TestFramework\\TestFramework.csproj", diff --git a/NonWindowsTests.slnf b/NonWindowsTests.slnf index f500564cf9..3e8a30387d 100644 --- a/NonWindowsTests.slnf +++ b/NonWindowsTests.slnf @@ -39,7 +39,6 @@ "src\\Platform\\Microsoft.Testing.Platform.MSBuild\\Microsoft.Testing.Platform.MSBuild.csproj", "src\\Platform\\Microsoft.Testing.Platform.ServerMode.Client.Sources\\Microsoft.Testing.Platform.ServerMode.Client.Sources.csproj", "src\\Platform\\Microsoft.Testing.Platform\\Microsoft.Testing.Platform.csproj", - "src\\TestFramework\\TestFramework.Extensions\\TestFramework.Extensions.csproj", "src\\TestFramework\\TestFramework.Windows.UIAutomation\\TestFramework.Windows.UIAutomation.csproj", "src\\TestFramework\\TestFramework.SourceGeneration\\TestFramework.SourceGeneration.csproj", "src\\TestFramework\\TestFramework\\TestFramework.csproj", diff --git a/TestFx.slnx b/TestFx.slnx index 9611938f6c..44ed2b7253 100644 --- a/TestFx.slnx +++ b/TestFx.slnx @@ -72,7 +72,8 @@ - + + diff --git a/docs/decisions/bazel-build.md b/docs/decisions/bazel-build.md index 02f8e7f50d..501201b010 100644 --- a/docs/decisions/bazel-build.md +++ b/docs/decisions/bazel-build.md @@ -4073,3 +4073,155 @@ recorded source, not a new full-product rerun of this lifecycle correction. Hosted cache authorization, transfer costs and main-seed behavior still require CI. Local logs, BEP, policy/source hashes and counterfactual records are retained under the session's `bazel-review-d9e8c1dc` evidence. + +## 2026-11-12: explicit MSTest platform packages and shared core + +**Baseline and scope.** The authoritative prerequisite is merged #12428, +`e1c66e5cbfa844384a59343c3727821f97e2a09a` (final PR head +`ef322e36cc63e455e22552077a29916822b3204f`), not an earlier prototype. +This tooling-only follow-up retires its live Extensions project/assembly +references, without deleting the archived API provenance. Hosting must still +reference core directly, and repeated probe passes must retain separate, +append-only evidence. The primary implementation owns the production projects, +SDK selection, solutions, API history, and integrated verification. + +**Decision.** One ordinary `MSTest.TestFramework` owns context and activation +contracts and targets netstandard2.0, net462, net10.0, and net11.0. Modern Uwp +and WinUI source libraries reference that same core, not separately compiled +UI cores. Therefore the final prerequisite's UI-core **API exclusions** are +intentionally superseded: modern UI probes must find `DeploymentItemAttribute` +and all six directory getters in core. This does not enable deployment on UI: +the matching adapters still own the unsupported-operation result and null +directory behavior. Classic UWP consumes netstandard2.0 core, which has no +`DeploymentItemAttribute`. UI-specific attributes and adapters stay isolated +in `MSTest.Uwp` and `MSTest.WinUI`; ordinary/other-flavor adapter packages must +not enter those package closures. + +Keeping flavored cores would contradict the approved shared-core contract; +keeping an empty Extensions assembly would preserve obsolete package/build +references. Neither is chosen. Preserve native compiler scheduling, signing, +source generation, production flavor dispatch, and app-owned activation. Use +the actual project package assets/dependencies rather than historical prototype +file counts. NuGet Windows lib paths omit the final `.0` platform component; +the classic Uwp package path is `uap10.0.16299`. UI adapter satellites belong +under `buildTransitive//_localization//`, preventing +classic/modern Uwp collisions. Ordinary adapter satellites remain shared under +`buildTransitive/_localization`; WinUI attribute satellites remain under lib. +Each UI TFM packs the existing matching adapter target content directly as +`.targets`, with `Parallelize.targets` beside it. The shared +`MSTest.Platform.props` supplies package-local roots as `.props`; +there is no extra wrapper target or `buildTransitive/common` directory. +Historical Extensions API files retain their bytes under APIHistory with +`.txt.history` names, so normal shipped-API promotion cannot rewrite them. + +**Consumer evidence plan.** + +| Requirement / risk | Automated consumer contract | Evidence boundary | +| --- | --- | --- | +| Shared ordinary core and isolated UI attributes/adapters | `windows_targeting_test`, `LibraryProbe`, and `windows\validate.ps1` check compile/runtime owners, core APIs, signing, loaded hashes, and flavor closure. | Native library probes are not XAML/AppX activation tests. | +| Core package ownership and retired payloads | `validate-mstest-packages.ps1` inspects lib/build assets, dependencies, satellites, loaded native assemblies, and normal/failure/zero-result exits. | Repack and composed consumer execution belong to primary. | +| SDK/meta-package contract | `Generate_MetaPackagePreservesDependencyAndAssetFlow`, contract-drift cases, and `validate-sdk-packages.ps1` follow core project ownership and supported framework/package selection. | SDK evaluation alone is not execution or source-generation proof. | +| Evidence survives repeated passes | Preserve unique run paths and distinct consumer-pass provenance files. | Do not overwrite an earlier successful pass with a later MSBuild/probe pass. | + +This boundary is nonvisual. No new launcher, protocol, apartment/exception +behavior, or unrelated analyzer work is authorized. Builds, restores, tests, +and red/green comparisons are deliberately not run by this lane in the shared +worktree; primary owns serial integrated verification. Static checks and final +validation gaps are recorded below. + +**Native producer boundary.** The existing Bazel UI lane compiles modern +Windows libraries only. Its new opt-in `mstest_platform_package_closure` +therefore produces modern Uwp/WinUI development packages, not a fabricated +classic UAP implementation. `validate-mstest-packages.ps1 -IncludeWindowsPlatformPackages` +checks those modern layouts/dependencies in +addition to the ordinary package closure; its ordinary consumer must still +resolve no UI packages. Classic UAP production and real UI package-consuming +activation remain primary's shipping-layout validation responsibilities. +The portable native matrix now follows the current `SupportedNetFrameworks` +(`net10.0;net11.0`); deliberately older rule-compatibility fixtures and pinned +SDK pack inventories are not evidence of additional MSTest shipping targets. + +### Tooling file report + +Paths are under `eng\bazel` unless qualified otherwise. + +| File | Requirement delivered locally | +| --- | --- | +| Root `BUILD.bazel` | Retire Extensions from managed libraries, samples, and framework tests. | +| `defs.bzl` | Match the current net10/net11 portable source contract. | +| `mstest.bzl` | Remove the Extensions source library; retain ordinary core and Hosting's signed friend identity. The relocated AppModel follows the existing services source glob. | +| `extensions.bzl` | Keep Hosting's direct core dependency; remove only its retired dependency. | +| `compatibility.bzl` | Remove live Extensions compatibility variants, not API history. | +| `tests.bzl` | Remove retired dependencies from native test hosts. | +| `reference-alias-tests.bzl` | Use a net10 MSTest host; preserve older independent alias/error fixtures. | +| `samples.bzl` | Remove retired dependencies and use supported MSTest/AOT host TFMs. | +| `mstest-packages.bzl` | Package core from its real owner, retain net462 resolver core/dependencies, and expose isolated modern UI packages with canonical lib paths and per-TFM targets/localization. | +| `sdk-packages.bzl` | Remove the retired test-host dependency; select all 15 source-declared SDK cases. | +| `SdkPackageTool.cs` | Read the real core/meta references; validate the conditional classic Uwp branch without leaking it into portable dependency groups. | +| `test\UnitTests\Bazel.SdkPackages.UnitTests\SdkPackageTests.cs` | Update core ownership/framework fixtures and reject retired-framework, wrong-UI-reference, and wrong-UI-condition drift. | +| `mstest-consumer\NativePackageTests.cs` | Expect core without Extensions, assert shared APIs, and write unique provenance reports with an append-only path index. | +| `validate-mstest-packages.ps1` | Check current package entries/dependencies, per-TFM UI satellites, net462 resolver identity, and repeated-pass provenance; distinguish optional modern UI layout checks from activation. | +| `validate-sdk-packages.ps1` | Keep ordinary SDK profiles and add net10/net11 Uwp/WinUI reference-selection cases. | +| `validate-packages.ps1` | Match the portable native package matrix. | +| `validate.ps1` | Report the actual portable native matrix. | +| `windows.bzl` | Build the new attribute projects with one ordinary core and isolated matching adapters/services; retain production flavor symbols and activation code. | +| `windows\LibraryProbe.cs` | Require shared modern core APIs and separately owned UI attributes; reject retired/other-flavor payloads. | +| `windows\targeting_tests.bzl` | Check compile/runtime owners, flavor isolation, compatible net11 selection, and canonical Windows/classic-UAP paths. | +| `windows\validate.ps1` | Check named assembly sets and equal ordinary core hashes across desktop/Uwp/WinUI, not obsolete core API exclusions or prototype compiler counts. | +| `windows\AppModelHost.cs` | Preserve each activation report and append its path; retain the existing stdout payload and lifecycle. | +| `windows\validate-app-model.ps1` | Consume the path index, reject overwritten prefixes, and follow the current controller TFMs without changing activation/handshake checks. | +| `docs\decisions\bazel-build.md` | Append only this dated decision/evidence entry. | + +### Static validation and remaining integration evidence + +The local code patch is based on +`e1c66e5cbfa844384a59343c3727821f97e2a09a`. SHA-256 of raw +`git diff --binary HEAD -- BUILD.bazel eng\bazel test\UnitTests\Bazel.SdkPackages.UnitTests` stdout is +`267b0ef6aa9f6b2992edf0b224390be3ba58e5123ff65cd7e854bda0facb0f6d`. +This deliberately excludes this decision record and primary's other paths; +it is not a fingerprint of a tested integrated revision. + +Bounded read-only checks exited 0: + +- PowerShell `Parser.ParseFile` parsed all six changed scripts without executing + their bodies. +- Python `ast.parse` accepted the Python-compatible syntax of twelve changed + Starlark/BUILD files. This is **not** Bazel analysis or buildifier validation; + buildifier was not available. +- All five changed C# files retain UTF-8 BOMs and final newlines. +- Source discovery matched `PORTABLE_FRAMEWORKS` to `SupportedNetFrameworks`, + found the six current package asset/readme inputs, parsed their four MSBuild + XML inputs without evaluation, and matched the four meta-project + references/conditions. It counted thirteen data rows plus two non-data SDK + methods: fifteen source-declared cases, not discovered/executed tests. +- `git diff --check -- BUILD.bazel eng\bazel test\UnitTests\Bazel.SdkPackages.UnitTests docs\decisions\bazel-build.md` + exited 0. + +Parallel-safety preflight leaves scheduling unchanged: SDK cases use MSTest +method-level scheduling with CPU-count workers and per-test `TestTempDirectory` +inputs/outputs; the generated ordinary consumer retains two workers. Its +provenance test is the sole index writer, while the other passing methods read +stable package/configuration files. Driver invocations are serial. No new +process-global mutation, lock, background worker, or cleanup policy was added. + +**Test-value evidence:** all behavioral sensitivity below is a static +prediction; no product counts, red/green runs, archive production, or composed +consumer results were obtained by this lane. + +| Contract / test case | Buildable counterfactual | Correct implementation / evidence gap | +| --- | --- | --- | +| Shared core: `windows_targeting_test`, `LibraryProbe.VerifyFrameworkApi`, `PackagedTargetsProvideCoreAndParallelization` | Reintroduce a separately owned flavored core while retaining the same API shape. | Static: predicts owner/metadata/hash detection. Native analysis, compilation, and execution not run. | +| Layout: `UwpLibPathUsesNuGetCanonicalWindowsVersion`, `WinuiLibPathUsesNuGetCanonicalWindowsVersion`, `ClassicUwpLibPathPreservesMinimum`, `Assert-PackageLayout` | Retain trailing Windows `.0` folders or restore shared UI satellite placement. | Static: predicts path/layout detection. Native archive/consumer validation not run. | +| SDK/meta: `Generate_MetaPackagePreservesDependencyAndAssetFlow`; `Generate_RejectsContractDriftBeforeWritingOutputs` rows `meta-retired-framework`, `meta-ui-reference`, `meta-ui-condition` | Accept the retired project or wrong UI branch and emit an otherwise valid request. | Static: predicts dependency/rejection assertions fail. Fifteen source-declared SDK cases remain unexecuted. | +| Append-only provenance: `NativeAssembliesAreLoadedFromConsumer`, `Run-MSBuildConsumer`, `Read-AppModelProvenance` | Overwrite the path index on a later pass while keeping valid report JSON. | Static: predicts count/prefix detection. Repeated real probe/consumer passes not run. | + +The generated native versions remain source-derived: +MSTest `5.0.0-preview.bazel` and MTP `3.0.0-preview.bazel`; the pinned native +SDK remains `11.0.100-rc.3.26522.148`. Existing external dependency/toolchain +interop was not revalidated. Primary owns serial Bazel analysis/tests and +shipping-layout restore/build/run evidence, including net462 Configuration, +actual UI null directory getters and pre-body DeploymentItem rejection, +net11 package consumption, classic UAP, and real activation. No native classic +UAP producer was introduced. No commit, push, publication, or other-worktree +change was made by this lane. Archiving API provenance is not a compatibility +waiver or evidence that old binary consumers still work. diff --git a/docs/decisions/mstest-platform-packages.md b/docs/decisions/mstest-platform-packages.md new file mode 100644 index 0000000000..e06e543ade --- /dev/null +++ b/docs/decisions/mstest-platform-packages.md @@ -0,0 +1,279 @@ +# Explicit MSTest Windows application-model packages + +## Problem and contract + +This is the package stage of [#7225](https://github.com/microsoft/testfx/issues/7225), +after [#12412](https://github.com/microsoft/testfx/pull/12412) and +[#12428](https://github.com/microsoft/testfx/pull/12428). The starting point is +merged main `e1c66e5cbfa844384a59343c3727821f97e2a09a`, including #12428's final +head `ef322e36cc63e455e22552077a29916822b3204f`, not its earlier prototype. + +The package boundary is: + +- `TestFramework.csproj` owns `MSTest.TestFramework`. Its ordinary + `netstandard2.0`, `net462`, `net10.0`, and `net11.0` assemblies contain the + shared non-UI APIs. There are no application-model copies of core. +- `MSTest.Uwp` owns the existing AppContainer UI attribute and the matching + adapter/platform-services payloads for both classic `uap10.0.16299` and modern + UWP (`net10.0-windows10.0.17763.0`, also consumed by supported .NET 11 apps). + Modern UWP is not WinUI. +- `MSTest.WinUI` owns the existing WinUI attributes and matching + adapter/platform-services payloads for `net10.0-windows10.0.18362.0` and + compatible .NET 11 consumers. +- UI assemblies use conventional `lib/` assets. Each UI package owns its + build assets and depends on the matching core version, never on the ordinary + or other-flavor adapter package. `MSTest.TestAdapter` ships ordinary payloads + only. SDK, metapackage, direct-reference, and generated-helper consumers select + one composition; a non-UI helper library continues to reference core alone. + +The existing application owns its Windows App SDK/UWP runtime, application +entry point, dispatcher, package identity, activation, cancellation, and cleanup. +This change adds no launcher, handshake, protocol, runtime fallback, or process +exit convention. Existing packaged and unpackaged launchers remain responsible +for their current parent/child exit propagation and per-module results. +Classic UWP retains its distinct bootstrap dependencies. .NET Framework retains +its resolver copy of core and its configuration support. + +Removing the Extensions assembly/package layout is an intentional next-major +migration, not a binary-compatible type forwarding exercise. Existing shipped +API records remain historical evidence. The UI attribute names and behavior +remain unchanged; consumers must update package references and recompile. +Sharing the ordinary modern core also makes deployment/directory APIs visible +to modern UI consumers. UI runs must not invent deployment directories: +all six directory getters return null, even when the property bag contains +same-named entries. Unsupported `DeploymentItem` usage must fail before the test +body, including inherited attributes and reflection/source-generated execution, +rather than be ignored. Reuse the existing failed-test result path instead of +adding another exception or discovery framework. Classic UWP uses the netstandard +core, which does not expose `DeploymentItem`. + +## Research and experiments + +### 2026-11-12: merged-source inspection + +- Both prerequisite merge commits are ancestors of the clean starting HEAD; + origin/main equals the starting HEAD. #12428 is merged with the final head + above. +- Main still builds UI-specific core assemblies and packages core together with + Extensions. `_SelectMSTestUiCore` replaces compiler, runtime, and satellite + items, including an explicit replacement `HintPath` required by desktop + NuGet/MSBuild. Removing flavor selection entirely supersedes this mechanism; + merely changing item identities would reintroduce the fixed bug. +- Platform-services' WinUI `AppModel` helper currently lives in Extensions. + Moving that implementation to platform-services removes the only direct + internal dependency on the retiring assembly without creating a + core/UI/adapter project-reference cycle. +- The final prerequisite's Bazel Hosting-to-core correction and append-only + consumer report are retained. Native Bazel UI-core API-boundary assertions + must intentionally change to assert the shared-core contract, while keeping + UI attribute and adapter flavor checks. +- Read-only Windows application-model preflight passed with VS 2026 UWP + tooling, the classic 16299 SDK, modern Windows SDKs, an interactive desktop, + and AppX support. No registrations, system settings, or other worktrees were + changed. +- Initial baseline attempts could not locate unqualified `powershell` in native + child commands (wrapper exit 9009, then bootstrap exit 1). The inherited PATH + exceeds cmd.exe's supported length. A bounded command-local PATH containing + Windows PowerShell, System32, Windows, Git, and the required tools fixes lookup + without altering global settings. `build.cmd` then installs the pinned SDK, + workloads, and runtimes normally. These setup failures are not regression + evidence. +- The broad cold-cache attempts were stopped, but a child desktop MSBuild tree + escaped the shell's stop and continued writing old restore/build outputs. + The resulting adapter locking failures and first head package mismatch are + contaminated setup evidence, not pre-existing repository defects. Exact + process identities were captured, the owned PIDs were terminated, and a fresh + process inventory confirmed no remaining build in this workspace. No + process-name killing, other-worktree cleanup, or global cache eviction occurred. +- The focused framework-owner baseline passed with the repository desktop + helper (`/restore /t:Build,Pack /p:Configuration=Release /m:8`), building all + seven original TFMs with zero warnings/errors. The preserved baseline + `MSTest.TestFramework.5.0.0-dev.nupkg` has SHA-256 + `B5C3A79B141FAFF19EBE1080CB3FFB47865A411A69982CF9C49F28CD3FEAA78C`. + This is producer build/package evidence, not an executed behavioral baseline. +- Verified the configured effective producer dependency cache is + `Q:\.tools\.nuget\packages\`. It is reused for immutable external dependencies; + no cache is copied, cleared, or deleted. Same-version generated product + consumers retain separate fresh caches. +- After owned-process cleanup, the new core built and packed all four ordinary + TFMs successfully. New WinUI compilation exposed only missing declarations + for its existing embedded polyfill attribute; those were recorded in the + new assembly's unshipped API, not suppressed. +- NuGet rejected a shared `buildTransitive/common` directory with NU5129. + Instead of suppressing the warning or adding a root import that would apply + to unrelated TFMs, each supported TFM now owns its appropriately named + package-local props/targets and `Parallelize.targets`. Existing shared target + sources are mapped into those locations at pack time. UWP classic/modern + satellites are kept beside their own TFM payloads to avoid collisions. +- `eng/mark-shipped.ps1` recursively discovers live shipped API filenames. + Historical Extensions records therefore use `.txt.history` filenames; their + original bytes are preserved and the release glob has zero archive matches. +- Native Windows libraries and both targeting/asset-selection analysis tests + built/passed, but the new shared-core validation initially assumed a modern + portable `TargetFrameworkAttribute`. The prerequisite ordinary Bazel core + already omitted that attribute: only netstandard/net462 metadata was linked. + Correct the new oracle, not the native producer: absent metadata remains + supported, a declared wrong/Windows TFM is rejected, and desktop/UI core bytes + are compared under the independently planned framework major. No broad native + metadata, runtime, or source changes are introduced by this correction. + +## Alternatives and decision + +1. Keep Extensions and the current paired flavor selection. This preserves + today's hidden platform-specific core API shapes but does not retire the + project or give consumers explicit package ownership. +2. Rename the existing flavor bundles and continue shipping separate copies of + core. This is the smallest layout-only alternative, but keeps property-based + core replacement and lets a UI application disagree with an ordinary helper + library about the same core assembly's API and identity. +3. Use one non-UI core and explicit UI packages (chosen). Standard NuGet + selection replaces core swapping. The necessary contract effects are the + visible modern directory/deployment APIs and explicit rejection of + unsupported UI deployment. Existing UI behavior is moved, not redesigned. + +No migration analyzer, broad exception-handling redesign, new test framework, +or unrelated native/UI fixes are included. Reconsider the selected shape if +real packaged consumers demonstrate an unresolvable core/runtime dependency +or helper composition incompatibility. + +The adapter still builds the UI variants that the explicit packages bundle. +Its own pack operation narrows the public framework list only after Build, +before NuGet computes pack frameworks, and restores it afterwards. This also +covers older desktop pack walkers that use `TargetFrameworks` rather than only +NuGet's private item list. Sdk.Extras also caches its flavor matrix during +Build; pack filters that matrix and suppresses only the UI dependency groups +from the otherwise complete restore graph. The original matrix is restored +after pack. Source builds and restore retain the full graph. + +The SDK may infer a safe early application-model default and expose a bounded +explicit override where restore precedes desktop UWP tooling imports. Selection +must apply to every runner and source-generated helper injection path. Conflict +checks inspect the current inner TFM's resolved closure, never every target in a +multi-targeted assets file. Package builder hooks must honor +`IsTestApplication=false` without dropping source-generation compile hooks. + +## Validation and demonstration + +Use the repository-pinned SDK/build scripts, configuration-matched shipping +NuGets, isolated effective consumer caches, and physical/loaded assembly +provenance. Do not equate package inspection, compilation, discovery, skips, or +zero tests with application execution. + +| Requirement / risk | Existing or focused E2E evidence | Surface / gap | +| --- | --- | --- | +| Core ownership, API shape, matching outputs and satellites | `CoreFrameworkAssemblyTests`, `FrameworkTargetingTests`, `WindowsApplicationModelPackageTests` | Nonvisual package/API boundary; compare physical package, cache, compiler, runtime, and loaded bytes. | +| SDK defaults, explicit models, conflicts, CPM, multi-TFM and source-generated helper isolation | Relevant `SdkTests` cases plus focused missing composition cases | Generated consumer assets and executed host results; retain ordinary helper behavior. | +| Classic UWP | `ClassicUwpTests` with packed `MSTest.Uwp` | Real registration/activation, test identity/outcome/TRX, and exact owned cleanup. | +| Modern UWP on .NET 10/.NET 11 | `ModernUwpTests` and affected native SDK cases | Desktop UWP build, selected UWP payloads, real activated application and TRX. | +| Packaged/unpackaged WinUI | `PackagedWinUITests`, `WinUITests`, `UnpackagedWinUITests` | Real packaged/unpackaged UI dispatch and existing startup failure paths. | +| .NET Framework resolver/configuration and Hosting | Existing net462 compatibility and generated/ordinary Hosting cases | Real packed consumer, dependencies, selected test results, and core identity. | +| API histories and directly dependent tooling | API analyzer build and existing native Bazel package/library probes | No broad historical-baseline deletion; native tooling surfaces not executed remain explicit gaps. | +| Behavioral sensitivity | Same focused assertions on correct and isolated buildable counterfactual package behavior; preservation cases before/after | Record exact revisions/patches, commands, exits, executed identities/counts and assertion failures. | + +### Executed shipping-layout evidence + +All runs below use Release, repository SDK +`12.0.100-alpha.1.26556.115`, MSTest `5.0.0-dev`, and MTP `3.0.0-dev`. +The outer acceptance hosts target net12.0; generated consumers target the +frameworks named by their cases. Producer dependencies use the verified +immutable cache; generated consumers use fresh fixture/asset caches. + +The producer entry point is: + +```powershell +.\build.cmd -pack -c Release -projects $sourceFilter /m:8 /nr:false /bl:$packLog +``` + +`$sourceFilter` is a session-owned `.slnf` containing all **42 actual `src/` +project members** of `TestFx.slnx`, with an absolute solution path. It is not a +PowerShell/Arcade `src\**` glob. The final producer run exits 0 with zero +warnings/errors, and the unchanged root package verifier passes after updating +its expected physical payload counts: core 67, ordinary adapter 54, Uwp 73, +WinUI 53. Classic Uwp's PRI is retained. The ordinary adapter contains no UI +payload and has only net462/net10/net11 dependency groups. + +For acceptance selections, the common command is: + +```powershell +.\.dotnet\dotnet.exe test --project $project -c Release --no-build ` + --filter $filter -p:UsingDotNetTest=true "-p:ArtifactsTestResultsDir=$results" ` + "-bl:$binlog" --no-artifact-post-processing --show-test-results failed +``` + +Independent discovery uses the same project/filter with `--list-tests json`, +clearing `TestingPlatformCommandLineArguments` and +`TestRunnerAdditionalArguments`. Expected identities are reconciled with source +and verified against fresh TRX by the existing `verify_execution.py` gate. +Every passing row below has exit 0 and zero skips. + +| Requirement | Exact selection / executed cases | Result | +| --- | --- | --- | +| Core/UI ownership, matching compile/runtime/satellite bytes, package closure, and pre-body UI deployment failure | `CoreFrameworkAssemblyTests`, `WindowsApplicationModelPackageTests`, and `.WinUITests.` | 43/43 passed. `DeploymentItemsFailBeforeBodiesIncludingInheritedAttributes` executes reflection, Rooting, and ReflectionFree and checks exact failed identities/messages, not merely a failed child exit. | +| SDK defaults/explicit choices, CPM, ordinary/UI multi-TFM, helper/source-generation isolation, and net462 | `SdkTests.MSTestSdk_`, `SettingIsTestApplicationToFalseReducesAddedExtensionsAndMakesProjectNotExecutable`, `TestApplicationRunsTestsFromReferencedMSTestSdkTestLibrary`, `SourceGenerationNonAotTests.MSTestSdk_SourceGenerationOptIn_DoesNotFlowTransitively`, `FrameworkTargetingTests.PackedPackages_UseMatchingFrameworkAssetsAndRuntime`, `NetFrameworkRunnerCompatibilityTests` | 65/65 passed. Helper runtime payloads stay private; only the MSTest builder hook is excluded, without changing unrelated MTP dependency hooks. | +| Direct conflicting package pairs | `SdkTests.ExplicitPackages_RejectConflictingAdaptersBeforeCompilation` | 3/3 passed for ordinary+Uwp, ordinary+WinUI, and Uwp+WinUI. `PrepareForBuild` reports the composition diagnostic before compilation. | +| Actual classic/modern UWP and unpackaged WinUI | `ClassicUwpTests`, `ModernUwpTests`, `UnpackagedWinUITests` | 12/12 passed. Classic consumes SDK/metapackage/direct Uwp compositions; modern executes net10/net11 plus inherited unsupported deployment. x86/ARM64 layouts build; real execution is x64. Unpackaged dispatch, timeout cleanup, and constructor failure paths execute. | +| Actual packaged WinUI | `PackagedFullTrustWinUI_RegistersActivatesConnectsBackRunsUiTestsAndCleansUp`, `PackagedAppContainerWinUI_RunsThroughMtpControllerAndPublishesTrx`, `PackagedAppContainerWinUI_ExplicitIntegrationPublishesTrx` | 3/3 passed, including direct `MSTest.WinUI`. Names/outcomes and package identity are checked in the real activated host's TRX. | +| Hosting/core dependency and scope lifetime | `GeneratedMSTestHostingInjectionTests` | 8/8 passed across net462/net10/net11, including explicit unsupported AppDomain discovery/execution. | +| .NET Framework assembly-qualified configuration | `DataSourceTests.TestDataSourceFromAppConfig` | 1/1 passed: a net472 consumer selects the net462 package assets, loads `TestConfigurationSection, MSTest.TestFramework`, and produces the expected four passed/one intentionally failed child results. | +| Shipping native SDK routing | `PackagedAppNativeDotnetTestTests.NativeDotnetTest_` | 10/10 passed with isolated SDK 10.0.401 and verbose SDK diagnostics retained: activation, intentional nonzero child, retry, help/discovery, disabled launcher, AppContainer fallback rejection, and disabled routing. | +| Existing context/UI semantics | `TestContextTests` and `WinUIExtensionTests` | 20/20 context cases across net48/net10/net11/WinUI and 6/6 WinUI lifecycle cases passed. | +| Directly dependent native SDK tooling | `.\eng\bazel.ps1 test //:sdk_package_tests --jobs=2 --test_output=errors` | Bazel target passed. Native library/package follow-through is recorded in the maintained Bazel decision entry. | + +Real activation preflight passes without changing machine settings. Each real +application owns its unique registration and cleanup. Loaded core/UI/services +paths are recorded in the tests' context output; `CoreFrameworkAssemblyTests` +also compares current NuGet, effective cache, compiler, copied runtime, and +satellite SHA-256 values. + +The exact frozen shipping package hashes are: + +| Package (`5.0.0-dev`) | SHA-256 | +| --- | --- | +| MSTest.TestFramework | `910EE1E42522F58B709F246B3F485E9D651B4A43C5A7AC2D53DCE6266A844FA4` | +| MSTest.TestAdapter | `4919459CA1CE3F34DC9E6A81185C3FBD35BA81B29E8159C307D6E1C1AAB6F07D` | +| MSTest.Uwp | `9D758A77C1A34781F43208C7488D3BEC0302D80021DACF8A7B0CD54D2AE0AA67` | +| MSTest.WinUI | `C91FABBC15223E201E2AE4E6CD95E68FD6AA8767333575EAD37BFED939C3B77C` | + +### Test-value evidence + +The isolated comparison starts at the same prerequisite commit and retains the +implementation/test patch SHA-256 +`40A24B318FBC73958041B198553CFCA92956665BAF6EEFEC788E9A2E7092937D`. +The deliberate, buildable fault patch has SHA-256 +`314F18C1C3B184930923EC5949C7722FE84CAB039D635943980B7506CE81E9E9`: +the UI `TestRunDirectory` getter calls base, and the deployment guard's OR +becomes AND. No API, test, assertion, selector, or package identity is removed. +Both UI packages are rebuilt/repacked into separate outputs; retained consumers +restore those same-version packages through fresh comparison caches. + +| Contract / retained test | Wrong implementation | Correct implementation | +| --- | --- | --- | +| `PackedConsumersUseSharedCoreAndSelectedUiPackage` | Executed: four UI cases fail the intended null assertion with `TestRunDirectory = "must-not-be-a-directory"`; both ordinary cases pass. | Same six cases pass in the 43-case shipping selection. | +| `DeploymentItemsFailBeforeBodiesIncludingInheritedAttributes` | Executed: all three metadata modes fail the intended message/canary assertion because `DEPLOYMENT_BODY_EXECUTED` replaces the unsupported-operation result. | Same three cases pass in the shipping selection, including inherited method/class attributes. | + +The comparison executes all 9 planned cases: exit 2, 7 intended failures, +2 ordinary passes, zero skips. The first comparison attempt lacked the pinned +10/11 runtimes and is **setup failure, not sensitivity proof**; installing those +exact runtimes fixes that setup without changing product/test bits. Correct +behavior is then restored byte-for-byte, rebuilt/repacked, and rerun separately. +That restored run exits 0: the **same 9/9 cases pass**, zero skips, with fresh +consumer caches. The four contract source/test files match the primary +worktree's SHA-256 values. Red/green NuGets, TRX, build/execution binlogs, retained +test identities, and both patch hashes are preserved in the task's +`counterfactual` evidence directory. +Package/SDK selection groups have executed green coverage but no additional +fault campaign; they are not credited with the two behavioral faults above. + +Logs, binary logs, expected identities, and reports are task-owned evidence, +not source additions. This package boundary introduces no report/UI layout, +so a readable transcript and exact artifact/identity checks are more useful +than a staged screenshot. Actual UI activation/dispatch runs above are not +replaced by package manifests or source-only builds. + +## Open questions and rollout + +The delivery owner remains responsible through package flow and downstream +adoption. This targets main's next major MSTest release, not a servicing +backport that changes an existing released package boundary. Architecture and +release-branch surfaces not exercised locally must remain explicit validation +gaps. No merge or Agent merge is authorized by this package-stage delivery. diff --git a/eng/bazel/SdkPackageTool.cs b/eng/bazel/SdkPackageTool.cs index 6e1307abac..cf7cbc037d 100644 --- a/eng/bazel/SdkPackageTool.cs +++ b/eng/bazel/SdkPackageTool.cs @@ -135,7 +135,7 @@ string ExpandMetadata(string value) => Regex.Replace(value, @"\$\(([^()]+)\)", m ProjectUrl = "https://github.com/microsoft/testfx", Repository = new { Type = "git", Url = "https://github.com/microsoft/testfx" }, ReleaseNotes = ExpandMetadata(Property(sourceProperties, "PackageReleaseNotes")) - + "\nExperimental native Bazel build, not an official release. Portable .NET 8/9/10/11 package scope; Windows, .NET Framework, UWP and NativeAOT execution are not validated.", + + "\nExperimental native Bazel build, not an official release. Portable .NET 10/11 package scope; Windows, .NET Framework, UWP and NativeAOT execution are not validated.", }, PackageTypes = Array.Empty(), DependencyGroups = input.PackageId == "MSTest" @@ -193,8 +193,9 @@ static Dependency[] MetaPackageDependencies(XElement project, Dictionary(StringComparer.Ordinal) { - ["$(RepoRoot)src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj"] = ("MSTest.TestAdapter", versions["MSTestVersion"], ""), - ["$(RepoRoot)src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj"] = ("MSTest.TestFramework", versions["MSTestVersion"], ""), + ["$(RepoRoot)src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj"] = ("MSTest.TestAdapter", versions["MSTestVersion"], "'$(TargetFramework)'!='$(UwpMinimum)'"), + ["$(RepoRoot)src/TestFramework/MSTest.Uwp/MSTest.Uwp.csproj"] = ("MSTest.Uwp", versions["MSTestVersion"], "'$(TargetFramework)'=='$(UwpMinimum)'"), + ["$(RepoRoot)src/TestFramework/TestFramework/TestFramework.csproj"] = ("MSTest.TestFramework", versions["MSTestVersion"], ""), ["$(RepoRoot)src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csproj"] = ("Microsoft.Testing.Extensions.TrxReport", versions["MicrosoftTestingPlatformVersion"], "'$(TargetFramework)'!='$(UwpMinimum)'"), }; var dependencies = new List(); @@ -207,7 +208,10 @@ static Dependency[] MetaPackageDependencies(XElement project, Dictionary property.Name).ToArray(), SequenceOrder.InAnyOrder); + Assert.IsFalse(File.Exists(Path.Combine(AppContext.BaseDirectory, "MSTest.TestFramework.Extensions.dll"))); var loaded = new List(); foreach (string name in names) @@ -48,13 +48,19 @@ public void NativeAssembliesAreLoadedFromConsumer() string evidence = Environment.GetEnvironmentVariable("TESTFX_BAZEL_CONSUMER_EVIDENCE") ?? throw new InvalidOperationException("The consumer evidence path was not supplied."); - File.WriteAllText(evidence, JsonSerializer.Serialize(new + string reportPath = Path.Combine(Path.GetDirectoryName(Path.GetFullPath(evidence))!, "loaded-assemblies-" + Guid.NewGuid().ToString("N") + ".json"); + using (FileStream report = File.Open(reportPath, FileMode.CreateNew, FileAccess.Write, FileShare.Read)) { - Runtime = RuntimeInformation.FrameworkDescription, - CoreLib = typeof(object).Assembly.Location, - Framework = expectations.RootElement.GetProperty("Framework").GetString(), - Assemblies = loaded, - })); + JsonSerializer.Serialize(report, new + { + Runtime = RuntimeInformation.FrameworkDescription, + CoreLib = typeof(object).Assembly.Location, + Framework = expectations.RootElement.GetProperty("Framework").GetString(), + Assemblies = loaded, + }); + } + + File.AppendAllLines(evidence, [reportPath]); } [TestMethod] @@ -80,9 +86,25 @@ public void KoreanSatellitesAreCopiedAndLoadable() } [TestMethod] - public void PackagedTargetsProvideExtensionsAndParallelization() + public void PackagedTargetsProvideCoreAndParallelization() { Assert.AreEqual("MSTest.TestFramework", typeof(TestContext).Assembly.GetName().Name); + Assert.AreSame(typeof(Assert).Assembly, typeof(TestContext).Assembly); + Assert.AreSame(typeof(Assert).Assembly, typeof(DeploymentItemAttribute).Assembly); + string[] directories = + [ + nameof(TestContext.TestRunDirectory), + nameof(TestContext.DeploymentDirectory), + nameof(TestContext.ResultsDirectory), + nameof(TestContext.TestRunResultsDirectory), + nameof(TestContext.TestResultsDirectory), + nameof(TestContext.TestTempDirectory), + ]; + foreach (string directory in directories) + { + Assert.IsNotNull(typeof(TestContext).GetProperty(directory), directory); + } + ParallelizeAttribute? parallelize = typeof(NativePackageTests).Assembly.GetCustomAttribute(); Assert.IsNotNull(parallelize); Assert.AreEqual(ExecutionScope.MethodLevel, parallelize.Scope); diff --git a/eng/bazel/mstest-packages.bzl b/eng/bazel/mstest-packages.bzl index ed4b87aad9..885f554e3c 100644 --- a/eng/bazel/mstest-packages.bzl +++ b/eng/bazel/mstest-packages.bzl @@ -1,4 +1,4 @@ -"""The portable MSTest package layouts, with explicitly owned bundled payloads.""" +"""MSTest package layouts, with explicitly owned core and platform payloads.""" load( "@rules_dotnet//dotnet/private:providers.bzl", @@ -7,9 +7,15 @@ load( "NuGetPackInfo", ) load("@rules_dotnet//dotnet/private/rules/nuget_pack:layout.bzl", "extra_files_layout") -load(":defs.bzl", "PORTABLE_FRAMEWORKS") +load(":defs.bzl", "PORTABLE_FRAMEWORKS", "STANDARD_FRAMEWORKS") load(":packages.bzl", "package_build_assets", "package_version") +def mstest_package_tfm(framework): + """Match NuGet's Windows folder normalization without shortening classic UAP.""" + if "-windows" in framework and len(framework.split("-windows")[1].split(".")) == 4: + return framework.removesuffix(".0") + return framework + def _frameworks_impl(_settings, attr): return { framework: {"@rules_dotnet//dotnet:target_framework": framework} @@ -76,23 +82,35 @@ def _package_impl(ctx): if len(targets) != len(ctx.attr.directories): fail("{} is missing native assembly outputs for {}".format(ctx.label, framework)) for index, target in enumerate(targets): - directory = ctx.attr.directories[index].replace("{tfm}", framework) + package_tfm = mstest_package_tfm(framework) + directory = ctx.attr.directories[index].replace("{tfm}", package_tfm) resource_directory = ctx.attr.resource_directories[index] - # Adapter satellites are shared once, using the lowest portable TFM. + # Ordinary adapter satellites are shared once, from its first TFM. if "{tfm}" not in resource_directory and framework != ctx.attr.target_frameworks[0]: resource_directory = "" - name = _add_assembly(entries, target, framework, directory, resource_directory.replace("{tfm}", framework)) + name = _add_assembly(entries, target, framework, directory, resource_directory.replace("{tfm}", package_tfm)) names[name] = True external_dependencies = [] if ctx.attr.nuget_deps and framework not in ctx.split_attr.nuget_deps: fail("{} is missing external dependency metadata for {}".format(ctx.label, framework)) - for target in ctx.split_attr.nuget_deps.get(framework, []): + external_targets = ctx.split_attr.nuget_deps.get(framework, []) + if framework == "net462": + external_targets += ctx.split_attr.netframework_nuget_deps.get(framework, []) + for target in external_targets: info = target[DotnetAssemblyRuntimeInfo] if info.nuget_info == None: fail("{} is not an external NuGet dependency".format(target.label)) external_dependencies.append(struct(id = info.name, version = info.version, exclude = ["Build", "Analyzers"])) - groups.append(struct(targetFramework = framework, dependencies = dependencies + external_dependencies)) + groups.append(struct(targetFramework = mstest_package_tfm(framework), dependencies = dependencies + external_dependencies)) + + for target in ctx.attr.resolver_libraries: + info = target[DotnetAssemblyRuntimeInfo] + if target[DotnetAssemblyCompileInfo].target_framework != "net462" or len(info.libs) != 1: + fail("The VSTest resolver payload must be an exact net462 core implementation.") + for file in info.libs: + entries.append(("buildTransitive/net462/" + file.basename, file)) + names[info.name] = True for target in ctx.attr.task_libraries: _add_assembly(entries, target, "netstandard2.0", "_MSBuildTasks/netstandard2.0", "_MSBuildTasks/netstandard2.0") @@ -174,6 +192,8 @@ _package = rule( "deps": attr.label_list(providers = [NuGetPackInfo]), "dependency_excludes": attr.string_list_dict(), "nuget_deps": attr.label_list(providers = [DotnetAssemblyRuntimeInfo], cfg = _frameworks), + "netframework_nuget_deps": attr.label_list(providers = [DotnetAssemblyRuntimeInfo], cfg = _frameworks), + "resolver_libraries": attr.label_list(providers = [DotnetAssemblyCompileInfo, DotnetAssemblyRuntimeInfo]), "bound_platform": attr.bool(), "package_id": attr.string(mandatory = True), "description": attr.string(mandatory = True), @@ -191,21 +211,21 @@ def _asset(files, name, source, destination): files[":" + name] = destination def native_mstest_packages(): - """Declare portable packages using the explicit compatibility task wrappers.""" + """Declare ordinary packages and opt-in modern Windows platform packages.""" package_version(name = "mstest_package_version", property_name = "VersionPrefix") - framework_project = "src/TestFramework/TestFramework.Extensions" + framework_project = "src/TestFramework/TestFramework" adapter_project = "src/Adapter/MSTest.TestAdapter" - framework_files = {} + framework_files = {framework_project + "/MSTest.TestFramework.targets": "buildTransitive/MSTest.TestFramework.targets"} adapter_files = {} - for framework in PORTABLE_FRAMEWORKS: + windows_adapter_files = {} + for framework in PORTABLE_FRAMEWORKS + ["net462"]: suffix = framework.replace(".", "_") - _asset(framework_files, "framework_build_" + suffix, framework_project + "/build/" + framework + "/MSTest.TestFramework.targets", "build/" + framework + "/MSTest.TestFramework.targets") - _asset(framework_files, "framework_transitive_" + suffix, framework_project + "/buildTransitive/net8.0AndLater/MSTest.TestFramework.targets", "buildTransitive/" + framework + "/MSTest.TestFramework.targets") + files = windows_adapter_files if framework == "net462" else adapter_files for extension in ["props", "targets"]: filename = "MSTest.TestAdapter." + extension - _asset(adapter_files, "adapter_build_" + suffix + "_" + extension, adapter_project + "/build/" + framework + "/" + filename, "build/" + framework + "/" + filename) - _asset(adapter_files, "adapter_transitive_" + suffix + "_" + extension, adapter_project + "/buildTransitive/common/" + filename, "buildTransitive/" + framework + "/" + filename) - _asset(adapter_files, "adapter_parallelize_" + suffix, adapter_project + "/buildTransitive/Parallelize.targets", "buildTransitive/" + framework + "/Parallelize.targets") + _asset(files, "adapter_build_" + suffix + "_" + extension, adapter_project + "/build/" + framework + "/" + filename, "build/" + framework + "/" + filename) + _asset(files, "adapter_transitive_" + suffix + "_" + extension, adapter_project + "/buildTransitive/common/" + filename, "buildTransitive/" + framework + "/" + filename) + _asset(files, "adapter_parallelize_" + suffix, adapter_project + "/buildTransitive/Parallelize.targets", "buildTransitive/" + framework + "/Parallelize.targets") _package( name = "framework_package", @@ -213,9 +233,10 @@ def native_mstest_packages(): version_file = ":mstest_package_version", description = "Provides the libraries for writing tests with MSTest. MSTest is Microsoft supported Test Framework.", readme = framework_project + "/PACKAGE.md", - libraries = [":framework", ":framework_extensions"], - directories = ["lib/{tfm}", "buildTransitive/{tfm}"], - resource_directories = ["lib/{tfm}", ""], + libraries = [":framework"], + target_frameworks = STANDARD_FRAMEWORKS + ["net462"], + directories = ["lib/{tfm}"], + resource_directories = ["lib/{tfm}"], files = framework_files, deps = [":analyzers_package"], dependency_excludes = {"MSTest.Analyzers": ["Compile", "Runtime"]}, @@ -258,14 +279,30 @@ def native_mstest_packages(): description = "Discovers and runs MSTest tests using VSTest or Microsoft Testing Platform. MSTest is Microsoft supported Test Framework.", readme = adapter_project + "/PACKAGE.md", libraries = [":adapter", ":platform_services"], + target_frameworks = select({ + "@platforms//os:windows": ["net462"] + PORTABLE_FRAMEWORKS, + "//conditions:default": PORTABLE_FRAMEWORKS, + }), directories = ["buildTransitive/{tfm}", "buildTransitive/{tfm}"], resource_directories = ["buildTransitive/_localization", "buildTransitive/_localization"], - files = adapter_files, + files = select({ + "@platforms//os:windows": adapter_files | windows_adapter_files, + "//conditions:default": adapter_files, + }), + resolver_libraries = select({ + "@platforms//os:windows": [":framework_net462"], + "//conditions:default": [], + }), deps = [":trx_abstractions_package", ":telemetry_package", ":platform_msbuild_package"] + select({ "@platforms//os:windows": [":framework_package"], "//conditions:default": [], }), nuget_deps = ["@paket.source//microsoft.testplatform.objectmodel"], + netframework_nuget_deps = [ + "@paket.compatibility_mstest//system.memory", + "@paket.compatibility_mstest//system.threading.tasks.extensions", + "@paket.compatibility_mstest//system.reflection.metadata", + ], ) native.filegroup( name = "mstest_packages", @@ -275,3 +312,38 @@ def native_mstest_packages(): name = "mstest_package_closure", srcs = [":mstest_packages", ":packages", ":analyzers_package"], ) + + platform_packages = [] + for flavor, package_id, framework in [ + ("uwp", "MSTest.Uwp", "net10.0-windows10.0.17763.0"), + ("winui", "MSTest.WinUI", "net10.0-windows10.0.18362.0"), + ]: + name = "mstest_" + flavor + "_package" + project = "src/TestFramework/" + package_id + tfm = mstest_package_tfm(framework) + files = { + adapter_project + "/buildTransitive/common/MSTest.TestAdapter.targets": "buildTransitive/" + tfm + "/" + package_id + ".targets", + adapter_project + "/buildTransitive/Parallelize.targets": "buildTransitive/" + tfm + "/Parallelize.targets", + "src/TestFramework/PlatformPackage/MSTest.Platform.props": "buildTransitive/" + tfm + "/" + package_id + ".props", + } + _package( + name = name, + package_id = package_id, + version_file = ":mstest_package_version", + description = "Provides UI-thread test attributes and matching MSTest adapters for " + package_id + ".", + readme = project + "/PACKAGE.md", + libraries = [":mstest_" + flavor, ":adapter_" + flavor, ":platform_services_" + flavor], + target_frameworks = [framework], + directories = ["lib/{tfm}", "buildTransitive/{tfm}", "buildTransitive/{tfm}"], + resource_directories = ["lib/{tfm}", "buildTransitive/{tfm}/_localization", "buildTransitive/{tfm}/_localization"], + files = files, + deps = [":framework_package", ":trx_abstractions_package", ":telemetry_package", ":platform_msbuild_package"], + nuget_deps = ["@paket.source//microsoft.testplatform.objectmodel"], + target_compatible_with = ["@platforms//os:windows"], + ) + platform_packages.append(":" + name) + native.filegroup( + name = "mstest_platform_package_closure", + srcs = [":mstest_package_closure"] + platform_packages, + target_compatible_with = ["@platforms//os:windows"], + ) diff --git a/eng/bazel/mstest.bzl b/eng/bazel/mstest.bzl index 13d83bb194..a2abeb1dcc 100644 --- a/eng/bazel/mstest.bzl +++ b/eng/bazel/mstest.bzl @@ -38,7 +38,6 @@ def mstest_libraries(): "MSTestAdapter.PlatformServices", "MSTest.TestAdapter", "Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests", - "MSTest.TestFramework.Extensions", "MSTest.Extensions.Hosting", "Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests", "MSTestAdapter.PlatformServices.UnitTests", @@ -46,25 +45,6 @@ def mstest_libraries(): ], deps = [":assert_generator_plugin"], ) - testfx_library( - name = "framework_extensions", - project = "src/TestFramework/TestFramework.Extensions", - target_frameworks = STANDARD_FRAMEWORKS + ["net462"], - linked_srcs = testfx_compatibility_select(["//eng/bazel:CompatibilityFrameworkMetadata.cs"]), - assembly_name = "MSTest.TestFramework.Extensions", - defines = ["EXCLUDE_RANGE_INDEX_POLYFILL", "EXCLUDE_OS_POLYFILL"], - usings = ["Polyfills", "Microsoft.VisualStudio.TestTools.UnitTesting.Resources"], - resources = { - "src/TestFramework/TestFramework.Extensions/Resources/FrameworkExtensionsMessages.resx": "Microsoft.VisualStudio.TestTools.UnitTesting.Resources.FrameworkExtensionsMessages", - }, - internals_visible_to = [ - "MSTestAdapter.PlatformServices", - "MSTestAdapter.PlatformServices.UnitTests", - "MSTest.TestAdapter", - "Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests", - ], - deps = [":framework"], - ) testfx_library( name = "platform_services", project = "src/Adapter/MSTestAdapter.PlatformServices", @@ -84,7 +64,7 @@ def mstest_libraries(): "MSTest.Acceptance.IntegrationTests", "MSTest.Performance.Benchmarks", ], - deps = [":framework", ":framework_extensions"] + testfx_compatibility_select([ + deps = [":framework"] + testfx_compatibility_select([ "@paket.compatibility_mstest//system.memory", "@paket.compatibility_mstest//system.threading.tasks.extensions", ]), @@ -128,7 +108,6 @@ def mstest_libraries(): ":msbuild_extension", ":retry", ":platform_msbuild", - ":framework_extensions", ] + testfx_nuget(["microsoft.testplatform.objectmodel"], compatibility_group = "compatibility_mstest") + testfx_compatibility_select([ "@paket.compatibility_mstest//system.memory", "@paket.compatibility_mstest//system.threading.tasks.extensions", diff --git a/eng/bazel/reference-alias-tests.bzl b/eng/bazel/reference-alias-tests.bzl index d28b53c3b6..19aec04073 100644 --- a/eng/bazel/reference-alias-tests.bzl +++ b/eng/bazel/reference-alias-tests.bzl @@ -23,7 +23,7 @@ def reference_alias_tests(): exclude = [_PROJECT + "/" + name + ".cs" for name in ["First", "Second", "InvalidConfiguration"]], linked_srcs = ["//eng/bazel:TestMain.cs"], defines = ["TESTFX_METHOD_PARALLEL"], - target_frameworks = ["net8.0"], + target_frameworks = ["net10.0"], reference_aliases = { "Bazel.Aliases.First": ["global", "FirstAlias"], "Bazel.Aliases.Second": ["SecondAlias"], @@ -36,7 +36,6 @@ def reference_alias_tests(): ":alias_second", ":adapter", ":framework", - ":framework_extensions", ":trx", ], ) diff --git a/eng/bazel/samples.bzl b/eng/bazel/samples.bzl index b0399005f1..9d44130dc1 100644 --- a/eng/bazel/samples.bzl +++ b/eng/bazel/samples.bzl @@ -14,12 +14,12 @@ def portable_samples(): testfx_binary( name = name, project = project, - target_frameworks = ["net8.0"], + target_frameworks = ["net10.0"], polyfills = False, linked_srcs = ["//eng/bazel:TestMain.cs", "//eng/bazel:PortableTestFrameworkMetadata.cs"], defines = defines, generate_documentation_file = False, - deps = [":adapter", ":framework", ":framework_extensions", ":trx"], + deps = [":adapter", ":framework", ":trx"], ) testfx_test( name = name + "_test", @@ -32,11 +32,11 @@ def portable_samples(): name = "custom_report", project = "samples/public/mstest-runner/CustomReportExtension/CustomReportExtension", linked_srcs = ["//eng/bazel:PortableTestFrameworkMetadata.cs"], - target_frameworks = ["net8.0"], + target_frameworks = ["net10.0"], polyfills = False, usings = ["Microsoft.VisualStudio.TestTools.UnitTesting"], generate_documentation_file = False, - deps = [":adapter", ":framework", ":framework_extensions", ":platform"], + deps = [":adapter", ":framework", ":platform"], ) testfx_test( name = "custom_report_test", @@ -146,17 +146,17 @@ def portable_samples(): testfx_binary( name = "aot_sample", project = "samples/public/DemoMSTestSdk/ProjectWithNativeAOT", - target_frameworks = ["net8.0"], + target_frameworks = ["net10.0"], polyfills = False, linked_srcs = ["//eng/bazel:TestMain.cs", "//eng/bazel:PortableTestFrameworkMetadata.cs"], analyzer_configs = ["//eng/bazel:reflection-free.globalconfig"], generate_documentation_file = False, - deps = [":adapter", ":framework", ":framework_extensions", ":platform_services", ":trx", ":sample_source_generator"], + deps = [":adapter", ":framework", ":platform_services", ":trx", ":sample_source_generator"], ) publish_binary( name = "aot_publish", binary = ":aot_sample", - target_framework = "net8.0", + target_framework = "net10.0", native_aot = True, tags = ["manual"], ) diff --git a/eng/bazel/sdk-packages.bzl b/eng/bazel/sdk-packages.bzl index 9ef9a880ed..ebca496f80 100644 --- a/eng/bazel/sdk-packages.bzl +++ b/eng/bazel/sdk-packages.bzl @@ -138,11 +138,11 @@ def sdk_packages(): generate_documentation_file = False, data = ["//eng/bazel:sdk_package_tool"], envs = {"TESTFX_BAZEL_SDK_PACKAGE_TOOL": "$(rlocationpath //eng/bazel:sdk_package_tool)"}, - deps = [":adapter", ":framework", ":framework_extensions", ":trx", ":mstest_analyzer_plugin", "//eng/bazel:runfiles"], + deps = [":adapter", ":framework", ":trx", ":mstest_analyzer_plugin", "//eng/bazel:runfiles"], ) testfx_test( name = "sdk_package_tests", binary = ":sdk_package_tests_app", - args = ["--minimum-expected-tests", "12"], + args = ["--minimum-expected-tests", "15"], size = "medium", ) diff --git a/eng/bazel/tests.bzl b/eng/bazel/tests.bzl index 8fd6b1404f..cba76f9b45 100644 --- a/eng/bazel/tests.bzl +++ b/eng/bazel/tests.bzl @@ -12,7 +12,6 @@ def native_unit_test_deps(): ":platform", ":adapter", ":framework", - ":framework_extensions", ":trx", ":junit", ":ctrf", @@ -185,7 +184,7 @@ def unit_tests(): defines = ["TESTFX_FOUR_WORKERS" if four_workers else "TESTFX_METHOD_PARALLEL"], usings = ["Microsoft.Testing.Platform.Extensions"] if name == "vstest_bridge_tests" else [], generate_documentation_file = False, - deps = [":platform", ":adapter", ":framework", ":framework_extensions", ":trx", ":mstest_analyzer_plugin"] + dependencies, + deps = [":platform", ":adapter", ":framework", ":trx", ":mstest_analyzer_plugin"] + dependencies, ) testfx_test( name = name, @@ -203,7 +202,7 @@ def unit_tests(): generate_documentation_file = False, data = ["//eng/bazel:build_tools"], envs = {"TESTFX_BAZEL_BUILD_TOOLS": "$(rlocationpath //eng/bazel:build_tools)"}, - deps = [":adapter", ":framework", ":framework_extensions", ":trx", ":mstest_analyzer_plugin", "//eng/bazel:runfiles"], + deps = [":adapter", ":framework", ":trx", ":mstest_analyzer_plugin", "//eng/bazel:runfiles"], ) testfx_test( name = "build_tools_tests", @@ -231,7 +230,6 @@ def unit_tests(): generate_documentation_file = False, deps = [ ":framework", - ":framework_extensions", ":adapter", ":platform_services", ":platform", diff --git a/eng/bazel/validate-mstest-packages.ps1 b/eng/bazel/validate-mstest-packages.ps1 index a396896f07..66a650248e 100644 --- a/eng/bazel/validate-mstest-packages.ps1 +++ b/eng/bazel/validate-mstest-packages.ps1 @@ -6,25 +6,35 @@ [CmdletBinding()] param( [string] $OutputRoot, - [switch] $VerifySatelliteSensitivity + [switch] $VerifySatelliteSensitivity, + [switch] $IncludeWindowsPlatformPackages ) $ErrorActionPreference = 'Stop' $PSNativeCommandUseErrorActionPreference = $false +if ($IncludeWindowsPlatformPackages -and -not $IsWindows) { throw 'Native UI package validation requires Windows.' } $root = Split-Path (Split-Path $PSScriptRoot -Parent) -Parent $bazel = Join-Path $root 'eng\bazel.ps1' if (-not $OutputRoot) { $OutputRoot = Join-Path $root 'artifacts\bazel-mstest-validation' } $directory = Join-Path ([System.IO.Path]::GetFullPath($OutputRoot)) ([DateTime]::UtcNow.ToString('yyyyMMdd-HHmmss') + '-' + [Guid]::NewGuid().ToString('N').Substring(0, 8)) $feed = Join-Path $directory 'feed' New-Item -ItemType Directory -Path $feed -Force | Out-Null -$frameworks = @('net8.0', 'net9.0', 'net10.0', 'net11.0') -$expectedIds = @( +$frameworks = @('net10.0', 'net11.0') +$coreFrameworks = @('netstandard2.0', 'net462') + $frameworks +$adapterFrameworks = if ($IsWindows) { @('net462') + $frameworks } else { $frameworks } +$platformFrameworks = @{ + 'MSTest.Uwp' = 'net10.0-windows10.0.17763' + 'MSTest.WinUI' = 'net10.0-windows10.0.18362' +} +$portableIds = @( 'MSTest.TestFramework', 'MSTest.TestAdapter', 'MSTest.Analyzers', 'Microsoft.Testing.Platform', 'Microsoft.Testing.Platform.MSBuild', 'Microsoft.Testing.Extensions.Telemetry', 'Microsoft.Testing.Extensions.TrxReport', 'Microsoft.Testing.Extensions.TrxReport.Abstractions' ) -$passingTests = @('NativeAssembliesAreLoadedFromConsumer', 'KoreanSatellitesAreCopiedAndLoadable', 'PackagedTargetsProvideExtensionsAndParallelization') +$expectedIds = $portableIds +if ($IncludeWindowsPlatformPackages) { $expectedIds += @('MSTest.Uwp', 'MSTest.WinUI') } +$passingTests = @('NativeAssembliesAreLoadedFromConsumer', 'KoreanSatellitesAreCopiedAndLoadable', 'PackagedTargetsProvideCoreAndParallelization') $packages = @{} $steps = [System.Collections.Generic.List[object]]::new() $runs = [System.Collections.Generic.List[object]]::new() @@ -89,8 +99,14 @@ function Assert-Trx([string] $Path, [string[]] $Expected, [int] $Failed = 0, [st function Assert-PackageLayout($Archive, $Metadata, [string] $Id) { $groups = @($Metadata.SelectNodes('./*[local-name()="dependencies"]/*[local-name()="group"]')) - if ($Id -in @('MSTest.TestFramework', 'MSTest.TestAdapter', 'Microsoft.Testing.Platform.MSBuild', 'Microsoft.Testing.Extensions.Telemetry')) { - Assert-Names $frameworks @($groups | ForEach-Object targetFramework) "$Id framework groups" + $packageFrameworks = switch ($Id) { + 'MSTest.TestFramework' { $coreFrameworks } + 'MSTest.TestAdapter' { $adapterFrameworks } + { $platformFrameworks.ContainsKey($_) } { @($platformFrameworks[$Id]) } + default { $frameworks } + } + if ($Id -in @('MSTest.TestFramework', 'MSTest.TestAdapter', 'Microsoft.Testing.Platform.MSBuild', 'Microsoft.Testing.Extensions.Telemetry', 'MSTest.Uwp', 'MSTest.WinUI')) { + Assert-Names $packageFrameworks @($groups | ForEach-Object targetFramework) "$Id framework groups" } $allDependencies = @($Metadata.SelectNodes('.//*[local-name()="dependency"]')) foreach ($dependency in $allDependencies) { @@ -98,16 +114,16 @@ function Assert-PackageLayout($Archive, $Metadata, [string] $Id) { throw "$Id declares a private bundled assembly as package dependency: $($dependency.id)" } } - foreach ($framework in $frameworks) { + if (@($Archive.Entries | Where-Object Name -Like 'MSTest.TestFramework.Extensions.*').Count) { + throw "$Id contains a retired Extensions payload." + } + foreach ($framework in $packageFrameworks) { switch ($Id) { 'MSTest.TestFramework' { foreach ($extension in @('dll', 'xml', 'pdb')) { $null = Get-ZipHash $Archive "lib/$framework/MSTest.TestFramework.$extension" - $null = Get-ZipHash $Archive "buildTransitive/$framework/MSTest.TestFramework.Extensions.$extension" } - if ($Archive.GetEntry("lib/$framework/MSTest.TestFramework.Extensions.dll")) { throw 'Framework.Extensions must not be an implicit lib asset for modern .NET.' } - $null = Get-ZipHash $Archive "build/$framework/MSTest.TestFramework.targets" - $null = Get-ZipHash $Archive "buildTransitive/$framework/MSTest.TestFramework.targets" + $null = Get-ZipHash $Archive 'buildTransitive/MSTest.TestFramework.targets' } 'MSTest.TestAdapter' { foreach ($name in @('MSTest.TestAdapter', 'MSTestAdapter.PlatformServices')) { @@ -119,6 +135,27 @@ function Assert-PackageLayout($Archive, $Metadata, [string] $Id) { } $null = Get-ZipHash $Archive "buildTransitive/$framework/Parallelize.targets" if (@($Archive.Entries | Where-Object FullName -Like 'lib/*').Count) { throw 'The adapter must not expose a lib folder.' } + if ($framework -eq 'net462') { + $null = Get-ZipHash $Archive 'buildTransitive/net462/MSTest.TestFramework.dll' + } + } + { $platformFrameworks.ContainsKey($_) } { + foreach ($name in @('MSTest.TestAdapter', 'MSTestAdapter.PlatformServices')) { + $null = Get-ZipHash $Archive "buildTransitive/$framework/$name.dll" + } + $null = Get-ZipHash $Archive "lib/$framework/$Id.dll" + foreach ($extension in @('props', 'targets')) { + $null = Get-ZipHash $Archive "buildTransitive/$framework/$Id.$extension" + } + $null = Get-ZipHash $Archive "buildTransitive/$framework/Parallelize.targets" + if (@($Archive.Entries | Where-Object FullName -Like 'buildTransitive/common/*').Count) { + throw "$Id must use package-local targets, not a shared wrapper directory." + } + if (@($Archive.Entries | Where-Object { $_.FullName -like '*/MSTest.TestFramework.dll' -or + $_.FullName -like 'lib/*/MSTest.Uwp.dll' -and $Id -ne 'MSTest.Uwp' -or + $_.FullName -like 'lib/*/MSTest.WinUI.dll' -and $Id -ne 'MSTest.WinUI' }).Count) { + throw "$Id must depend on shared core and isolate its own UI assembly." + } } 'Microsoft.Testing.Platform.MSBuild' { $null = Get-ZipHash $Archive "lib/$framework/Microsoft.Testing.Extensions.MSBuild.dll" @@ -146,12 +183,20 @@ function Assert-PackageLayout($Archive, $Metadata, [string] $Id) { } $catalogs = switch ($Id) { 'MSTest.TestFramework' { - @{ Directory = 'src\TestFramework\TestFramework\Resources\xlf'; Stem = 'FrameworkMessages'; Assembly = 'MSTest.TestFramework'; Folders = @($frameworks | ForEach-Object { "lib/$_" }) } + @{ Directory = 'src\TestFramework\TestFramework\Resources\xlf'; Stem = 'FrameworkMessages'; Assembly = 'MSTest.TestFramework'; Folders = @($coreFrameworks | ForEach-Object { "lib/$_" }) } } 'MSTest.TestAdapter' { @{ Directory = 'src\Adapter\MSTest.TestAdapter\Resources\xlf'; Stem = 'PlatformAdapterResources'; Assembly = 'MSTest.TestAdapter'; Folders = @('buildTransitive/_localization') } @{ Directory = 'src\Adapter\MSTestAdapter.PlatformServices\Resources\xlf'; Stem = 'Resource'; Assembly = 'MSTestAdapter.PlatformServices'; Folders = @('buildTransitive/_localization') } } + { $platformFrameworks.ContainsKey($_) } { + $folder = "buildTransitive/$($platformFrameworks[$Id])/_localization" + @{ Directory = 'src\Adapter\MSTest.TestAdapter\Resources\xlf'; Stem = 'PlatformAdapterResources'; Assembly = 'MSTest.TestAdapter'; Folders = @($folder) } + @{ Directory = 'src\Adapter\MSTestAdapter.PlatformServices\Resources\xlf'; Stem = 'Resource'; Assembly = 'MSTestAdapter.PlatformServices'; Folders = @($folder) } + } + 'MSTest.WinUI' { + @{ Directory = 'src\TestFramework\MSTest.WinUI\Resources\xlf'; Stem = 'FrameworkExtensionsMessages'; Assembly = 'MSTest.WinUI'; Folders = @("lib/$($platformFrameworks[$Id])") } + } } foreach ($catalog in $catalogs) { foreach ($source in Get-ChildItem -LiteralPath (Join-Path $root $catalog.Directory) -Filter "$($catalog.Stem).*.xlf" -File) { @@ -159,8 +204,8 @@ function Assert-PackageLayout($Archive, $Metadata, [string] $Id) { foreach ($folder in $catalog.Folders) { $null = Get-ZipHash $Archive "$folder/$culture/$($catalog.Assembly).resources.dll" } } } - if ($Id -eq 'MSTest.TestFramework' -and @($Archive.Entries | Where-Object FullName -Like '*MSTest.TestFramework.Extensions.resources.dll').Count) { - throw 'The shipping framework layout bundles only the core satellite resources.' + if ($Id -eq 'MSTest.TestAdapter' -and @($Archive.Entries | Where-Object FullName -Match '(^|/)(winui|uwp|uap[^/]*|net\d+\.\d+-windows[^/]*)(/|$)').Count) { + throw 'The ordinary adapter must not ship UI flavor payloads or build assets.' } foreach ($group in $groups) { $dependencies = @($group.SelectNodes('./*[local-name()="dependency"]')) @@ -171,11 +216,12 @@ function Assert-PackageLayout($Archive, $Metadata, [string] $Id) { throw 'The framework must retain native analyzer/build assets and exclude only compile/runtime.' } } - 'MSTest.TestAdapter' { + { $_ -in @('MSTest.TestAdapter', 'MSTest.Uwp', 'MSTest.WinUI') } { $ids = @('Microsoft.Testing.Extensions.TrxReport.Abstractions', 'Microsoft.Testing.Extensions.Telemetry', 'Microsoft.Testing.Platform.MSBuild', 'Microsoft.TestPlatform.ObjectModel') - if ($IsWindows) { $ids += 'MSTest.TestFramework' } + if ($IsWindows -or $Id -ne 'MSTest.TestAdapter') { $ids += 'MSTest.TestFramework' } + if ($group.targetFramework -eq 'net462') { $ids += @('System.Memory', 'System.Threading.Tasks.Extensions', 'System.Reflection.Metadata') } Assert-Names $ids @($dependencies | ForEach-Object id) "$Id dependencies" - foreach ($dependency in $dependencies | Where-Object id -NE 'Microsoft.TestPlatform.ObjectModel') { + foreach ($dependency in $dependencies | Where-Object { $_.id -ne 'Microsoft.TestPlatform.ObjectModel' -and $_.id -notlike 'System.*' }) { if ($dependency.HasAttribute('exclude')) { throw "The adapter must retain build/analyzer assets from $($dependency.id)." } } } @@ -192,11 +238,11 @@ function Assert-PackageLayout($Archive, $Metadata, [string] $Id) { function New-Expectations([string] $Framework, [string] $Path) { $assemblies = [ordered]@{} - foreach ($id in $expectedIds | Where-Object { $_ -ne 'MSTest.Analyzers' }) { + foreach ($id in $portableIds | Where-Object { $_ -ne 'MSTest.Analyzers' }) { $archive = [System.IO.Compression.ZipFile]::OpenRead($packages[$id].Path) try { $names = switch ($id) { - 'MSTest.TestFramework' { @("lib/$Framework/MSTest.TestFramework.dll", "buildTransitive/$Framework/MSTest.TestFramework.Extensions.dll") } + 'MSTest.TestFramework' { @("lib/$Framework/MSTest.TestFramework.dll") } 'MSTest.TestAdapter' { @("buildTransitive/$Framework/MSTest.TestAdapter.dll", "buildTransitive/$Framework/MSTestAdapter.PlatformServices.dll") } 'Microsoft.Testing.Platform.MSBuild' { @("lib/$Framework/Microsoft.Testing.Extensions.MSBuild.dll") } default { @("lib/$Framework/$id.dll") } @@ -270,8 +316,8 @@ function Build-Consumer([string] $Name, [string] $Framework, [string] $PackageFe $assets = Get-Content -LiteralPath $assetsPath -Raw | ConvertFrom-Json -AsHashtable Assert-Names @([System.IO.Path]::TrimEndingDirectorySeparator($Cache)) @($assets.packageFolders.Keys | ForEach-Object { [System.IO.Path]::TrimEndingDirectorySeparator($_) }) "$Name restore folders" $resolved = @($assets.libraries.Keys | Where-Object { $_ -match '^(MSTest\.|Microsoft\.Testing\.)' }) - Assert-Names @($packages.Values | ForEach-Object { "$($_.Id)/$($_.Version)" }) $resolved "$Name native package closure" - foreach ($id in $expectedIds) { + Assert-Names @($portableIds | ForEach-Object { "$_/$($packages[$_].Version)" }) $resolved "$Name native package closure" + foreach ($id in $portableIds) { $package = $packages[$id] $cached = Join-Path $Cache ($id.ToLowerInvariant() + '\' + $package.Version + '\' + $id.ToLowerInvariant() + '.' + $package.Version + '.nupkg') $staged = Join-Path $PackageFeed "$id.$($package.Version).nupkg" @@ -290,7 +336,8 @@ function Run-Consumer($Consumer) { $expectations = Join-Path $Consumer.Directory 'expectations.json' New-Expectations $Consumer.Framework $expectations $env:TESTFX_BAZEL_MSTEST_EXPECTATIONS = $expectations - $env:TESTFX_BAZEL_CONSUMER_EVIDENCE = Join-Path $Consumer.Directory 'loaded-assemblies.json' + $env:TESTFX_BAZEL_CONSUMER_EVIDENCE = Join-Path $Consumer.Directory 'loaded-assemblies.paths' + $previousEvidence = if (Test-Path -LiteralPath $env:TESTFX_BAZEL_CONSUMER_EVIDENCE) { @(Get-Content -LiteralPath $env:TESTFX_BAZEL_CONSUMER_EVIDENCE).Count } else { 0 } $env:DOTNET_ROOT = Join-Path $directory 'missing-runtime' $env:DOTNET_ROOT_X64 = $env:DOTNET_ROOT $discovery = Invoke-Step "$name-discovery" $Consumer.Executable @('--list-tests') @@ -305,7 +352,10 @@ function Run-Consumer($Consumer) { '--report-trx', '--report-trx-filename', 'pass.trx', '--results-directory', $results ) Assert-Trx (Join-Path $results 'pass.trx') $passingTests - $provenance = Get-Content -LiteralPath $env:TESTFX_BAZEL_CONSUMER_EVIDENCE -Raw | ConvertFrom-Json + $evidencePaths = @(Get-Content -LiteralPath $env:TESTFX_BAZEL_CONSUMER_EVIDENCE) + if ($evidencePaths.Count -ne $previousEvidence + 1) { throw "$name did not append exactly one consumer provenance path." } + $provenancePath = $evidencePaths[-1] + $provenance = Get-Content -LiteralPath $provenancePath -Raw | ConvertFrom-Json $major = $Consumer.Framework.Substring(3).Split('.')[0] if ($provenance.Runtime -notlike ".NET $major.*" -or [System.IO.Path]::GetRelativePath($Consumer.Published, $provenance.CoreLib) -cne 'System.Private.CoreLib.dll') { throw "$name did not execute on its self-contained $($Consumer.Framework) runtime." @@ -317,7 +367,7 @@ function Run-Consumer($Consumer) { Assert-Trx (Join-Path $results 'failure.trx') @('IntentionalFailure') 1 'BAZEL_INTENTIONAL_FAILURE' $empty = Invoke-Step "$name-empty" $Consumer.Executable @('--filter', 'FullyQualifiedName~NoSuchPackageCase', '--minimum-expected-tests', '1') 9 if ($empty -notmatch 'tests ran 0, minimum expected 1') { throw "$name did not execute the zero-result policy." } - $runs.Add([pscustomobject]@{ Consumer = $Consumer; Runtime = $provenance.Runtime; Provenance = $env:TESTFX_BAZEL_CONSUMER_EVIDENCE; Results = $results; Passed = $true }) + $runs.Add([pscustomobject]@{ Consumer = $Consumer; Runtime = $provenance.Runtime; Provenance = $provenancePath; ProvenanceIndex = $env:TESTFX_BAZEL_CONSUMER_EVIDENCE; Results = $results; Passed = $true }) } function Run-MSBuildConsumer($Consumer) { @@ -329,6 +379,7 @@ function Run-MSBuildConsumer($Consumer) { @{ Name = 'failure'; Filter = 'FullyQualifiedName~IntentionalFailure'; Exit = 1; Tests = @('IntentionalFailure'); Failed = 1; Message = 'BAZEL_INTENTIONAL_FAILURE' } )) { $name = "msbuild-$($scenario.Name)" + $previousEvidence = @(Get-Content -LiteralPath $env:TESTFX_BAZEL_CONSUMER_EVIDENCE).Count $arguments = "--filter $($scenario.Filter) --report-trx --report-trx-filename $name.trx --results-directory `"$results`"" Push-Location $Consumer.Directory try { @@ -341,8 +392,11 @@ function Run-MSBuildConsumer($Consumer) { } finally { Pop-Location } Assert-Trx (Join-Path $results "$name.trx") $scenario.Tests $scenario.Failed $scenario.Message + $evidencePaths = @(Get-Content -LiteralPath $env:TESTFX_BAZEL_CONSUMER_EVIDENCE) + $expectedEvidence = $previousEvidence + $(if ($scenario.Name -eq 'pass') { 1 } else { 0 }) + if ($evidencePaths.Count -ne $expectedEvidence) { throw "$name did not preserve append-only consumer provenance." } } - $runs.Add([pscustomobject]@{ Consumer = $Consumer; Driver = 'Native Platform.MSBuild InvokeTestingPlatform'; ParentExits = @(0, 1); Results = $results; Passed = $true }) + $runs.Add([pscustomobject]@{ Consumer = $Consumer; Driver = 'Native Platform.MSBuild InvokeTestingPlatform'; ParentExits = @(0, 1); ProvenanceIndex = $env:TESTFX_BAZEL_CONSUMER_EVIDENCE; Provenance = $evidencePaths; Results = $results; Passed = $true }) } $environmentNames = @( @@ -366,11 +420,12 @@ try { [xml]$versions = Get-Content -LiteralPath (Join-Path $root 'eng\Versions.props') -Raw $mstestVersion = $versions.SelectSingleNode('//*[local-name()="VersionPrefix"]').InnerText + '-preview.bazel' $mtpVersion = $versions.SelectSingleNode('//*[local-name()="TestingPlatformVersionPrefix"]').InnerText + '-preview.bazel' - $null = Invoke-Step 'native-pack' $bazel @('build', '//:mstest_package_closure', '--jobs=2', '--noshow_progress', '--show_result=0') + $packageClosure = if ($IncludeWindowsPlatformPackages) { '//:mstest_platform_package_closure' } else { '//:mstest_package_closure' } + $null = Invoke-Step 'native-pack' $bazel @('build', $packageClosure, '--jobs=2', '--noshow_progress', '--show_result=0') $executionRoot = & $bazel info execution_root if ($LASTEXITCODE -ne 0) { throw 'Could not locate the native execution root.' } - $paths = @(& $bazel cquery //:mstest_package_closure --output=files --noshow_progress) - if ($LASTEXITCODE -ne 0 -or $paths.Count -ne $expectedIds.Count) { throw 'Expected exactly eight native packages in the MSTest validation closure.' } + $paths = @(& $bazel cquery $packageClosure --output=files --noshow_progress) + if ($LASTEXITCODE -ne 0 -or $paths.Count -ne $expectedIds.Count) { throw "Expected $($expectedIds.Count) native packages in the MSTest validation closure." } foreach ($path in $paths) { $packagePath = Join-Path $executionRoot $path $archive = [System.IO.Compression.ZipFile]::OpenRead($packagePath) @@ -403,6 +458,21 @@ try { finally { $archive.Dispose() } } Assert-Names $expectedIds @($packages.Keys) 'Native feed' + if ($IsWindows) { + $coreArchive = [System.IO.Compression.ZipFile]::OpenRead($packages['MSTest.TestFramework'].Path) + $adapterArchive = $null + try { + $adapterArchive = [System.IO.Compression.ZipFile]::OpenRead($packages['MSTest.TestAdapter'].Path) + if ((Get-ZipHash $adapterArchive 'buildTransitive/net462/MSTest.TestFramework.dll') -cne + (Get-ZipHash $coreArchive 'lib/net462/MSTest.TestFramework.dll')) { + throw 'The net462 VSTest resolver copy must match ordinary net462 core.' + } + } + finally { + $coreArchive.Dispose() + if ($adapterArchive) { $adapterArchive.Dispose() } + } + } $sdkVersion = [regex]::Match((Get-Content -LiteralPath (Join-Path $root 'MODULE.bazel') -Raw), 'dotnet\.toolchain\(dotnet_version = "([^"]+)"\)').Groups[1].Value if (-not $sdkVersion) { throw 'Could not identify the native toolchain SDK.' } @@ -458,7 +528,7 @@ try { $expectations = Join-Path $counterfactual.Directory 'expectations.json' New-Expectations 'net11.0' $expectations $env:TESTFX_BAZEL_MSTEST_EXPECTATIONS = $expectations - $env:TESTFX_BAZEL_CONSUMER_EVIDENCE = Join-Path $counterfactual.Directory 'loaded-assemblies.json' + $env:TESTFX_BAZEL_CONSUMER_EVIDENCE = Join-Path $counterfactual.Directory 'loaded-assemblies.paths' $results = Join-Path $counterfactual.Directory 'results' $null = Invoke-Step 'counterfactual-execution' $counterfactual.Executable @( '--filter', 'FullyQualifiedName!~IntentionalFailure', '--minimum-expected-tests', '3', @@ -472,7 +542,7 @@ try { Run-Consumer $restored } $succeeded = $true - Write-Host "Native MSTest package consumers passed. Evidence: $directory" + Write-Host "Native MSTest ordinary package consumers passed. Optional UI packages cover modern native layouts, not classic UAP production or UI activation. Evidence: $directory" } finally { foreach ($name in $environmentNames) { @@ -481,7 +551,7 @@ finally { else { Remove-ProcessEnvironmentVariable $name } } Pop-Location - [pscustomobject]@{ Passed = $succeeded; BaseRevision = $revision; WorkingTree = $workingTree; Packages = @($packages.Values); Runs = $runs; Steps = $steps } | + [pscustomobject]@{ Passed = $succeeded; IncludeWindowsPlatformPackages = [bool]$IncludeWindowsPlatformPackages; ClassicUapProduced = $false; UIActivationValidated = $false; BaseRevision = $revision; WorkingTree = $workingTree; Packages = @($packages.Values); Runs = $runs; Steps = $steps } | ConvertTo-Json -Depth 10 | Set-Content -LiteralPath (Join-Path $directory 'validation.json') -Encoding utf8 } diff --git a/eng/bazel/validate-packages.ps1 b/eng/bazel/validate-packages.ps1 index 7feadd0594..fb74879cf1 100644 --- a/eng/bazel/validate-packages.ps1 +++ b/eng/bazel/validate-packages.ps1 @@ -22,7 +22,7 @@ $directory = if ($EvidenceRoot) { Join-Path $EvidenceRoot $run } else { Join-Pat $feed = Join-Path $directory 'feed' $consumer = Join-Path $directory 'consumer' New-Item -ItemType Directory -Path $feed, $consumer | Out-Null -$frameworks = @('net8.0', 'net9.0', 'net10.0', 'net11.0') +$frameworks = @('net10.0', 'net11.0') $expectedPackageIds = @('Microsoft.Testing.Platform', 'Microsoft.Testing.Extensions.TrxReport.Abstractions', 'Microsoft.Testing.Extensions.TrxReport') $seenPackages = [System.Collections.Generic.HashSet[string]]::new([StringComparer]::Ordinal) $seenRuntimes = [System.Collections.Generic.HashSet[string]]::new([StringComparer]::Ordinal) diff --git a/eng/bazel/validate-sdk-packages.ps1 b/eng/bazel/validate-sdk-packages.ps1 index 9886e80acc..338bdd9f25 100644 --- a/eng/bazel/validate-sdk-packages.ps1 +++ b/eng/bazel/validate-sdk-packages.ps1 @@ -22,7 +22,7 @@ $feed = Join-Path $directory 'feed' New-Item -ItemType Directory -Path $feed -Force | Out-Null $pwsh = Join-Path $PSHOME $(if ($IsWindows) { 'pwsh.exe' } else { 'pwsh' }) $bazel = Join-Path $root 'eng\bazel.ps1' -$frameworks = @('net8.0', 'net9.0', 'net10.0', 'net11.0') +$frameworks = @('net10.0', 'net11.0') $steps = [Collections.Generic.List[object]]::new() $packages = @{} $evaluations = [Collections.Generic.List[object]]::new() @@ -131,7 +131,7 @@ function Assert-Trx([string] $Path, [string] $Name, [string] $Outcome) { Assert-Equal 0 ([int]$counters.notExecuted) 'Skipped test count' } -function New-Consumer([string] $Name, [string] $Properties, [switch] $Meta, [switch] $Layered) { +function New-Consumer([string] $Name, [string] $Properties, [switch] $Meta, [switch] $Layered, [string] $Framework = 'net11.0') { $path = Join-Path $directory $Name New-Item -ItemType Directory -Path $path | Out-Null foreach ($file in @('Directory.Build.props', 'Directory.Build.targets', 'Directory.Packages.props')) { @@ -143,7 +143,7 @@ function New-Consumer([string] $Name, [string] $Properties, [switch] $Meta, [swi 'msbuild-sdks' = @{ 'MSTest.Sdk' = $mstestVersion } test = @{ runner = $(if ($Meta) { 'VSTest' } else { 'Microsoft.Testing.Platform' }) } } | ConvertTo-Json -Depth 5 | Set-Content -LiteralPath (Join-Path $path 'global.json') -Encoding utf8 - $propertiesXml = "net11.0enableenable$Properties" + $propertiesXml = "$Frameworkenableenable$Properties" $project = if ($Layered) { @" @@ -334,8 +334,19 @@ try { @{ Name = 'sdk-aot-selection'; Properties = 'true'; Expected = @('Microsoft.Testing.Platform.MSBuild', 'MSTest.TestFramework', 'MSTest.SourceGeneration', 'MSTest.TestAdapter', 'Microsoft.Testing.Extensions.TrxReport', 'Microsoft.Testing.Extensions.CodeCoverage', 'Microsoft.CodeCoverage.MSBuild') }, @{ Name = 'sdk-version-overrides'; Properties = '7.8.93.2.1'; MSTestVersion = '7.8.9'; PlatformVersion = '3.2.1'; Expected = @('MSTest.TestFramework', 'MSTest.TestAdapter', 'Microsoft.Testing.Extensions.TrxReport', 'Microsoft.Testing.Extensions.CodeCoverage') } ) + foreach ($framework in $frameworks) { + foreach ($model in @('Uwp', 'WinUI')) { + $evaluationCases += @{ + Name = "sdk-$($model.ToLowerInvariant())-$framework" + Framework = "$framework-windows10.0.26100.0" + Properties = "true$model" + Expected = @('MSTest.TestFramework', "MSTest.$model", 'Microsoft.Testing.Extensions.TrxReport', 'Microsoft.Testing.Extensions.CodeCoverage') + } + } + } foreach ($case in $evaluationCases) { - $consumer = New-Consumer $case.Name $case.Properties -Layered:([bool]$case.Layered) + $framework = if ($case.Framework) { $case.Framework } else { 'net11.0' } + $consumer = New-Consumer $case.Name $case.Properties -Layered:([bool]$case.Layered) -Framework $framework $result = Invoke-Step "evaluate-$($case.Name)" $dotnet @('msbuild', 'Consumer.csproj', '-nologo', '-getProperty:UsingMSTestSdk,MSTestVersion,MicrosoftTestingPlatformVersion,_MSTestSdkImportsMicrosoftNETSdk,OutputType,NETCoreSdkVersion,MSBuildToolsPath', '-getItem:PackageReference,PackageVersion', "-bl:$(Join-Path $directory "$($case.Name)-evaluation.binlog")") $consumer -Environment $consumerEnvironment diff --git a/eng/bazel/validate.ps1 b/eng/bazel/validate.ps1 index 8873b696ae..f72053574e 100644 --- a/eng/bazel/validate.ps1 +++ b/eng/bazel/validate.ps1 @@ -175,7 +175,7 @@ try { RulesDotnet = 'add5c92b30888a70aa951de1744a770b8f8ef436' Sdk = $toolchain.Groups[1].Value Runtime = $toolchain.Groups[2].Value - TargetFrameworks = @('net8.0', 'net9.0', 'net10.0', 'net11.0') + TargetFrameworks = @('net10.0', 'net11.0') TestCounts = $counts TestSuite = $testSuite UnsupportedSuites = @($unsupportedSuites) diff --git a/eng/bazel/windows.bzl b/eng/bazel/windows.bzl index 68667e021d..c9bcc14ee0 100644 --- a/eng/bazel/windows.bzl +++ b/eng/bazel/windows.bzl @@ -6,7 +6,6 @@ load(":defs.bzl", "PORTABLE_FRAMEWORKS", "testfx_library", "testfx_matrix") _PLATFORM = "src/Platform/Microsoft.Testing.Platform" _SHARED = "src/Platform/SharedExtensionHelpers" _PACKAGED_APP = "src/Platform/Microsoft.Testing.Extensions.PackagedApp" -_FRAMEWORK = "src/TestFramework/TestFramework" _UI_AUTOMATION = "src/TestFramework/TestFramework.Windows.UIAutomation" _PACKAGED_FRAMEWORKS = [tfm + "-windows10.0.19041.0" for tfm in PORTABLE_FRAMEWORKS] _DESKTOP_FRAMEWORKS = [tfm + "-windows7.0" for tfm in PORTABLE_FRAMEWORKS] @@ -100,60 +99,24 @@ def _windows_library(name, target_frameworks, linked_srcs = [], minimum_version ) def _mstest_flavor(flavor, framework, symbol, projection_deps): - core = "framework_" + flavor - extensions = "framework_extensions_" + flavor + attributes = "mstest_" + flavor + assembly_name = "MSTest.Uwp" if flavor == "uwp" else "MSTest.WinUI" services = "platform_services_" + flavor adapter = "adapter_" + flavor - framework_project = "src/TestFramework/TestFramework.Extensions" + framework_project = "src/TestFramework/" + assembly_name services_project = "src/Adapter/MSTestAdapter.PlatformServices" adapter_project = "src/Adapter/MSTest.TestAdapter" _windows_library( - name = core, - project = _FRAMEWORK, - assembly_name = "MSTest.TestFramework", - target_frameworks = [framework], - minimum_version = "10.0.17763.0" if flavor == "winui" else "", - defines = ["EXCLUDE_RANGE_INDEX_POLYFILL", "EXCLUDE_OS_POLYFILL", "TESTFRAMEWORK_CI_DETECTOR", symbol], - linked_srcs = [ - _PLATFORM + "/Helpers/RoslynHashCode.cs", - _PLATFORM + "/Helpers/CIEnvironmentDetector.cs", - ], - resources = {_FRAMEWORK + "/Resources/FrameworkMessages.resx": "Microsoft.VisualStudio.TestTools.UnitTesting.Resources.FrameworkMessages"}, - usings = ["Polyfills", "Microsoft.VisualStudio.TestTools.UnitTesting.Resources"], - internals_visible_to = [ - "DynamicProxyGenAssembly2", - "MSTestAdapter.PlatformServices", - "MSTest.TestAdapter", - "Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests", - "MSTest.TestFramework.Extensions", - "MSTest.Extensions.Hosting", - "Microsoft.VisualStudio.TestPlatform.TestFramework.UnitTests", - "MSTestAdapter.PlatformServices.UnitTests", - "MSTest.Performance.Benchmarks", - ], - deps = [":assert_generator_plugin"], - ) - _windows_library( - name = extensions, + name = attributes, project = framework_project, - assembly_name = "MSTest.TestFramework.Extensions", + assembly_name = assembly_name, target_frameworks = [framework], - # The WinUI source already carries its supported-OS annotation. - emit_supported_os = flavor != "winui", + minimum_version = "10.0.17763.0" if flavor == "winui" else "", defines = ["EXCLUDE_RANGE_INDEX_POLYFILL", "EXCLUDE_OS_POLYFILL", symbol], usings = ["Polyfills", "Microsoft.VisualStudio.TestTools.UnitTesting.Resources"], - resources = {framework_project + "/Resources/FrameworkExtensionsMessages.resx": "Microsoft.VisualStudio.TestTools.UnitTesting.Resources.FrameworkExtensionsMessages"}, + resources = {framework_project + "/Resources/FrameworkExtensionsMessages.resx": "Microsoft.VisualStudio.TestTools.UnitTesting.Resources.FrameworkExtensionsMessages"} if flavor == "winui" else {}, analyzer_configs = ["//eng/bazel/windows:winrt.globalconfig"], - embedded_resources = { - framework_project + "/Properties/Extension.UWP.rd.xml": "Microsoft.VisualStudio.TestTools.UnitTesting.Properties.Extension.UWP.rd.xml", - } if flavor == "uwp" else {}, - internals_visible_to = [ - "MSTestAdapter.PlatformServices", - "MSTestAdapter.PlatformServices.UnitTests", - "MSTest.TestAdapter", - "Microsoft.VisualStudio.TestPlatform.MSTestAdapter.UnitTests", - ], - deps = [":" + core] + projection_deps, + deps = [":framework"] + projection_deps, ) _windows_library( name = services, @@ -174,7 +137,7 @@ def _mstest_flavor(flavor, framework, symbol, projection_deps): "MSTest.Acceptance.IntegrationTests", "MSTest.Performance.Benchmarks", ], - deps = [":" + core, ":" + extensions] + projection_deps, + deps = [":framework"] + projection_deps, ) _windows_library( name = adapter, @@ -206,8 +169,7 @@ def _mstest_flavor(flavor, framework, symbol, projection_deps): deps = [ ":platform", ":" + services, - ":" + core, - ":" + extensions, + ":framework", ":trx_abstractions", ":trx", ":telemetry", @@ -217,7 +179,7 @@ def _mstest_flavor(flavor, framework, symbol, projection_deps): "@paket.source//microsoft.testplatform.objectmodel", ], ) - native.filegroup(name = "_windows_" + flavor, srcs = [":" + core, ":" + extensions, ":" + services, ":" + adapter]) + native.filegroup(name = "_windows_" + flavor, srcs = [":framework", ":" + attributes, ":" + services, ":" + adapter]) testfx_matrix(name = "windows_" + flavor, target = ":_windows_" + flavor, frameworks = [framework]) def _library_probe(name, framework, scenario, deps, project_sdk = "default"): @@ -389,7 +351,7 @@ def windows_libraries(): target_frameworks = _DESKTOP_FRAMEWORKS, project_sdk = "windowsdesktop", resources = {_UI_AUTOMATION + "/Resources/WindowsUIAutomationResources.resx": "Microsoft.VisualStudio.TestTools.UnitTesting.Windows.UIAutomation.Resources.WindowsUIAutomationResources"}, - deps = [":framework", ":framework_extensions"], + deps = [":framework"], ) testfx_matrix( name = "windows_ui_automation_all", @@ -418,22 +380,22 @@ def windows_libraries(): probes.append(":" + name) _library_probe( "windows_probe_desktop", - "net8.0-windows7.0", + "net10.0-windows7.0", "desktop", - [":windows_ui_automation", ":framework", ":framework_extensions"], + [":windows_ui_automation", ":framework"], project_sdk = "windowsdesktop", ) _library_probe( "windows_probe_uwp", "net10.0-windows10.0.17763.0", "uwp", - [":adapter_uwp", ":platform_services_uwp", ":framework_extensions_uwp", ":framework_uwp"], + [":adapter_uwp", ":platform_services_uwp", ":mstest_uwp", ":framework"], ) _library_probe( "windows_probe_winui", "net10.0-windows10.0.18362.0", "winui", - [":adapter_winui", ":platform_services_winui", ":framework_extensions_winui", ":framework_winui"], + [":adapter_winui", ":platform_services_winui", ":mstest_winui", ":framework"], ) native.filegroup( name = "windows_probes", diff --git a/eng/bazel/windows/AppModelHost.cs b/eng/bazel/windows/AppModelHost.cs index 2fc2bd1e7f..cd28f3b612 100644 --- a/eng/bazel/windows/AppModelHost.cs +++ b/eng/bazel/windows/AppModelHost.cs @@ -57,7 +57,14 @@ private static void WriteProvenance() }), }; string json = JsonSerializer.Serialize(report); - File.WriteAllText(Path.Combine(AppContext.BaseDirectory, "native-app-model.json"), json); + string reportPath = Path.Combine(AppContext.BaseDirectory, "native-app-model-" + Guid.NewGuid().ToString("N") + ".json"); + using (FileStream stream = File.Open(reportPath, FileMode.CreateNew, FileAccess.Write, FileShare.Read)) + using (var writer = new StreamWriter(stream)) + { + writer.Write(json); + } + + File.AppendAllLines(Path.Combine(AppContext.BaseDirectory, "native-app-model.paths"), [reportPath]); Console.WriteLine("BAZEL_APPMODEL_PROVENANCE: " + json); } diff --git a/eng/bazel/windows/LibraryProbe.cs b/eng/bazel/windows/LibraryProbe.cs index 7fa880692e..b951efa203 100644 --- a/eng/bazel/windows/LibraryProbe.cs +++ b/eng/bazel/windows/LibraryProbe.cs @@ -56,10 +56,8 @@ public static void Main() throw new InvalidOperationException("A WPF reference assembly was loaded as a runtime implementation."); } - Assembly desktopExtensions = Assembly.Load("MSTest.TestFramework.Extensions"); sourceAssemblies.Add(windowTest.Assembly); - sourceAssemblies.Add(VerifyFrameworkApi(desktopExtensions, hasDesktopApi: true)); - sourceAssemblies.Add(desktopExtensions); + sourceAssemblies.Add(VerifyFrameworkApi()); runtimeAssemblies.Add(automation); #elif WINDOWS_UWP_PROBE || WINDOWS_WINUI_PROBE #if WINDOWS_UWP_PROBE @@ -67,22 +65,40 @@ public static void Main() #else scenario = "winui"; #endif - Assembly extensions = Assembly.Load("MSTest.TestFramework.Extensions"); - Assembly framework = VerifyFrameworkApi(extensions, hasDesktopApi: false); - Type uiMethod = extensions.GetType( + string uiAssemblyName = scenario == "uwp" ? "MSTest.Uwp" : "MSTest.WinUI"; + Assembly attributes = Assembly.Load(uiAssemblyName); + Assembly framework = VerifyFrameworkApi(attributes); + Type uiMethod = attributes.GetType( "Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute", throwOnError: true)!; - if (!typeof(Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute).IsAssignableFrom(uiMethod)) + if (uiMethod.Assembly != attributes || !typeof(Microsoft.VisualStudio.TestTools.UnitTesting.TestMethodAttribute).IsAssignableFrom(uiMethod)) { - throw new InvalidOperationException("The Windows flavor did not expose the UI test method attribute."); + throw new InvalidOperationException($"The UI test method attribute must be defined in {uiAssemblyName} and derive from shared core."); } - sourceAssemblies.Add(extensions); + const string winuiTargetName = "Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.WinUITestTargetAttribute"; + if ((attributes.GetType(winuiTargetName) is not null) != (scenario == "winui")) + { + throw new InvalidOperationException("WinUITestTargetAttribute must be isolated to MSTest.WinUI."); + } + + string otherFlavor = scenario == "uwp" ? "MSTest.WinUI" : "MSTest.Uwp"; + if (File.Exists(Path.Combine(AppContext.BaseDirectory, otherFlavor + ".dll"))) + { + throw new InvalidOperationException("The Windows consumer contains the other flavor's UI attributes."); + } + + sourceAssemblies.Add(attributes); sourceAssemblies.Add(framework); sourceAssemblies.Add(Assembly.Load("MSTestAdapter.PlatformServices")); sourceAssemblies.Add(Assembly.Load("MSTest.TestAdapter")); #else #error A Windows library probe scenario must be selected. #endif + if (File.Exists(Path.Combine(AppContext.BaseDirectory, "MSTest.TestFramework.Extensions.dll"))) + { + throw new InvalidOperationException("The retired Extensions assembly must not be in a native consumer layout."); + } + foreach (Assembly assembly in sourceAssemblies) { if (!assembly.GetCustomAttributes() @@ -103,34 +119,40 @@ public static void Main() } #if WINDOWS_DESKTOP_PROBE || WINDOWS_UWP_PROBE || WINDOWS_WINUI_PROBE - private static Assembly VerifyFrameworkApi(Assembly extensions, bool hasDesktopApi) + private static Assembly VerifyFrameworkApi(Assembly? attributes = null) { Assembly framework = typeof(Microsoft.VisualStudio.TestTools.UnitTesting.Assert).Assembly; Type context = typeof(Microsoft.VisualStudio.TestTools.UnitTesting.TestContext); if (framework.GetName().Name != "MSTest.TestFramework" || context.Assembly != framework - || extensions.GetType(context.FullName!) is not null) + || attributes?.GetType(context.FullName!) is not null + || framework.GetCustomAttribute() is not null) { - throw new InvalidOperationException("TestContext must be defined in the core framework, not Extensions."); + throw new InvalidOperationException("TestContext must be defined in the ordinary shared core, not a UI-specific assembly."); } const string deploymentItemName = "Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute"; Type? deploymentItem = framework.GetType(deploymentItemName); - if ((deploymentItem is not null) != hasDesktopApi - || (deploymentItem is not null && deploymentItem.Assembly != framework) - || extensions.GetType(deploymentItemName) is not null) + if (deploymentItem is null || deploymentItem.Assembly != framework + || attributes?.GetType(deploymentItemName) is not null) { - throw new InvalidOperationException($"DeploymentItemAttribute must be defined only in ordinary core and excluded from UI core. Expected desktop API: {hasDesktopApi}."); + throw new InvalidOperationException("DeploymentItemAttribute must be defined in shared modern core, including for UI consumers."); } string[] directories = ["TestRunDirectory", "DeploymentDirectory", "ResultsDirectory", "TestRunResultsDirectory", "TestResultsDirectory", "TestTempDirectory"]; foreach (string directory in directories) { - if ((context.GetProperty(directory) is not null) != hasDesktopApi) + if (context.GetProperty(directory) is null) { - throw new InvalidOperationException($"TestContext.{directory} must remain excluded from UI core and available in ordinary core. Expected desktop API: {hasDesktopApi}."); + throw new InvalidOperationException($"TestContext.{directory} must be available from shared core for every modern consumer."); } } + if (framework.GetType("Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute") is not null + || framework.GetType("Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.WinUITestTargetAttribute") is not null) + { + throw new InvalidOperationException("UI-specific attributes must not be defined in shared core."); + } + return framework; } #endif diff --git a/eng/bazel/windows/targeting_tests.bzl b/eng/bazel/windows/targeting_tests.bzl index 12837a41d4..1e9bac5f6b 100644 --- a/eng/bazel/windows/targeting_tests.bzl +++ b/eng/bazel/windows/targeting_tests.bzl @@ -17,6 +17,7 @@ load( ) load("@rules_dotnet//dotnet/private:providers.bzl", "DotnetAssemblyCompileInfo", "DotnetAssemblyRuntimeInfo") load("@rules_dotnet//dotnet/private/transitions:common.bzl", "FRAMEWORK_COMPATABILITY_TRANSITION_OUTPUTS") +load("//eng/bazel:mstest-packages.bzl", "mstest_package_tfm") def _configuration(framework): return analysis_test_transition(settings = { @@ -32,26 +33,26 @@ def _flavor_targets(flavor, framework): providers = [DotnetAssemblyCompileInfo, DotnetAssemblyRuntimeInfo], ) for name, target in [ - ("extensions", "framework_extensions_" + flavor), + ("attributes", "mstest_" + flavor), ("services", "platform_services_" + flavor), ("adapter", "adapter_" + flavor), ("probe", "windows_probe_" + flavor + "_app"), ] } -def _core_owners(target): +def _assembly_owners(target, name): compile_info = target[DotnetAssemblyCompileInfo] runtime_info = target[DotnetAssemblyRuntimeInfo] compile_owners = depset([ str(reference.owner) for reference in compile_info.refs + compile_info.transitive_refs.to_list() - if reference.basename == "MSTest.TestFramework.dll" + if reference.basename == name + ".dll" ]) runtime_owners = depset([ str(library.owner) for dependency in [runtime_info] + runtime_info.deps.to_list() for library in dependency.libs - if library.basename == "MSTest.TestFramework.dll" + if library.basename == name + ".dll" ]) return sorted(compile_owners.to_list()), sorted(runtime_owners.to_list()) @@ -86,19 +87,41 @@ def _targeting_tests_impl(ctx): {"name": "Microsoft.NETCore.App", "version": "8.0.0"}, {"name": "Microsoft.WindowsDesktop.App", "version": "8.0.0"}, ], desktop["runtimeOptions"]["frameworks"]), + ("Net11UwpConsumesNet10Attributes", "net10.0-windows10.0.17763.0", get_nearest_compatible_target_framework("net11.0-windows10.0.17763.0", ["net10.0-windows10.0.17763.0"])), + ("Net11WinuiConsumesNet10Attributes", "net10.0-windows10.0.18362.0", get_nearest_compatible_target_framework("net11.0-windows10.0.18362.0", ["net10.0-windows10.0.18362.0"])), + ("ModernUiSelectsOrdinaryCore", "net11.0", get_nearest_compatible_target_framework("net11.0-windows10.0.18362.0", ["netstandard2.0", "net462", "net10.0", "net11.0"])), + ("UwpLibPathUsesNuGetCanonicalWindowsVersion", "net10.0-windows10.0.17763", mstest_package_tfm("net10.0-windows10.0.17763.0")), + ("WinuiLibPathUsesNuGetCanonicalWindowsVersion", "net10.0-windows10.0.18362", mstest_package_tfm("net10.0-windows10.0.18362.0")), + ("ClassicUwpLibPathPreservesMinimum", "uap10.0.16299", mstest_package_tfm("uap10.0.16299")), ] - for flavor, core, targets in [ - ("Desktop", "framework", [ctx.attr.desktop[0]]), - ("Uwp", "framework_uwp", [ctx.attr.uwp_extensions[0], ctx.attr.uwp_services[0], ctx.attr.uwp_adapter[0], ctx.attr.uwp_probe[0]]), - ("Winui", "framework_winui", [ctx.attr.winui_extensions[0], ctx.attr.winui_services[0], ctx.attr.winui_adapter[0], ctx.attr.winui_probe[0]]), + for flavor, targets in [ + ("Desktop", [ctx.attr.desktop[0]]), + ("Uwp", [ctx.attr.uwp_attributes[0], ctx.attr.uwp_services[0], ctx.attr.uwp_adapter[0], ctx.attr.uwp_probe[0]]), + ("Winui", [ctx.attr.winui_attributes[0], ctx.attr.winui_services[0], ctx.attr.winui_adapter[0], ctx.attr.winui_probe[0]]), ]: for target in targets: - compile_owners, runtime_owners = _core_owners(target) - expected = [str(Label("//:" + core))] + compile_owners, runtime_owners = _assembly_owners(target, "MSTest.TestFramework") + expected = [str(Label("//:framework"))] cases.extend([ ("{} {} compile core".format(flavor, target.label), expected, compile_owners), ("{} {} runtime core".format(flavor, target.label), expected, runtime_owners), ]) + for flavor, assembly_name, other in [("uwp", "MSTest.Uwp", "MSTest.WinUI"), ("winui", "MSTest.WinUI", "MSTest.Uwp")]: + for kind in ["attributes", "services", "adapter", "probe"]: + target = getattr(ctx.attr, flavor + "_" + kind)[0] + for name, owner, present in [ + (assembly_name, "mstest_" + flavor, kind in ["attributes", "probe"]), + (other, "", False), + ("MSTest.TestAdapter", "adapter_" + flavor, kind in ["adapter", "probe"]), + ("MSTestAdapter.PlatformServices", "platform_services_" + flavor, kind in ["services", "adapter", "probe"]), + ("MSTest.TestFramework.Extensions", "", False), + ]: + compile_owners, runtime_owners = _assembly_owners(target, name) + expected = [str(Label("//:" + owner))] if present else [] + cases.extend([ + ("{} {} compile {}".format(flavor, kind, name), expected, compile_owners), + ("{} {} runtime {}".format(flavor, kind, name), expected, runtime_owners), + ]) failures = [ "{}: expected {}, actual {}".format(name, repr(expected), repr(actual)) for name, expected, actual in cases @@ -115,7 +138,7 @@ windows_targeting_test = rule( attrs = { "desktop": attr.label( default = "//:windows_probe_desktop_app", - cfg = _configuration("net8.0-windows7.0"), + cfg = _configuration("net10.0-windows7.0"), providers = [DotnetAssemblyCompileInfo, DotnetAssemblyRuntimeInfo], ), } | _flavor_targets("uwp", "net10.0-windows10.0.17763.0") | _flavor_targets("winui", "net10.0-windows10.0.18362.0"), diff --git a/eng/bazel/windows/validate-app-model.ps1 b/eng/bazel/windows/validate-app-model.ps1 index 24eae66010..9da26539c3 100644 --- a/eng/bazel/windows/validate-app-model.ps1 +++ b/eng/bazel/windows/validate-app-model.ps1 @@ -24,6 +24,7 @@ $directory = Join-Path $ArtifactsDirectory $run $layout = Join-Path $directory 'package layout' $identity = "TestFx.Bazel.$run" $steps = [Collections.Generic.List[object]]::new() +$recordedProvenancePaths = @() $succeeded = $false $inputHashes = @(Get-FileHash -Algorithm SHA256 -LiteralPath @( (Join-Path $root 'MODULE.bazel'), (Join-Path $root 'eng\bazel\defs.bzl'), @@ -63,6 +64,7 @@ function Invoke-Process([string] $Name, [string] $Executable, [string[]] $Argume if ($timedOut -or $process.ExitCode -ne $ExpectedExit) { throw "$Name returned $($process.ExitCode), expected $ExpectedExit; timeout=$timedOut. See its retained log." } + if ($text.Contains('BAZEL_APPMODEL_PROVENANCE: ')) { $null = Read-AppModelProvenance -RequireNew } if ($StandardOutputOnly) { return $output } return $text } @@ -108,6 +110,21 @@ function Assert-Pass([string] $Path) { } } +function Read-AppModelProvenance([switch] $RequireNew) { + $paths = @(Get-Content -LiteralPath (Join-Path $layout 'native-app-model.paths')) + if ($paths.Count -eq 0 -or $paths.Count -lt $script:recordedProvenancePaths.Count -or + ($RequireNew -and $paths.Count -le $script:recordedProvenancePaths.Count)) { + throw 'The app-model host did not append a provenance path.' + } + for ($index = 0; $index -lt $script:recordedProvenancePaths.Count; $index++) { + if ($paths[$index] -cne $script:recordedProvenancePaths[$index]) { + throw 'The app-model host overwrote an earlier provenance path.' + } + } + $script:recordedProvenancePaths = $paths + return Get-Content -LiteralPath $paths[-1] -Raw | ConvertFrom-Json +} + Push-Location $root try { $targets = @('//:windows_app_model') @@ -120,7 +137,7 @@ try { $hostLayout = Copy-Publish '//:windows_app_model' 'TestFx.Bazel.AppModelHost' $layout if (-not $HostOnly) { $controllers = [ordered]@{} - foreach ($framework in @('net8', 'net9')) { + foreach ($framework in @('net10', 'net11')) { $controllers[$framework] = Copy-Publish "//:windows_controller_$framework" 'mstest-appmodel-controller' (Join-Path $directory "controller-$framework") } $sdkVersion = [regex]::Match((Get-Content -LiteralPath 'MODULE.bazel' -Raw), 'dotnet\.toolchain\(dotnet_version = "([^"]+)"\)').Groups[1].Value @@ -174,7 +191,7 @@ try { $activated = Join-Path $directory 'activated' $null = Invoke-Process 'registered-activation' $hostLayout.Executable ($pass + @('--results-directory', $activated)) Assert-Pass (Join-Path $activated 'tests.trx') - $marker = Get-Content -LiteralPath (Join-Path $layout 'native-app-model.json') -Raw | ConvertFrom-Json + $marker = Read-AppModelProvenance $packages = Get-OwnedPackage if ($packages.Count -ne 1 -or $marker.PackageName -cne $identity -or -not [string]::Equals($packages[0].InstallLocation.TrimEnd('\'), $layout.TrimEnd('\'), [StringComparison]::OrdinalIgnoreCase) -or @@ -207,9 +224,9 @@ try { } finally { try { - $markerPath = Join-Path $layout 'native-app-model.json' + $markerPath = Join-Path $layout 'native-app-model.paths' if (Test-Path -LiteralPath $markerPath) { - $marker = Get-Content -LiteralPath $markerPath -Raw | ConvertFrom-Json + $marker = Read-AppModelProvenance $process = Get-CimInstance Win32_Process -Filter "ProcessId=$($marker.ProcessId)" if ($process -and [string]::Equals($process.ExecutablePath, (Join-Path $layout 'TestFx.Bazel.AppModelHost.exe'), [StringComparison]::OrdinalIgnoreCase)) { Stop-Process -Id $marker.ProcessId diff --git a/eng/bazel/windows/validate.ps1 b/eng/bazel/windows/validate.ps1 index eea550fe07..d6ee3ff856 100644 --- a/eng/bazel/windows/validate.ps1 +++ b/eng/bazel/windows/validate.ps1 @@ -22,6 +22,7 @@ $directory = Join-Path $ArtifactsDirectory $run New-Item -ItemType Directory -Path $directory | Out-Null $steps = [Collections.Generic.List[object]]::new() $consumers = [Collections.Generic.List[object]]::new() +$coreHashes = @{} $succeeded = $false $inputHashes = @(Get-FileHash -Algorithm SHA256 -LiteralPath @( (Join-Path $root 'MODULE.bazel'), (Join-Path $root 'BUILD.bazel'), @@ -77,11 +78,9 @@ function Invoke-Consumer([string] $Name, [string] $Executable, [string] $Layout) } $probes = @( - @{ Name = 'windows_probe_packaged_net8'; Scenario = 'packaged'; Major = 8; Platform = '10.0.19041.0' }, - @{ Name = 'windows_probe_packaged_net9'; Scenario = 'packaged'; Major = 9; Platform = '10.0.19041.0' }, @{ Name = 'windows_probe_packaged_net10'; Scenario = 'packaged'; Major = 10; Platform = '10.0.19041.0' }, @{ Name = 'windows_probe_packaged_net11'; Scenario = 'packaged'; Major = 11; Platform = '10.0.19041.0' }, - @{ Name = 'windows_probe_desktop'; Scenario = 'desktop'; Major = 8; Platform = '7.0' }, + @{ Name = 'windows_probe_desktop'; Scenario = 'desktop'; Major = 10; Platform = '7.0' }, @{ Name = 'windows_probe_uwp'; Scenario = 'uwp'; Major = 10; Platform = '10.0.17763.0' }, @{ Name = 'windows_probe_winui'; Scenario = 'winui'; Major = 10; Platform = '10.0.18362.0' } ) @@ -132,8 +131,17 @@ try { if ($report.Scenario -cne $probe.Scenario -or ([Version]$report.Runtime).Major -ne $probe.Major) { throw "Consumer scenario/runtime mismatch for $($probe.Name)." } - $expectedCount = if ($probe.Scenario -eq 'packaged') { 2 } elseif ($probe.Scenario -eq 'desktop') { 3 } else { 4 } - if (@($report.SourceAssemblies).Count -ne $expectedCount) { throw "Missing source assembly evidence for $($probe.Name)." } + $expectedAssemblies = switch ($probe.Scenario) { + 'packaged' { @('Microsoft.Testing.Extensions.PackagedApp', 'Microsoft.Testing.Platform') } + 'desktop' { @('MSTest.Windows.UIAutomation', 'MSTest.TestFramework') } + 'uwp' { @('MSTest.Uwp', 'MSTest.TestFramework', 'MSTestAdapter.PlatformServices', 'MSTest.TestAdapter') } + 'winui' { @('MSTest.WinUI', 'MSTest.TestFramework', 'MSTestAdapter.PlatformServices', 'MSTest.TestAdapter') } + } + $actualAssemblies = @($report.SourceAssemblies.Name) + if ($actualAssemblies.Count -ne $expectedAssemblies.Count -or + (Compare-Object ($expectedAssemblies | Sort-Object -CaseSensitive) ($actualAssemblies | Sort-Object -CaseSensitive) -CaseSensitive)) { + throw "Unexpected source assembly identities for $($probe.Name)." + } if (@($report.SourceAssemblies | Where-Object PublicKeyToken -CNE 'b03f5f7f11d50a3a').Count -ne 0) { throw "Source assembly public-signing identity mismatch for $($probe.Name)." } @@ -147,15 +155,26 @@ try { } $windowsAssemblies = @($report.SourceAssemblies | Where-Object { $_.Name -in @('Microsoft.Testing.Extensions.PackagedApp', 'MSTest.Windows.UIAutomation') -or - ($probe.Scenario -in @('uwp', 'winui') -and $_.Name -in @('MSTest.TestFramework', 'MSTest.TestFramework.Extensions', 'MSTestAdapter.PlatformServices', 'MSTest.TestAdapter')) + ($probe.Scenario -in @('uwp', 'winui') -and $_.Name -in @('MSTest.Uwp', 'MSTest.WinUI', 'MSTestAdapter.PlatformServices', 'MSTest.TestAdapter')) }) foreach ($assembly in $windowsAssemblies) { - $minimum = if ($probe.Scenario -eq 'winui' -and $assembly.Name -in @('MSTest.TestFramework', 'MSTest.TestFramework.Extensions')) { '10.0.17763.0' } else { $probe.Platform } + $minimum = if ($assembly.Name -eq 'MSTest.WinUI') { '10.0.17763.0' } else { $probe.Platform } if ($assembly.Framework -cne ".NETCoreApp,Version=v$($probe.Major).0" -or $assembly.Platform -cne "Windows$($probe.Platform)" -or $assembly.SupportedOS -cne "windows$minimum") { throw "Windows TFM/minimum metadata mismatch in $($assembly.Name)." } } + foreach ($core in @($report.SourceAssemblies | Where-Object Name -CEQ 'MSTest.TestFramework')) { + $expectedCoreFramework = ".NETCoreApp,Version=v$($probe.Major).0" + # Portable native cores historically omit this attribute; Windows metadata is never valid here. + if (($core.Framework -and $core.Framework -cne $expectedCoreFramework) -or $core.Platform -or $core.SupportedOS) { + throw 'A UI-specific core was selected instead of the ordinary shared core.' + } + if ($coreHashes.ContainsKey($expectedCoreFramework) -and $coreHashes[$expectedCoreFramework] -cne $core.Sha256) { + throw 'Desktop and UI consumers did not load the same native core payload.' + } + $coreHashes[$expectedCoreFramework] = $core.Sha256 + } if ($probe.Scenario -eq 'packaged' -and (Test-Path -LiteralPath (Join-Path $layout 'Microsoft.Windows.UI.Xaml.dll'))) { throw 'The ordinary WinRT profile leaked the UWP XAML projection.' } @@ -167,7 +186,7 @@ try { if ($LASTEXITCODE -ne 0) { throw 'Could not inspect the Windows producer action graph.' } $graph = Get-Content -LiteralPath $graphPath -Raw | ConvertFrom-Json $compilerCount = @($graph.actions | Where-Object mnemonic -eq 'CSharpCompile').Count - if ($compilerCount -lt 16) { throw 'The Windows library matrix is missing compiler actions.' } + if ($compilerCount -eq 0) { throw 'The Windows library matrix has no native compiler actions.' } foreach ($action in $graph.actions) { foreach ($argument in $action.arguments) { if ($argument -match '(?i)(^|[\s/\\])(MSBuild(\.exe|\.dll)?|dotnet(\.exe)?\s+(build|test|msbuild))(\s|$)') { @@ -176,7 +195,7 @@ try { } } $succeeded = $true - Write-Host "Native Windows libraries and seven consumers passed. No app registration or XAML compilation was exercised. Evidence: $directory" + Write-Host "Native Windows libraries and $($probes.Count) consumers passed. No app registration or XAML compilation was exercised. Evidence: $directory" } finally { [pscustomobject]@{ diff --git a/eng/mutation-testing/modules.json b/eng/mutation-testing/modules.json index 9d2e231297..bf22e1f77a 100644 --- a/eng/mutation-testing/modules.json +++ b/eng/mutation-testing/modules.json @@ -1,6 +1,6 @@ { "schemaVersion": 1, - "knownTargetCount": 41, + "knownTargetCount": 42, "excludedProjects": [ { "project": "src/Platform/Microsoft.Testing.Extensions.PackagedApp.Controller/Microsoft.Testing.Extensions.PackagedApp.Controller.csproj", @@ -33,6 +33,14 @@ { "project": "src/TestFramework/TestFramework.Windows.UIAutomation/TestFramework.Windows.UIAutomation.csproj", "reason": "Windows desktop UI Automation project requiring the WPF framework; it cannot execute in the Ubuntu/net10.0 mutation shards." + }, + { + "project": "src/TestFramework/MSTest.Uwp/MSTest.Uwp.csproj", + "reason": "UWP UI library requiring Windows application-model tooling; its classic and modern package consumers execute in the Windows app-model acceptance job, not Ubuntu/net10.0 mutation shards." + }, + { + "project": "src/TestFramework/MSTest.WinUI/MSTest.WinUI.csproj", + "reason": "WinUI UI library requiring the Windows App SDK; its packaged and unpackaged consumers execute in Windows acceptance tests, not Ubuntu/net10.0 mutation shards." } ], "modules": [ @@ -379,17 +387,6 @@ "enabled": true, "legacyReport": false }, - { - "id": "test-framework-extensions", - "displayName": "MSTest.TestFramework.Extensions", - "project": "src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj", - "testProjects": [ - "test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csproj" - ], - "timeoutMinutes": 360, - "enabled": true, - "legacyReport": false - }, { "id": "adapter-platform-services", "displayName": "MSTestAdapter.PlatformServices", diff --git a/eng/verify-nupkgs.ps1 b/eng/verify-nupkgs.ps1 index 4aa2213653..d81358a901 100644 --- a/eng/verify-nupkgs.ps1 +++ b/eng/verify-nupkgs.ps1 @@ -20,8 +20,10 @@ function Confirm-NugetPackages { Write-Verbose "Starting Confirm-NugetPackages." $expectedNumOfFiles = @{ "MSTest.Sdk" = 16 - "MSTest.TestFramework" = 135 - "MSTest.TestAdapter" = 66 + "MSTest.TestFramework" = 67 + "MSTest.Uwp" = 73 + "MSTest.WinUI" = 53 + "MSTest.TestAdapter" = 54 "MSTest.Extensions.Hosting" = 57 "MSTest" = 10 "MSTest.Analyzers" = 56 diff --git a/samples/public/ClassicUwpMtpApp/ClassicUwpMtpApp.csproj b/samples/public/ClassicUwpMtpApp/ClassicUwpMtpApp.csproj index cea4d2c15e..93b6fff03a 100644 --- a/samples/public/ClassicUwpMtpApp/ClassicUwpMtpApp.csproj +++ b/samples/public/ClassicUwpMtpApp/ClassicUwpMtpApp.csproj @@ -42,11 +42,11 @@ - - diff --git a/samples/public/UwpVSTestApp/UwpVSTestApp.csproj b/samples/public/UwpVSTestApp/UwpVSTestApp.csproj index 553e066417..8a8d85bbd4 100644 --- a/samples/public/UwpVSTestApp/UwpVSTestApp.csproj +++ b/samples/public/UwpVSTestApp/UwpVSTestApp.csproj @@ -32,8 +32,7 @@ - - + diff --git a/samples/public/WinUIVSTestApp/WinUIVSTestApp.csproj b/samples/public/WinUIVSTestApp/WinUIVSTestApp.csproj index 4751fd830c..4e0f4b36a9 100644 --- a/samples/public/WinUIVSTestApp/WinUIVSTestApp.csproj +++ b/samples/public/WinUIVSTestApp/WinUIVSTestApp.csproj @@ -50,8 +50,7 @@ - - + - + diff --git a/src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj b/src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj index 4c32f71781..11012f8c26 100644 --- a/src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj +++ b/src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj @@ -28,14 +28,11 @@ false MSTest.TestAdapter $(CommonPackageTags) MSTest TestFramework TestAdapter VisualStudio MSTestV2 - @@ -70,46 +67,21 @@ $(CommonProductDescription)]]> dependency: PrivateAssets="all" suppresses the dependency (and its transitive package dependencies). --> - - - - - none - - - - - none - - - - + + + + - - - - - - - - @@ -169,15 +141,10 @@ $(CommonProductDescription)]]> - - - - - @@ -211,7 +176,6 @@ $(CommonProductDescription)]]> - @@ -219,6 +183,42 @@ $(CommonProductDescription)]]> + + + + <_MSTestAdapterBuildFlavor Include="@(_SdkProjectFlavorMatrixItem)" /> + <_SdkProjectFlavorMatrixItem Remove="@(_SdkProjectFlavorMatrixItem)" + Condition=" '%(_SdkProjectFlavorMatrixItem.TargetFramework)' == '$(UwpMinimum)' + OR '%(_SdkProjectFlavorMatrixItem.TargetFramework)' == '$(ModernUwpMinimum)' + OR '%(_SdkProjectFlavorMatrixItem.TargetFramework)' == '$(WinUiMinimum)' " /> + <_FrameworksWithSuppressedDependencies Include="$(UwpMinimum);$(ModernUwpMinimum);$(WinUiMinimum)" /> + + + + + + + <_MSTestAdapterBuildFrameworks>$(TargetFrameworks) + $(SupportedNetFrameworks) + $(NetFrameworkMinimum);$(TargetFrameworks) + + + + + + $(_MSTestAdapterBuildFrameworks) + + + <_SdkProjectFlavorMatrixItem Remove="@(_SdkProjectFlavorMatrixItem)" /> + <_SdkProjectFlavorMatrixItem Include="@(_MSTestAdapterBuildFlavor)" /> + + + PreserveNewest diff --git a/src/Adapter/MSTest.TestAdapter/PACKAGE.md b/src/Adapter/MSTest.TestAdapter/PACKAGE.md index 6bafa986c6..7e9a28aaed 100644 --- a/src/Adapter/MSTest.TestAdapter/PACKAGE.md +++ b/src/Adapter/MSTest.TestAdapter/PACKAGE.md @@ -24,17 +24,12 @@ Supported platforms: - .NET 4.6.2+ - .NET 10.0+ -- .NET 10.0 Windows.18362+ (WinUI) -- UWP 10.0.16299 -- UWP 10.0.17763 with .NET 10+ -## Classic UWP dependencies - -The classic UWP adapter payload contains the adapter and its platform-services -assembly. Microsoft.Testing.Platform and its extensions are restored from their -own NuGet packages rather than duplicated inside this package. The classic UWP -bootstrap also depends on the TRX reporting and Retry packages. The adapter's -build targets include the resolved runtime assemblies in the AppX deployment. +Use `MSTest.Uwp` for classic or modern UWP applications and `MSTest.WinUI` for +packaged or unpackaged WinUI applications. Those packages own their matching +UI attributes, adapters, platform services and satellites. This ordinary adapter +no longer switches assemblies based on `UseWinUI` or `UseUwpTools`; do not +combine it with either UI package. ## F# modules diff --git a/src/Adapter/MSTest.TestAdapter/PackageDependencies.props b/src/Adapter/MSTest.TestAdapter/PackageDependencies.props new file mode 100644 index 0000000000..ff3e824f6e --- /dev/null +++ b/src/Adapter/MSTest.TestAdapter/PackageDependencies.props @@ -0,0 +1,18 @@ + + + + + + + + none + + + none + + + + + + + diff --git a/src/Adapter/MSTest.TestAdapter/build/uap10.0/MSTest.TestAdapter.props b/src/Adapter/MSTest.TestAdapter/build/uap10.0/MSTest.TestAdapter.props deleted file mode 100644 index f15322b9ac..0000000000 --- a/src/Adapter/MSTest.TestAdapter/build/uap10.0/MSTest.TestAdapter.props +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/Adapter/MSTest.TestAdapter/build/uap10.0/MSTest.TestAdapter.targets b/src/Adapter/MSTest.TestAdapter/build/uap10.0/MSTest.TestAdapter.targets deleted file mode 100644 index 699a1cdcd9..0000000000 --- a/src/Adapter/MSTest.TestAdapter/build/uap10.0/MSTest.TestAdapter.targets +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/Adapter/MSTest.TestAdapter/buildTransitive/common/MSTest.TestAdapter.props b/src/Adapter/MSTest.TestAdapter/buildTransitive/common/MSTest.TestAdapter.props index 1e14ef753e..67f3987bad 100644 --- a/src/Adapter/MSTest.TestAdapter/buildTransitive/common/MSTest.TestAdapter.props +++ b/src/Adapter/MSTest.TestAdapter/buildTransitive/common/MSTest.TestAdapter.props @@ -3,18 +3,7 @@ true true + <_MSTestOrdinaryAdapterReferenced>true - - - - MSTest - Microsoft.VisualStudio.TestTools.UnitTesting.TestingPlatformBuilderHook - - - diff --git a/src/Adapter/MSTest.TestAdapter/buildTransitive/common/MSTest.TestAdapter.targets b/src/Adapter/MSTest.TestAdapter/buildTransitive/common/MSTest.TestAdapter.targets index 300f3a050a..0dab08588c 100644 --- a/src/Adapter/MSTest.TestAdapter/buildTransitive/common/MSTest.TestAdapter.targets +++ b/src/Adapter/MSTest.TestAdapter/buildTransitive/common/MSTest.TestAdapter.targets @@ -14,26 +14,39 @@ false - - <_TestAdapterPlatformServicesRoot>$(MSBuildThisFileDirectory)../net10.0/winui/ - - - - <_TestAdapterPlatformServicesRoot>$(MSBuildThisFileDirectory)../net10.0/uwp/ - - - <_TestAdapterPlatformServicesRoot>$(MSBuildThisFileDirectory) + + <_MSTestAdapterPayloadRoot Condition=" '$(_MSTestAdapterPayloadRoot)' == '' ">$(MSBuildThisFileDirectory) + <_MSTestAdapterLocalizationRoot Condition=" '$(_MSTestAdapterLocalizationRoot)' == '' ">$(MSBuildThisFileDirectory)..\_localization\ + + + + + + + + + + + MSTest + Microsoft.VisualStudio.TestTools.UnitTesting.TestingPlatformBuilderHook + + + - $(_TestAdapterPlatformServicesRoot)MSTest.TestAdapter.dll + $(_MSTestAdapterPayloadRoot)MSTest.TestAdapter.dll + false - $(_TestAdapterPlatformServicesRoot)MSTestAdapter.PlatformServices.dll + $(_MSTestAdapterPayloadRoot)MSTestAdapter.PlatformServices.dll + false @@ -73,7 +86,7 @@ --> <_MSTestSatelliteResourceLanguages Include="$(SatelliteResourceLanguages)" /> - <_MSTestV2Files Include="$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\_localization'))\**\*.dll" /> + <_MSTestV2Files Include="$(_MSTestAdapterLocalizationRoot)**\*.dll" /> <_MSTestV2Files Update="@(_MSTestV2Files)"> @@ -105,7 +118,7 @@ Inputs/Outputs of CopyMSTestV2Resources are evaluated for incremental build. --> - <_MSTestV2Files Include="$(MSBuildThisFileDirectory)..\_localization\%(CurrentUICultureHierarchy.Identity)\*.dll"> + <_MSTestV2Files Include="$(_MSTestAdapterLocalizationRoot)%(CurrentUICultureHierarchy.Identity)\*.dll"> %(CurrentUICultureHierarchy.Identity)\ $([System.String]::Copy('%(CurrentUICultureHierarchy.Identity)').ToLowerInvariant()) diff --git a/src/Adapter/MSTest.TestAdapter/buildTransitive/uwp/MSTest.TestAdapter.props b/src/Adapter/MSTest.TestAdapter/buildTransitive/uwp/MSTest.TestAdapter.props deleted file mode 100644 index 1e14ef753e..0000000000 --- a/src/Adapter/MSTest.TestAdapter/buildTransitive/uwp/MSTest.TestAdapter.props +++ /dev/null @@ -1,20 +0,0 @@ - - - - true - true - - - - - - MSTest - Microsoft.VisualStudio.TestTools.UnitTesting.TestingPlatformBuilderHook - - - - diff --git a/src/Adapter/MSTest.TestAdapter/buildTransitive/uwp/MSTest.TestAdapter.targets b/src/Adapter/MSTest.TestAdapter/buildTransitive/uwp/MSTest.TestAdapter.targets index 5c96cf2b87..ae97ebd909 100644 --- a/src/Adapter/MSTest.TestAdapter/buildTransitive/uwp/MSTest.TestAdapter.targets +++ b/src/Adapter/MSTest.TestAdapter/buildTransitive/uwp/MSTest.TestAdapter.targets @@ -10,13 +10,28 @@ - $(MSBuildThisFileDirectory)MSTest.TestAdapter.dll + $(_MSTestAdapterPayloadRoot)MSTest.TestAdapter.dll + false - $(MSBuildThisFileDirectory)MSTestAdapter.PlatformServices.dll + $(_MSTestAdapterPayloadRoot)MSTestAdapter.PlatformServices.dll + false + + + + MSTest + Microsoft.VisualStudio.TestTools.UnitTesting.TestingPlatformBuilderHook + + + + + + + @@ -60,7 +75,7 @@ Every requested localized satellite must be copied to the output directory so any selected culture can be resolved at run time. --> - <_MSTestV2Files Include="$([System.IO.Path]::GetFullPath('$(MSBuildThisFileDirectory)..\_localization'))\**\*.dll" /> + <_MSTestV2Files Include="$(_MSTestAdapterLocalizationRoot)**\*.dll" /> <_MSTestV2Files Update="@(_MSTestV2Files)"> @@ -92,7 +107,7 @@ Inputs/Outputs of CopyMSTestV2Resources are evaluated for incremental build. --> - <_MSTestV2Files Include="$(MSBuildThisFileDirectory)..\_localization\%(CurrentUICultureHierarchy.Identity)\*.dll"> + <_MSTestV2Files Include="$(_MSTestAdapterLocalizationRoot)%(CurrentUICultureHierarchy.Identity)\*.dll"> %(CurrentUICultureHierarchy.Identity) $([System.String]::Copy('%(CurrentUICultureHierarchy.Identity)').ToLowerInvariant()) diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodRunner.cs b/src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodRunner.cs index f819eb57fd..322123a6c9 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodRunner.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Execution/TestMethodRunner.cs @@ -314,6 +314,24 @@ internal async Task RunTestMethodAsync() throw ApplicationStateGuard.Unreachable(); } +#if (WINDOWS_UWP || WIN_UI) && NET + IReflectionOperations reflection = PlatformServiceProvider.Instance.ReflectionOperations; + if (reflection.IsAttributeDefined(_testMethodInfo.MethodInfo) + || reflection.IsAttributeDefined(_testMethodInfo.Parent.ClassType)) + { + _testContext.SetOutcome(UnitTestOutcome.Failed); + return + [ + new TestResult + { + Outcome = UnitTestOutcome.Failed, + DisplayName = _test.DisplayName, + TestFailureException = new TestFailedException(UnitTestOutcome.Failed, Resource.DeploymentItemNotSupportedForUi), + }, + ]; + } +#endif + // Fast path for non-data-driven tests (the common case). // A single attribute scan replaces the two scans done by TryExecuteDataSourceBasedTestsAsync and // TryExecuteFoldedDataDrivenTestsAsync, and avoids allocating a List that would diff --git a/src/Adapter/MSTestAdapter.PlatformServices/InternalAPI/InternalAPI.Unshipped.txt b/src/Adapter/MSTestAdapter.PlatformServices/InternalAPI/InternalAPI.Unshipped.txt index 8971e71f46..f436607902 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/InternalAPI/InternalAPI.Unshipped.txt +++ b/src/Adapter/MSTestAdapter.PlatformServices/InternalAPI/InternalAPI.Unshipped.txt @@ -1,4 +1,12 @@ #nullable enable +Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.AppContainer.AppModel +static Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.AppContainer.AppModel.GetCurrentPackagePath() -> string? +static Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.AppContainer.AppModel.IsPackagedProcess() -> bool +override Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation.TestRunDirectory.get -> string? +override Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation.DeploymentDirectory.get -> string? +override Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation.ResultsDirectory.get -> string? +override Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation.TestRunResultsDirectory.get -> string? +override Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation.TestResultsDirectory.get -> string? Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.Execution.TestDependencyDeclaration.TryResolveClassDependency(System.Collections.Generic.IReadOnlyDictionary!>! methodsByClass, out string? dependentClassName, out string? prerequisiteClassName) -> bool Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.TestPartition Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.TestPartition.Count.get -> int diff --git a/src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj b/src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj index c985b6d70d..0681bd4344 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj +++ b/src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj @@ -38,7 +38,7 @@ - + diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/Resource.resx b/src/Adapter/MSTestAdapter.PlatformServices/Resources/Resource.resx index f36bcb8990..fa3c9d3a84 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/Resource.resx +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/Resource.resx @@ -129,6 +129,10 @@ Test Run deployment issue: Bad deployment item: '{0}': output directory '{1}' specifies the item to be deployed outside deployment root directory which is not allowed. {0} is the deployment item path. {1} is the output directory. + + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + Do not localize the API name {Locked="DeploymentItemAttribute"} or the application-model names {Locked="UWP"}{Locked="WinUI"}. + Test Run deployment issue: Failed to access output directory '{1}' specified by deployment item '{0}', the item will not be deployed: {2}: {3} {0} is the deployment item path. {1} is the output directory. {2} is the exception type. {3} is the exception message. diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.cs.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.cs.xlf index 57b68d1a24..db1894cab0 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.cs.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.cs.xlf @@ -196,6 +196,11 @@ byl však přijat tento počet argumentů: {4} s typy {5}. Neplatná položka nasazení: Zadaná cesta {0} nebo adresář výstupu {1} obsahuje neplatné znaky. {0} is the deployment item path. {1} is the output directory. + + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + Do not localize the API name {Locked="DeploymentItemAttribute"} or the application-model names {Locked="UWP"}{Locked="WinUI"}. + Invalid deployment item: the output directory cannot be null. Neplatná položka nasazení: Adresář výstupu nemůže být null. diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.de.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.de.xlf index f2014df56d..bdc9a44fd6 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.de.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.de.xlf @@ -196,6 +196,11 @@ aber empfing {4} Argument(e) mit den Typen „{5}“. Ungültiges Bereitstellungselement: Der angegebene Pfad "{0}" oder das angegebene Ausgabeverzeichnis "{1}" enthält unzulässige Zeichen. {0} is the deployment item path. {1} is the output directory. + + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + Do not localize the API name {Locked="DeploymentItemAttribute"} or the application-model names {Locked="UWP"}{Locked="WinUI"}. + Invalid deployment item: the output directory cannot be null. Ungültiges Bereitstellungselement: Das Ausgabeverzeichnis darf nicht null sein. diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.es.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.es.xlf index 338d2532bc..9b0a5d3682 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.es.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.es.xlf @@ -196,6 +196,11 @@ pero recibió {4} argumentos, con los tipos '{5}'. Elemento de implementación no válido: la ruta de acceso '{0}' o el directorio de salida '{1}' especificados contienen caracteres no válidos. {0} is the deployment item path. {1} is the output directory. + + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + Do not localize the API name {Locked="DeploymentItemAttribute"} or the application-model names {Locked="UWP"}{Locked="WinUI"}. + Invalid deployment item: the output directory cannot be null. Elemento de implementación no válido: el directorio de salida no puede ser un valor null. diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.fr.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.fr.xlf index f0180e25b0..1c8e016d4c 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.fr.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.fr.xlf @@ -196,6 +196,11 @@ mais a reçu {4} argument(s), avec les types « {5} ». Élément de déploiement non valide : le chemin '{0}' ou le répertoire de sortie '{1}' spécifié contient des caractères non conformes. {0} is the deployment item path. {1} is the output directory. + + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + Do not localize the API name {Locked="DeploymentItemAttribute"} or the application-model names {Locked="UWP"}{Locked="WinUI"}. + Invalid deployment item: the output directory cannot be null. Élément de déploiement non valide : le répertoire de sortie ne peut pas être null. diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.it.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.it.xlf index 8bbc8cd636..d1cfa71b21 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.it.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.it.xlf @@ -196,6 +196,11 @@ ma ha ricevuto {4} argomenti, con tipi '{5}'. Elemento di distribuzione non valido: la directory di output '{1}' o il percorso specificato '{0}' contiene caratteri non validi. {0} is the deployment item path. {1} is the output directory. + + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + Do not localize the API name {Locked="DeploymentItemAttribute"} or the application-model names {Locked="UWP"}{Locked="WinUI"}. + Invalid deployment item: the output directory cannot be null. Elemento della distribuzione non valido: la directory di output non può essere null. diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ja.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ja.xlf index 2e2f1043d0..2ceee589a8 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ja.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ja.xlf @@ -196,6 +196,11 @@ but received {4} argument(s), with types '{5}'. 無効な配置項目です: 指定されたパス '{0}' または出力ディレクトリ '{1}' に使用できない文字が含まれています。 {0} is the deployment item path. {1} is the output directory. + + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + Do not localize the API name {Locked="DeploymentItemAttribute"} or the application-model names {Locked="UWP"}{Locked="WinUI"}. + Invalid deployment item: the output directory cannot be null. 無効な配置項目です: 出力ディレクトリを null にすることはできません。 diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ko.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ko.xlf index e609cf3959..3cdeb8db93 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ko.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ko.xlf @@ -196,6 +196,11 @@ but received {4} argument(s), with types '{5}'. 잘못된 배포 항목: 지정된 경로 '{0}' 또는 출력 디렉터리 '{1}'에 잘못된 문자가 들어 있습니다. {0} is the deployment item path. {1} is the output directory. + + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + Do not localize the API name {Locked="DeploymentItemAttribute"} or the application-model names {Locked="UWP"}{Locked="WinUI"}. + Invalid deployment item: the output directory cannot be null. 잘못된 배포 항목: 출력 디렉터리는 null일 수 없습니다. diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pl.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pl.xlf index 883ffac3f0..2ef7f9de80 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pl.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pl.xlf @@ -196,6 +196,11 @@ ale odebrał argumenty {4} z typami „{5}”. Nieprawidłowy element wdrożenia: wybrana ścieżka „{0}” lub katalog wyjściowy „{1}” zawiera niedozwolone znaki. {0} is the deployment item path. {1} is the output directory. + + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + Do not localize the API name {Locked="DeploymentItemAttribute"} or the application-model names {Locked="UWP"}{Locked="WinUI"}. + Invalid deployment item: the output directory cannot be null. Nieprawidłowy element wdrożenia: katalog wyjściowy nie może mieć wartości null. diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pt-BR.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pt-BR.xlf index 918269c3ea..1599df9f23 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pt-BR.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.pt-BR.xlf @@ -196,6 +196,11 @@ mas {4} argumentos recebidos, com tipos '{5}'. Item de implantação inválido: o caminho especificado '{0}' ou o diretório de saída '{1}' contém caracteres ilegais. {0} is the deployment item path. {1} is the output directory. + + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + Do not localize the API name {Locked="DeploymentItemAttribute"} or the application-model names {Locked="UWP"}{Locked="WinUI"}. + Invalid deployment item: the output directory cannot be null. Item de implantação inválido: o diretório de saída não pode ser null. diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ru.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ru.xlf index 6d8c70d98c..1ed40b480d 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ru.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.ru.xlf @@ -196,6 +196,11 @@ but received {4} argument(s), with types '{5}'. Недопустимый элемент развертывания: указанный путь "{0}" или выходной каталог "{1}" содержат недопустимые символы. {0} is the deployment item path. {1} is the output directory. + + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + Do not localize the API name {Locked="DeploymentItemAttribute"} or the application-model names {Locked="UWP"}{Locked="WinUI"}. + Invalid deployment item: the output directory cannot be null. Недопустимый элемент развертывания: выходной каталог не может быть равен null. diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.tr.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.tr.xlf index d5c8be91cf..3d6cadfe6b 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.tr.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.tr.xlf @@ -196,6 +196,11 @@ ancak, '{5}' türünde {4} bağımsız değişken aldı. Geçersiz dağıtım öğesi: Belirtilen '{0}' yolu veya '{1}' çıktı dizini geçersiz karakterler içeriyor. {0} is the deployment item path. {1} is the output directory. + + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + Do not localize the API name {Locked="DeploymentItemAttribute"} or the application-model names {Locked="UWP"}{Locked="WinUI"}. + Invalid deployment item: the output directory cannot be null. Geçersiz dağıtım öğesi: Çıktı dizini null olamaz. diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hans.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hans.xlf index ce8dffc40d..b259771449 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hans.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hans.xlf @@ -196,6 +196,11 @@ but received {4} argument(s), with types '{5}'. 无效的部署项: 指定的路径“{0}”或输出目录“{1}”包含非法字符。 {0} is the deployment item path. {1} is the output directory. + + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + Do not localize the API name {Locked="DeploymentItemAttribute"} or the application-model names {Locked="UWP"}{Locked="WinUI"}. + Invalid deployment item: the output directory cannot be null. 部署项无效: 输出目录不能为 null。 diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hant.xlf b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hant.xlf index e89ba37e93..e32823526a 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hant.xlf +++ b/src/Adapter/MSTestAdapter.PlatformServices/Resources/xlf/Resource.zh-Hant.xlf @@ -196,6 +196,11 @@ but received {4} argument(s), with types '{5}'. 部署項目無效: 指定的路徑 '{0}' 或輸出目錄 '{1}' 含有非法字元。 {0} is the deployment item path. {1} is the output directory. + + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + DeploymentItemAttribute is not supported by UWP or WinUI test hosts. Remove the attribute and include required files in the application package. + Do not localize the API name {Locked="DeploymentItemAttribute"} or the application-model names {Locked="UWP"}{Locked="WinUI"}. + Invalid deployment item: the output directory cannot be null. 部署項目無效: 輸出目錄不可為 null。 diff --git a/src/TestFramework/TestFramework.Extensions/AppModel.cs b/src/Adapter/MSTestAdapter.PlatformServices/Services/AppModel.cs similarity index 100% rename from src/TestFramework/TestFramework.Extensions/AppModel.cs rename to src/Adapter/MSTestAdapter.PlatformServices/Services/AppModel.cs diff --git a/src/Adapter/MSTestAdapter.PlatformServices/Services/TestContextImplementation.Properties.cs b/src/Adapter/MSTestAdapter.PlatformServices/Services/TestContextImplementation.Properties.cs index 5f186cdf12..76b713fbdb 100644 --- a/src/Adapter/MSTestAdapter.PlatformServices/Services/TestContextImplementation.Properties.cs +++ b/src/Adapter/MSTestAdapter.PlatformServices/Services/TestContextImplementation.Properties.cs @@ -26,6 +26,26 @@ internal sealed partial class TestContextImplementation /// public override IDictionary Properties => _properties; +#if WINDOWS_UWP || WIN_UI + /// + public override string? TestRunDirectory => null; + + /// + public override string? DeploymentDirectory => null; + + /// + public override string? ResultsDirectory => null; + + /// + public override string? TestRunResultsDirectory => null; + + /// + public override string? TestResultsDirectory => null; + + /// + public override string? TestTempDirectory => null; +#endif + /// /// Returns whether property with parameter name is present or not. /// diff --git a/src/Package/MSTest.Sdk/PACKAGE.md b/src/Package/MSTest.Sdk/PACKAGE.md index 0cb0ac57e8..361b205525 100644 --- a/src/Package/MSTest.Sdk/PACKAGE.md +++ b/src/Package/MSTest.Sdk/PACKAGE.md @@ -24,6 +24,23 @@ Supported platforms: - UWP 10.0.16299 - UWP 10.0.17763 with .NET 10+ +The SDK uses one shared `MSTest.TestFramework` and selects exactly one adapter +composition: `MSTest.TestAdapter` for ordinary .NET, `MSTest.Uwp` for classic or +modern UWP, or `MSTest.WinUI` for WinUI. The UI packages replace +`MSTest.TestFramework.Extensions`; modern UWP does not use WinUI. + +`MSTestApplicationModel` accepts `Default`, `Uwp`, or `WinUI`. Leave it empty to +infer from the current target framework and UI tooling properties, or set it +explicitly when desktop tooling imports arrive after restore-time package +selection. `UseUwp=true` with `UseUwpTools=false` remains ordinary unless another +model is explicitly selected. Conflicting or unknown models are rejected. +Selection and central package versions are per inner target framework. + +Reusable helpers use `IsTestApplication=false`. Ordinary helpers remain +core-only unless source generation needs runtime hooks; UI helpers use their +matching UI package. Their adapter dependencies stay private and do not copy +application payloads into a referencing project. + For package identity, AUMID activation, unpackaged WinUI, UWP launch activation, UI dispatchers, and AppContainer security guidance, see [Testing UWP and WinUI apps with MSTest](https://github.com/microsoft/testfx/blob/main/docs/winui-testing.md). @@ -32,7 +49,7 @@ For packaged Windows applications, the SDK references `Microsoft.Testing.Extensions.PackagedApp.MSBuild` from the aligned MTP release. That separately shipped package owns the full-trust controller, shared launch targets and classic UWP bootstrap; the SDK does not embed a second controller -payload. MSTest metapackage and adapter-only projects can reference the same +payload. Direct `MSTest.Uwp` and `MSTest.WinUI` consumers can reference the same integration explicitly with `EnableMSTestRunner=true`. ## Documentation diff --git a/src/Package/MSTest.Sdk/README.md b/src/Package/MSTest.Sdk/README.md index 123133fb84..99ab30ca63 100644 --- a/src/Package/MSTest.Sdk/README.md +++ b/src/Package/MSTest.Sdk/README.md @@ -20,15 +20,36 @@ Specify the SDK version in the `Sdk` attribute (`MSTest.Sdk/x.y.z`) or through t | --- | --- | | Default | ClassicEngine: self-contained MSTest runner built on Microsoft.Testing.Platform | | `true` | NativeAOT MSTest runner | -| `true` | VSTest with `Microsoft.NET.Test.Sdk` and `MSTest.TestAdapter` | +| `true` | VSTest with `Microsoft.NET.Test.Sdk` and the selected adapter composition | `UseVSTest=true` takes precedence over `PublishAot`. Set `false` to create a reusable test library instead of an executable test application. ## Windows application models -MSTest.Sdk uses Microsoft.Testing.Platform by default for unpackaged WinUI, packaged full-trust WinUI, AppContainer-configured WinUI, modern UWP (`UseUwpTools=true`), and classic `uap10.0` projects. For packaged applications it references `Microsoft.Testing.Extensions.PackagedApp.MSBuild`, which supplies the full-trust app-model controller and shared launch targets. That controller registers the package and activates the exact manifest application by AUMID while retaining MTP-owned cancellation, reports, retries, and exit-code handling. The SDK itself does not duplicate the tool payload. The integration package ships in the aligned MTP release and can also be referenced explicitly by MSTest metapackage or adapter-only consumers. +MSTest.Sdk uses Microsoft.Testing.Platform by default for unpackaged WinUI, packaged full-trust WinUI, AppContainer-configured WinUI, modern UWP (`UseUwpTools=true`), and classic `uap10.0` projects. All compositions share `MSTest.TestFramework`; UI APIs are supplied by the explicit `MSTest.Uwp` and `MSTest.WinUI` packages, not `MSTest.TestFramework.Extensions`. -`UseUwp=true` adds UWP XAML references. The desktop Visual Studio UWP targets enable `UseUwpTools` after MSTest.Sdk declares its package references and before the packages select their specialized UWP assemblies. MSTest.Sdk preserves the UWP application model during that earlier evaluation when `UseUwp=true` and `UseUwpTools` is still unset. Set `UseUwpTools=false` explicitly to use the references without UWP package activation; this selects the ordinary MSTest assemblies and direct MTP runner unless another packaged application model is configured. +| Application model | Adapter/UI package selected by the SDK | +| --- | --- | +| Ordinary .NET | `MSTest.TestAdapter` | +| Classic or modern UWP | `MSTest.Uwp` | +| WinUI | `MSTest.WinUI` | + +Set `MSTestApplicationModel` to `Default`, `Uwp`, or `WinUI` to select a composition explicitly. An empty value infers the model from `UseWinUI=true`, `UseUwpTools=true`, `UseUwp=true` while `UseUwpTools` is unset, or a classic `uap` target framework; otherwise it selects `Default`. The explicit property controls package ownership before late desktop tooling imports, but does not enable or override that tooling. Unknown values and conflicting models fail with an MSBuild error. Modern UWP never selects WinUI. + +`UseUwp=true` adds UWP XAML references. The desktop Visual Studio UWP targets can enable `UseUwpTools` after MSTest.Sdk declares its package references. MSTest.Sdk preserves the UWP composition during that earlier evaluation when `UseUwp=true` and `UseUwpTools` is still unset. Set `UseUwpTools=false` explicitly to use the references without UWP package activation; this selects the ordinary composition and direct MTP runner unless another application model is explicitly selected. + +Selection applies to ClassicEngine, NativeAOT, and VSTest, including their source-generation hooks. Central package management receives a `PackageVersion` for the selected package, without requiring `VersionOverride`. Multi-targeted projects select independently for each inner framework. For example, a project whose UWP tooling imports are late can declare its package composition as follows: + +```xml + + net11.0;net11.0-windows10.0.26100.0 + Uwp + +``` + +Ordinary reusable helpers (`IsTestApplication=false`) reference only `MSTest.TestFramework` unless source generation requires adapter runtime hooks. UI helpers reference their matching UI package. Helper adapter references are private, do not register an application builder hook, and do not copy adapter payloads or satellites into the consuming application; the application supplies its own selected runtime composition. An ordinary source-generated helper can therefore be referenced by a UWP or WinUI test application without introducing `MSTest.TestAdapter` transitively. + +For packaged applications the SDK references `Microsoft.Testing.Extensions.PackagedApp.MSBuild`, which supplies the full-trust app-model controller and shared launch targets. That controller registers the package and activates the exact manifest application by AUMID while retaining MTP-owned cancellation, reports, retries, and exit-code handling. The SDK itself does not duplicate the tool payload. The integration package ships in the aligned MTP release and can also be referenced explicitly by consumers of `MSTest.Uwp` or `MSTest.WinUI`. Unsigned build-output layouts require Windows Developer Mode or sideloading. UWP builds still require the Visual Studio UWP/MSBuild workload, but they do not require `Microsoft.NET.Test.Sdk`, `vstest.console`, or the Visual Studio UWP test-host runtime provider. See [Testing UWP and WinUI apps with MSTest](../../../docs/winui-testing.md). diff --git a/src/Package/MSTest.Sdk/Sdk/Runner/ClassicEngine.targets b/src/Package/MSTest.Sdk/Sdk/Runner/ClassicEngine.targets index 7bcddec8e9..55da144460 100644 --- a/src/Package/MSTest.Sdk/Sdk/Runner/ClassicEngine.targets +++ b/src/Package/MSTest.Sdk/Sdk/Runner/ClassicEngine.targets @@ -85,10 +85,10 @@ - + $(MSTestVersion) - diff --git a/src/Package/MSTest.Sdk/Sdk/Runner/Common.targets b/src/Package/MSTest.Sdk/Sdk/Runner/Common.targets index 6af291998b..546809673e 100644 --- a/src/Package/MSTest.Sdk/Sdk/Runner/Common.targets +++ b/src/Package/MSTest.Sdk/Sdk/Runner/Common.targets @@ -8,8 +8,8 @@ - Exe - Exe + Exe + Exe <_SdkMajorVersion>$(NETCoreSdkVersion.Split('.')[0]) <_SupportsGlobalJsonTestRunner Condition="'$(NETCoreSdkVersion)' != '' AND '$(_SdkMajorVersion)' >= '10'">true true @@ -17,7 +17,7 @@ + Condition=" '$(IsTestApplication)' == 'true' AND ('$(_MSTestWinUIApplicationModel)' == 'true' OR '$(_MSTestUwpApplicationModel)' == 'true' OR '$(UseUwp)' == 'true') AND '@(ApplicationDefinition)' != '' "> false @@ -39,9 +39,9 @@ $(MicrosoftTestingExtensionsCommonVersion) true + Condition=" '$(EnableMicrosoftTestingExtensionsPackagedApp)' == '' AND '$(IsTestApplication)' == 'true' AND '$(_MSTestWinUIApplicationModel)' == 'true' AND '$(WindowsPackageType)' != 'None' ">true true + Condition=" '$(EnableMicrosoftTestingExtensionsPackagedApp)' == '' AND '$(IsTestApplication)' == 'true' AND '$(_MSTestUwpApplicationModel)' == 'true' ">true false diff --git a/src/Package/MSTest.Sdk/Sdk/Runner/NativeAOT.targets b/src/Package/MSTest.Sdk/Sdk/Runner/NativeAOT.targets index 004342fad9..493fbce4b6 100644 --- a/src/Package/MSTest.Sdk/Sdk/Runner/NativeAOT.targets +++ b/src/Package/MSTest.Sdk/Sdk/Runner/NativeAOT.targets @@ -68,14 +68,14 @@ Condition=" '$(EnableMicrosoftTestingPlatform)' == 'true' and '$(ManagePackageVersionsCentrally)' == 'true' " /> - + $(MSTestVersion) - diff --git a/src/Package/MSTest.Sdk/Sdk/Sdk.targets b/src/Package/MSTest.Sdk/Sdk/Sdk.targets index b54c53867e..bfef2fd466 100644 --- a/src/Package/MSTest.Sdk/Sdk/Sdk.targets +++ b/src/Package/MSTest.Sdk/Sdk/Sdk.targets @@ -8,11 +8,33 @@ false - <_MSTestUwpApplicationModel Condition=" '$(UseUwpTools)' == 'true' OR ('$(UseUwp)' == 'true' AND '$(UseUwpTools)' == '') ">true + <_MSTestApplicationModel>$(MSTestApplicationModel) + <_MSTestApplicationModel Condition=" '$(_MSTestApplicationModel)' == '' AND '$(UseWinUI)' == 'true' ">WinUI + <_MSTestApplicationModel Condition=" '$(_MSTestApplicationModel)' == '' AND ('$(UseUwpTools)' == 'true' OR ('$(UseUwp)' == 'true' AND '$(UseUwpTools)' == '') OR $(TargetFramework.StartsWith('uap'))) ">Uwp + <_MSTestApplicationModel Condition=" '$(_MSTestApplicationModel)' == '' ">Default + <_MSTestUwpApplicationModel>false + <_MSTestUwpApplicationModel Condition=" '$(_MSTestApplicationModel)' == 'Uwp' ">true + <_MSTestWinUIApplicationModel>false + <_MSTestWinUIApplicationModel Condition=" '$(_MSTestApplicationModel)' == 'WinUI' ">true + <_MSTestAdapterPackageId>MSTest.TestAdapter + <_MSTestAdapterPackageId Condition=" '$(_MSTestApplicationModel)' == 'Uwp' ">MSTest.Uwp + <_MSTestAdapterPackageId Condition=" '$(_MSTestApplicationModel)' == 'WinUI' ">MSTest.WinUI + + <_MSTestSdkHelperNeedsAdapter>false + <_MSTestSdkHelperNeedsAdapter + Condition=" '$(IsTestApplication)' != 'true' + AND ('$(_MSTestApplicationModel)' == 'Uwp' OR '$(_MSTestApplicationModel)' == 'WinUI' + OR ('$([MSBuild]::GetTargetFrameworkIdentifier($(TargetFramework)))' != '.NETStandard' + AND ('$(EnableMSTestSourceGeneration)' == 'true' + OR ('$(UseVSTest)' == 'false' AND '$(PublishAot)' == 'true')))) ">true + + false @@ -21,9 +43,19 @@ - - + + + + + - - - + + + $(MSTestVersion) + all + runtime - diff --git a/src/Package/MSTest.Sdk/Sdk/VSTest/VSTest.targets b/src/Package/MSTest.Sdk/Sdk/VSTest/VSTest.targets index f5bb75fdfe..28767a1a47 100644 --- a/src/Package/MSTest.Sdk/Sdk/VSTest/VSTest.targets +++ b/src/Package/MSTest.Sdk/Sdk/VSTest/VSTest.targets @@ -36,10 +36,10 @@ - + $(MSTestVersion) - diff --git a/src/Package/MSTest/MSTest.csproj b/src/Package/MSTest/MSTest.csproj index 4da44ec705..82626a2c20 100644 --- a/src/Package/MSTest/MSTest.csproj +++ b/src/Package/MSTest/MSTest.csproj @@ -29,9 +29,7 @@ Supported platforms: - .NET 4.6.2+ - .NET 10.0+ -- .NET 10.0 Windows.18362+ (WinUI) - UWP 10.0.16299 -- UWP 10.0.17763 with .NET 10+ $(CommonProductDescription)]]> @@ -45,8 +43,9 @@ $(CommonProductDescription)]]> - - + + + diff --git a/src/Package/MSTest/PACKAGE.md b/src/Package/MSTest/PACKAGE.md index 2dd77a1c53..ad1c3068e4 100644 --- a/src/Package/MSTest/PACKAGE.md +++ b/src/Package/MSTest/PACKAGE.md @@ -22,9 +22,13 @@ Supported platforms: - .NET 4.6.2+ - .NET 10.0+ -- .NET 10.0 Windows.18362+ (WinUI) - UWP 10.0.16299 -- UWP 10.0.17763 with .NET 10+ + +Classic UWP selects `MSTest.Uwp` through its UAP dependency group. Modern UWP +and WinUI cannot be distinguished by a Windows TFM alone: reference +`MSTest.Uwp` or `MSTest.WinUI` directly instead of this metapackage, or use +`MSTest.Sdk` with the appropriate application model. Do not combine them with +the ordinary adapter dependency supplied by this metapackage. ## Documentation diff --git a/src/TestFramework/TestFramework.Extensions/InternalAPI/InternalAPI.Shipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/InternalAPI.Shipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/InternalAPI/InternalAPI.Shipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/InternalAPI.Shipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/InternalAPI/InternalAPI.Unshipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/InternalAPI.Unshipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/InternalAPI/InternalAPI.Unshipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/InternalAPI.Unshipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.17763.0/InternalAPI.Shipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.17763.0/InternalAPI.Shipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.17763.0/InternalAPI.Shipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.17763.0/InternalAPI.Shipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.17763.0/InternalAPI.Unshipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.17763.0/InternalAPI.Unshipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.17763.0/InternalAPI.Unshipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.17763.0/InternalAPI.Unshipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.18362.0/InternalAPI.Shipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.18362.0/InternalAPI.Shipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.18362.0/InternalAPI.Shipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.18362.0/InternalAPI.Shipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.18362.0/InternalAPI.Unshipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.18362.0/InternalAPI.Unshipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.18362.0/InternalAPI.Unshipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net10.0-windows10.0.18362.0/InternalAPI.Unshipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/InternalAPI/net10.0/InternalAPI.Shipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net10.0/InternalAPI.Shipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/InternalAPI/net10.0/InternalAPI.Shipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net10.0/InternalAPI.Shipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/InternalAPI/net10.0/InternalAPI.Unshipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net10.0/InternalAPI.Unshipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/InternalAPI/net10.0/InternalAPI.Unshipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net10.0/InternalAPI.Unshipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/InternalAPI/net462/InternalAPI.Shipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net462/InternalAPI.Shipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/InternalAPI/net462/InternalAPI.Shipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net462/InternalAPI.Shipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/InternalAPI/net462/InternalAPI.Unshipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net462/InternalAPI.Unshipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/InternalAPI/net462/InternalAPI.Unshipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/net462/InternalAPI.Unshipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/InternalAPI/netstandard2.0/InternalAPI.Shipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/netstandard2.0/InternalAPI.Shipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/InternalAPI/netstandard2.0/InternalAPI.Shipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/netstandard2.0/InternalAPI.Shipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/InternalAPI/netstandard2.0/InternalAPI.Unshipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/netstandard2.0/InternalAPI.Unshipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/InternalAPI/netstandard2.0/InternalAPI.Unshipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/netstandard2.0/InternalAPI.Unshipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/InternalAPI/uap10.0.16299/InternalAPI.Shipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/uap10.0.16299/InternalAPI.Shipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/InternalAPI/uap10.0.16299/InternalAPI.Shipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/uap10.0.16299/InternalAPI.Shipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/InternalAPI/uap10.0.16299/InternalAPI.Unshipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/uap10.0.16299/InternalAPI.Unshipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/InternalAPI/uap10.0.16299/InternalAPI.Unshipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/InternalAPI/uap10.0.16299/InternalAPI.Unshipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/PublicAPI.Shipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/PublicAPI.Shipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/PublicAPI/PublicAPI.Shipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/PublicAPI.Shipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/PublicAPI.Unshipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/PublicAPI/PublicAPI.Unshipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/PublicAPI.Unshipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.17763.0/PublicAPI.Shipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.17763.0/PublicAPI.Shipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.17763.0/PublicAPI.Shipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.17763.0/PublicAPI.Shipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.17763.0/PublicAPI.Unshipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.17763.0/PublicAPI.Unshipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.17763.0/PublicAPI.Unshipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.17763.0/PublicAPI.Unshipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.18362.0/PublicAPI.Shipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.18362.0/PublicAPI.Shipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.18362.0/PublicAPI.Shipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.18362.0/PublicAPI.Shipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.18362.0/PublicAPI.Unshipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.18362.0/PublicAPI.Unshipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.18362.0/PublicAPI.Unshipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net10.0-windows10.0.18362.0/PublicAPI.Unshipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/net10.0/PublicAPI.Shipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net10.0/PublicAPI.Shipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/PublicAPI/net10.0/PublicAPI.Shipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net10.0/PublicAPI.Shipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/net10.0/PublicAPI.Unshipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net10.0/PublicAPI.Unshipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/PublicAPI/net10.0/PublicAPI.Unshipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net10.0/PublicAPI.Unshipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/net462/PublicAPI.Shipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net462/PublicAPI.Shipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/PublicAPI/net462/PublicAPI.Shipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net462/PublicAPI.Shipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/net462/PublicAPI.Unshipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net462/PublicAPI.Unshipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/PublicAPI/net462/PublicAPI.Unshipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/net462/PublicAPI.Unshipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/netstandard2.0/PublicAPI.Shipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/netstandard2.0/PublicAPI.Shipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/PublicAPI/netstandard2.0/PublicAPI.Shipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/netstandard2.0/PublicAPI.Shipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/netstandard2.0/PublicAPI.Unshipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/uap10.0.16299/PublicAPI.Shipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/uap10.0.16299/PublicAPI.Shipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/PublicAPI/uap10.0.16299/PublicAPI.Shipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/uap10.0.16299/PublicAPI.Shipped.txt.history diff --git a/src/TestFramework/TestFramework.Extensions/PublicAPI/uap10.0.16299/PublicAPI.Unshipped.txt b/src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/uap10.0.16299/PublicAPI.Unshipped.txt.history similarity index 100% rename from src/TestFramework/TestFramework.Extensions/PublicAPI/uap10.0.16299/PublicAPI.Unshipped.txt rename to src/TestFramework/APIHistory/TestFramework.Extensions/PublicAPI/uap10.0.16299/PublicAPI.Unshipped.txt.history diff --git a/src/TestFramework/APIHistory/TestFramework.Extensions/README.md b/src/TestFramework/APIHistory/TestFramework.Extensions/README.md new file mode 100644 index 0000000000..d103180320 --- /dev/null +++ b/src/TestFramework/APIHistory/TestFramework.Extensions/README.md @@ -0,0 +1,13 @@ +# Retired Extensions API provenance + +These are the unchanged shipped and unshipped API records of +`MSTest.TestFramework.Extensions` at merged main +`e1c66e5cbfa844384a59343c3727821f97e2a09a`. They are historical records, not an +active build input or an API-compatibility claim for the new assemblies. +The `.txt.history` suffix deliberately keeps these snapshots out of +`eng/mark-shipped.ps1`'s recursive `PublicAPI.Shipped.txt` / +`InternalAPI.Shipped.txt` discovery, so a release cannot promote or rewrite them. + +The non-UI APIs moved to core in #12412 and #12428. The remaining UI APIs now +belong to `MSTest.Uwp` and `MSTest.WinUI`. Consumers must update their package +references and recompile for this intentional next-major package boundary. diff --git a/src/TestFramework/TestFramework.Extensions/Attributes/UWP_UITestMethodAttribute.cs b/src/TestFramework/MSTest.Uwp/Attributes/UITestMethodAttribute.cs similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Attributes/UWP_UITestMethodAttribute.cs rename to src/TestFramework/MSTest.Uwp/Attributes/UITestMethodAttribute.cs diff --git a/src/TestFramework/MSTest.Uwp/InternalAPI/InternalAPI.Shipped.txt b/src/TestFramework/MSTest.Uwp/InternalAPI/InternalAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/TestFramework/MSTest.Uwp/InternalAPI/InternalAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/TestFramework/MSTest.Uwp/InternalAPI/InternalAPI.Unshipped.txt b/src/TestFramework/MSTest.Uwp/InternalAPI/InternalAPI.Unshipped.txt new file mode 100644 index 0000000000..115f82fe64 --- /dev/null +++ b/src/TestFramework/MSTest.Uwp/InternalAPI/InternalAPI.Unshipped.txt @@ -0,0 +1,3 @@ +#nullable enable +Microsoft.CodeAnalysis.EmbeddedAttribute +Microsoft.CodeAnalysis.EmbeddedAttribute.EmbeddedAttribute() -> void diff --git a/src/TestFramework/MSTest.Uwp/MSTest.Uwp.csproj b/src/TestFramework/MSTest.Uwp/MSTest.Uwp.csproj new file mode 100644 index 0000000000..881670a0b2 --- /dev/null +++ b/src/TestFramework/MSTest.Uwp/MSTest.Uwp.csproj @@ -0,0 +1,30 @@ + + + + <_UsesMSBuildSdkExtras Condition=" '$(OS)' == 'Windows_NT' ">true + + + + + + $(ModernUwpMinimum) + $(UwpMinimum);$(TargetFrameworks) + MSTest.Uwp + MSTest.Uwp + $(DefineConstants);WINDOWS_UWP + + + + + + + + + + + + + + diff --git a/src/TestFramework/MSTest.Uwp/PACKAGE.md b/src/TestFramework/MSTest.Uwp/PACKAGE.md new file mode 100644 index 0000000000..1000a5a050 --- /dev/null +++ b/src/TestFramework/MSTest.Uwp/PACKAGE.md @@ -0,0 +1,26 @@ +# MSTest.Uwp + +Write and run UI-thread tests in classic and modern UWP applications. This +package contains `MSTest.Uwp.dll`, the UWP MSTest adapter and platform services, +and their localized resources. It depends on the matching `MSTest.TestFramework` +package, not on `MSTest.TestAdapter` or `MSTest.WinUI`. + +Supported targets are classic `uap10.0.16299` and modern +`net10.0-windows10.0.17763.0`, including compatible .NET 11 UWP consumers. +The application still owns its UWP tooling, runtime, manifest and activation. +Modern UWP does not use WinUI assets. + +Reference this package instead of the `MSTest` metapackage or ordinary adapter +for modern UWP. With `MSTest.Sdk`, select `MSTestApplicationModel=Uwp` when +desktop UWP tooling is imported too late for restore-time inference. +Ordinary helper libraries need only `MSTest.TestFramework`. + +`Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute` +keeps its existing API and dispatches through the UWP CoreWindow dispatcher. +Migrate references to the retired `MSTest.TestFramework.Extensions` assembly and +recompile. All six `TestContext` directory getters return null in UWP hosts, +even when the property bag contains same-named values. Deployment items are +unsupported: modern UWP tests using `[DeploymentItem]` fail before their body; +classic UWP's netstandard core does not expose that attribute. + +MSTest is Microsoft supported Test Framework. diff --git a/src/TestFramework/TestFramework.Extensions/Properties/AssemblyInfo.cs b/src/TestFramework/MSTest.Uwp/Properties/AssemblyInfo.cs similarity index 50% rename from src/TestFramework/TestFramework.Extensions/Properties/AssemblyInfo.cs rename to src/TestFramework/MSTest.Uwp/Properties/AssemblyInfo.cs index e79fe7763d..b41b7b5a9a 100644 --- a/src/TestFramework/TestFramework.Extensions/Properties/AssemblyInfo.cs +++ b/src/TestFramework/MSTest.Uwp/Properties/AssemblyInfo.cs @@ -1,11 +1,5 @@ // Copyright (c) Microsoft Corporation. All rights reserved. // Licensed under the MIT license. See LICENSE file in the project root for full license information. -#if !WIN_UI [assembly: CLSCompliant(true)] [assembly: ComVisible(false)] -#else -// Extra .0 at the end is a workaround for https://github.com/dotnet/roslyn-analyzers/issues/5728 -// Can be removed after the issue is closed. -[assembly: SupportedOSPlatform("windows10.0.17763.0")] -#endif diff --git a/src/TestFramework/TestFramework.Extensions/Properties/Extension.UWP.rd.xml b/src/TestFramework/MSTest.Uwp/Properties/MSTest.Uwp.rd.xml similarity index 97% rename from src/TestFramework/TestFramework.Extensions/Properties/Extension.UWP.rd.xml rename to src/TestFramework/MSTest.Uwp/Properties/MSTest.Uwp.rd.xml index 4a9d515ef0..a5b06eeeb1 100644 --- a/src/TestFramework/TestFramework.Extensions/Properties/Extension.UWP.rd.xml +++ b/src/TestFramework/MSTest.Uwp/Properties/MSTest.Uwp.rd.xml @@ -25,7 +25,7 @@ https://go.microsoft.com/fwlink/?LinkID=391919 --> - + diff --git a/src/TestFramework/MSTest.Uwp/PublicAPI/PublicAPI.Shipped.txt b/src/TestFramework/MSTest.Uwp/PublicAPI/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/TestFramework/MSTest.Uwp/PublicAPI/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/TestFramework/MSTest.Uwp/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/MSTest.Uwp/PublicAPI/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..175a7cf10f --- /dev/null +++ b/src/TestFramework/MSTest.Uwp/PublicAPI/PublicAPI.Unshipped.txt @@ -0,0 +1,4 @@ +#nullable enable +Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute +Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute.UITestMethodAttribute(string! callerFilePath = "", int callerLineNumber = -1) -> void +override Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute.ExecuteAsync(Microsoft.VisualStudio.TestTools.UnitTesting.ITestMethod! testMethod) -> System.Threading.Tasks.Task! diff --git a/src/TestFramework/TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs b/src/TestFramework/MSTest.WinUI/Attributes/UITestMethodAttribute.cs similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Attributes/WinUI_UITestMethodAttribute.cs rename to src/TestFramework/MSTest.WinUI/Attributes/UITestMethodAttribute.cs diff --git a/src/TestFramework/TestFramework.Extensions/Attributes/WinUITestTargetAttribute.cs b/src/TestFramework/MSTest.WinUI/Attributes/WinUITestTargetAttribute.cs similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Attributes/WinUITestTargetAttribute.cs rename to src/TestFramework/MSTest.WinUI/Attributes/WinUITestTargetAttribute.cs diff --git a/src/TestFramework/MSTest.WinUI/InternalAPI/InternalAPI.Shipped.txt b/src/TestFramework/MSTest.WinUI/InternalAPI/InternalAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/TestFramework/MSTest.WinUI/InternalAPI/InternalAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/TestFramework/MSTest.WinUI/InternalAPI/InternalAPI.Unshipped.txt b/src/TestFramework/MSTest.WinUI/InternalAPI/InternalAPI.Unshipped.txt new file mode 100644 index 0000000000..41c5ec0968 --- /dev/null +++ b/src/TestFramework/MSTest.WinUI/InternalAPI/InternalAPI.Unshipped.txt @@ -0,0 +1,4 @@ +#nullable enable +Microsoft.CodeAnalysis.EmbeddedAttribute +Microsoft.CodeAnalysis.EmbeddedAttribute.EmbeddedAttribute() -> void +static Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute.WaitForApplicationStartup(System.Threading.Tasks.TaskCompletionSource! startupCompletion, System.Func! waitForUiThreadExit, System.TimeSpan timeout, System.TimeSpan pollInterval) -> void diff --git a/src/TestFramework/MSTest.WinUI/MSTest.WinUI.csproj b/src/TestFramework/MSTest.WinUI/MSTest.WinUI.csproj new file mode 100644 index 0000000000..7925c7b289 --- /dev/null +++ b/src/TestFramework/MSTest.WinUI/MSTest.WinUI.csproj @@ -0,0 +1,25 @@ + + + + $(WinUiMinimum) + MSTest.WinUI + MSTest.WinUI + $(DefineConstants);WIN_UI + 10.0.18362.0 + 10.0.17763.0 + 10.0.17763.0 + + + + + + + + + + + + + diff --git a/src/TestFramework/MSTest.WinUI/PACKAGE.md b/src/TestFramework/MSTest.WinUI/PACKAGE.md new file mode 100644 index 0000000000..ce98512218 --- /dev/null +++ b/src/TestFramework/MSTest.WinUI/PACKAGE.md @@ -0,0 +1,25 @@ +# MSTest.WinUI + +Write and run UI-thread tests in packaged and unpackaged WinUI applications. +This package contains `MSTest.WinUI.dll`, the WinUI MSTest adapter and platform +services, and their localized resources. It depends on the matching +`MSTest.TestFramework` package, not on `MSTest.TestAdapter` or `MSTest.Uwp`. + +The package targets `net10.0-windows10.0.18362.0` and compatible .NET 11 +consumers. The application still owns its Windows App SDK version, runtime +bootstrap, dispatcher, manifest and activation; this package does not install +or select that runtime. + +Reference this package instead of the `MSTest` metapackage or ordinary adapter. +`MSTest.Sdk` selects it for WinUI applications, with +`MSTestApplicationModel=WinUI` available for explicit restore-time selection. +Ordinary helper libraries need only `MSTest.TestFramework`. + +The existing AppContainer `UITestMethodAttribute` and `WinUITestTargetAttribute` +APIs are unchanged. Migrate references to the retired +`MSTest.TestFramework.Extensions` assembly and recompile. All six `TestContext` +directory getters return null in WinUI hosts, even when the property bag +contains same-named values. Tests using `[DeploymentItem]` fail before their +body because UI-host deployment is unsupported. + +MSTest is Microsoft supported Test Framework. diff --git a/src/TestFramework/MSTest.WinUI/Properties/AssemblyInfo.cs b/src/TestFramework/MSTest.WinUI/Properties/AssemblyInfo.cs new file mode 100644 index 0000000000..6165e9e158 --- /dev/null +++ b/src/TestFramework/MSTest.WinUI/Properties/AssemblyInfo.cs @@ -0,0 +1,4 @@ +// Copyright (c) Microsoft Corporation. All rights reserved. +// Licensed under the MIT license. See LICENSE file in the project root for full license information. + +[assembly: SupportedOSPlatform("windows10.0.17763.0")] diff --git a/src/TestFramework/MSTest.WinUI/PublicAPI/PublicAPI.Shipped.txt b/src/TestFramework/MSTest.WinUI/PublicAPI/PublicAPI.Shipped.txt new file mode 100644 index 0000000000..7dc5c58110 --- /dev/null +++ b/src/TestFramework/MSTest.WinUI/PublicAPI/PublicAPI.Shipped.txt @@ -0,0 +1 @@ +#nullable enable diff --git a/src/TestFramework/MSTest.WinUI/PublicAPI/PublicAPI.Unshipped.txt b/src/TestFramework/MSTest.WinUI/PublicAPI/PublicAPI.Unshipped.txt new file mode 100644 index 0000000000..e41ff441f9 --- /dev/null +++ b/src/TestFramework/MSTest.WinUI/PublicAPI/PublicAPI.Unshipped.txt @@ -0,0 +1,9 @@ +#nullable enable +Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute +Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute.UITestMethodAttribute(string! callerFilePath = "", int callerLineNumber = -1) -> void +Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.WinUITestTargetAttribute +Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.WinUITestTargetAttribute.ApplicationType.get -> System.Type! +Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.WinUITestTargetAttribute.WinUITestTargetAttribute(System.Type! applicationType) -> void +override Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute.ExecuteAsync(Microsoft.VisualStudio.TestTools.UnitTesting.ITestMethod! testMethod) -> System.Threading.Tasks.Task! +static Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute.DispatcherQueue.get -> Microsoft.UI.Dispatching.DispatcherQueue? +static Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethodAttribute.DispatcherQueue.set -> void diff --git a/src/TestFramework/TestFramework.Extensions/Resources/FrameworkExtensionsMessages.resx b/src/TestFramework/MSTest.WinUI/Resources/FrameworkExtensionsMessages.resx similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Resources/FrameworkExtensionsMessages.resx rename to src/TestFramework/MSTest.WinUI/Resources/FrameworkExtensionsMessages.resx diff --git a/src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.cs.xlf b/src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.cs.xlf similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.cs.xlf rename to src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.cs.xlf diff --git a/src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.de.xlf b/src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.de.xlf similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.de.xlf rename to src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.de.xlf diff --git a/src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.es.xlf b/src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.es.xlf similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.es.xlf rename to src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.es.xlf diff --git a/src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.fr.xlf b/src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.fr.xlf similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.fr.xlf rename to src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.fr.xlf diff --git a/src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.it.xlf b/src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.it.xlf similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.it.xlf rename to src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.it.xlf diff --git a/src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.ja.xlf b/src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.ja.xlf similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.ja.xlf rename to src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.ja.xlf diff --git a/src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.ko.xlf b/src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.ko.xlf similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.ko.xlf rename to src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.ko.xlf diff --git a/src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.pl.xlf b/src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.pl.xlf similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.pl.xlf rename to src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.pl.xlf diff --git a/src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.pt-BR.xlf b/src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.pt-BR.xlf similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.pt-BR.xlf rename to src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.pt-BR.xlf diff --git a/src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.ru.xlf b/src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.ru.xlf similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.ru.xlf rename to src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.ru.xlf diff --git a/src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.tr.xlf b/src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.tr.xlf similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.tr.xlf rename to src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.tr.xlf diff --git a/src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.zh-Hans.xlf b/src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.zh-Hans.xlf similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.zh-Hans.xlf rename to src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.zh-Hans.xlf diff --git a/src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.zh-Hant.xlf b/src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.zh-Hant.xlf similarity index 100% rename from src/TestFramework/TestFramework.Extensions/Resources/xlf/FrameworkExtensionsMessages.zh-Hant.xlf rename to src/TestFramework/MSTest.WinUI/Resources/xlf/FrameworkExtensionsMessages.zh-Hant.xlf diff --git a/src/TestFramework/PlatformPackage/MSTest.Platform.props b/src/TestFramework/PlatformPackage/MSTest.Platform.props new file mode 100644 index 0000000000..56acfd2c30 --- /dev/null +++ b/src/TestFramework/PlatformPackage/MSTest.Platform.props @@ -0,0 +1,10 @@ + + + <_MSTestAdapterPayloadRoot>$(MSBuildThisFileDirectory) + <_MSTestAdapterLocalizationRoot>$(MSBuildThisFileDirectory)_localization\ + <_MSTestUwpAdapterReferenced Condition=" '$(MSBuildThisFileName)' == 'MSTest.Uwp' ">true + <_MSTestWinUIAdapterReferenced Condition=" '$(MSBuildThisFileName)' == 'MSTest.WinUI' ">true + true + true + + diff --git a/src/TestFramework/PlatformPackage/PlatformPackage.props b/src/TestFramework/PlatformPackage/PlatformPackage.props new file mode 100644 index 0000000000..a49d62a42c --- /dev/null +++ b/src/TestFramework/PlatformPackage/PlatformPackage.props @@ -0,0 +1,25 @@ + + + + Microsoft.VisualStudio.TestTools.UnitTesting + true + true + $(CommonPackageTags) MSTest UI TestFramework TestAdapter + $(DefineConstants);TRACE;EXCLUDE_RANGE_INDEX_POLYFILL;EXCLUDE_OS_POLYFILL + $(TargetsForTfmSpecificContentInPackage);_AddMSTestPlatformPackageFiles + + + + + + + + + + + + + + + + diff --git a/src/TestFramework/PlatformPackage/PlatformPackage.targets b/src/TestFramework/PlatformPackage/PlatformPackage.targets new file mode 100644 index 0000000000..aadff46308 --- /dev/null +++ b/src/TestFramework/PlatformPackage/PlatformPackage.targets @@ -0,0 +1,28 @@ + + + + + <_PlatformPackageTfm Condition=" '$(TargetFramework)' == '$(UwpMinimum)' ">uap10.0.16299 + <_PlatformPackageTfm Condition=" '$(TargetFramework)' == '$(ModernUwpMinimum)' ">net10.0-windows10.0.17763 + <_PlatformPackageTfm Condition=" '$(TargetFramework)' == '$(WinUiMinimum)' ">net10.0-windows10.0.18362 + + + + + + + + + + + + + diff --git a/src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj b/src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj deleted file mode 100644 index 64adf54491..0000000000 --- a/src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj +++ /dev/null @@ -1,257 +0,0 @@ - - - - <_UsesMSBuildSdkExtras Condition=" '$(OS)' == 'Windows_NT' ">true - - - - - - - - netstandard2.0;$(NetFrameworkMinimum);$(SupportedNetFrameworks);$(UwpMinimum);$(ModernUwpMinimum);$(WinUiMinimum) - $(SupportedNetFrameworks);netstandard2.0 - - - - true - - false - MSTest.TestFramework - $(CommonPackageTags) MSTest TestFramework MSTestV2 Framework - - $(NoWarn);NU5100;NU5128 - - - - Microsoft.VisualStudio.TestTools.UnitTesting - MSTest.TestFramework.Extensions - $(DefineConstants);TRACE - - $(DefineConstants);EXCLUDE_RANGE_INDEX_POLYFILL;EXCLUDE_OS_POLYFILL - - - - - $(DefineConstants);WIN_UI - 10.0.18362.0 - 10.0.17763.0 - 10.0.17763.0 - - - - $(DefineConstants);WINDOWS_UWP - - - - - false - - - - - - - - - - - - - - - - - - - - - - - - - <_ApiTargetFramework>$(TargetFramework) - <_ApiTargetFramework Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net10.0')) AND !$(TargetFramework.Contains('-'))">net10.0 - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - <_NonPublishableNupkg>$(PackageOutputPath)$(PackageId).$(PackageVersion).nupkg - <_NonPublishableExtractDir>$(BaseIntermediateOutputPath)nupkgfix\ - - - - - - - <_NonPublishableNuspecPath>$(_NonPublishableExtractDir)$(PackageId).nuspec - <_NonPublishableNuspecContent>$([System.IO.File]::ReadAllText($(_NonPublishableNuspecPath))) - <_NonPublishableNuspecFixed>$([System.Text.RegularExpressions.Regex]::Replace($(_NonPublishableNuspecContent), '[ \t]*<dependency id="NotPublishable"[^>]*/>[ \t]*\r?\n', '')) - - <_NonPublishableDependencyRemoved>false - <_NonPublishableDependencyRemoved Condition=" '$(_NonPublishableNuspecFixed)' != '$(_NonPublishableNuspecContent)' ">true - - - - - - <_WriteTextFile Condition=" '$(_NonPublishableDependencyRemoved)' == 'true' " Path="$(_NonPublishableNuspecPath)" Content="$(_NonPublishableNuspecFixed)" /> - - - - - - - - - - $(TargetsForTfmSpecificContentInPackage);_AddTestFrameworkPackageFiles - - - - - - <_PackageTfm Condition=" '$(TargetFramework)' == '$(UwpMinimum)' ">uap10.0 - <_PackageTfm Condition=" '$(_PackageTfm)' == '' ">$(TargetFramework) - - - <_ExtensionsPackagePath Condition=" '$(TargetFramework)' == 'netstandard2.0' OR '$(TargetFramework)' == '$(NetFrameworkMinimum)' OR '$(TargetFramework)' == '$(UwpMinimum)' ">lib\$(_PackageTfm)\ - <_ExtensionsPackagePath Condition="$([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net10.0'))">buildTransitive\$(TargetFramework)\ - <_ExtensionsPackagePath Condition=" '$(TargetFramework)' == '$(WinUiMinimum)' ">buildTransitive\net10.0\winui\ - <_ExtensionsPackagePath Condition=" '$(TargetFramework)' == '$(ModernUwpMinimum)' ">buildTransitive\net10.0\uwp\ - - <_CorePackagePath>lib\$(_PackageTfm)\ - <_CorePackagePath Condition=" '$(TargetFramework)' == '$(WinUiMinimum)' OR '$(TargetFramework)' == '$(ModernUwpMinimum)' ">$(_ExtensionsPackagePath) - - - - - - - - - <_CoreResourceFile Include="$(TargetDir)**\MSTest.TestFramework.resources.dll" /> - - - - - - - - - - - - - - - - - - - - - - - diff --git a/src/TestFramework/TestFramework.Extensions/build/net10.0/MSTest.TestFramework.targets b/src/TestFramework/TestFramework.Extensions/build/net10.0/MSTest.TestFramework.targets deleted file mode 100644 index 9d8d32dc68..0000000000 --- a/src/TestFramework/TestFramework.Extensions/build/net10.0/MSTest.TestFramework.targets +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/TestFramework/TestFramework.Extensions/build/net11.0/MSTest.TestFramework.targets b/src/TestFramework/TestFramework.Extensions/build/net11.0/MSTest.TestFramework.targets deleted file mode 100644 index 1cf2ef5560..0000000000 --- a/src/TestFramework/TestFramework.Extensions/build/net11.0/MSTest.TestFramework.targets +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/TestFramework/TestFramework.Extensions/build/net462/MSTest.TestFramework.targets b/src/TestFramework/TestFramework.Extensions/build/net462/MSTest.TestFramework.targets deleted file mode 100644 index f80fd5bb22..0000000000 --- a/src/TestFramework/TestFramework.Extensions/build/net462/MSTest.TestFramework.targets +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/TestFramework/TestFramework.Extensions/build/netstandard2.0/MSTest.TestFramework.targets b/src/TestFramework/TestFramework.Extensions/build/netstandard2.0/MSTest.TestFramework.targets deleted file mode 100644 index d4afeaee4a..0000000000 --- a/src/TestFramework/TestFramework.Extensions/build/netstandard2.0/MSTest.TestFramework.targets +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/TestFramework/TestFramework.Extensions/build/uap10.0/MSTest.TestFramework.targets b/src/TestFramework/TestFramework.Extensions/build/uap10.0/MSTest.TestFramework.targets deleted file mode 100644 index 9b248fe99e..0000000000 --- a/src/TestFramework/TestFramework.Extensions/build/uap10.0/MSTest.TestFramework.targets +++ /dev/null @@ -1,3 +0,0 @@ - - - diff --git a/src/TestFramework/TestFramework.Extensions/buildTransitive/net10.0AndLater/MSTest.TestFramework.targets b/src/TestFramework/TestFramework.Extensions/buildTransitive/net10.0AndLater/MSTest.TestFramework.targets deleted file mode 100644 index 6150e3528e..0000000000 --- a/src/TestFramework/TestFramework.Extensions/buildTransitive/net10.0AndLater/MSTest.TestFramework.targets +++ /dev/null @@ -1,54 +0,0 @@ - - - - <_TestFrameworkExtensionsRoot>$(MSBuildThisFileDirectory)../net10.0/winui/ - - - - - <_TestFrameworkExtensionsRoot>$(MSBuildThisFileDirectory)../net10.0/uwp/ - - - - <_TestFrameworkExtensionsRoot>$(MSBuildThisFileDirectory) - - - - - $(_TestFrameworkExtensionsRoot)MSTest.TestFramework.Extensions.dll - PreserveNewest - False - - - - - - - <_MSTestCoreCompileAsset Include="@(ResolvedCompileFileDefinitions)" Condition=" '%(Filename)' == 'MSTest.TestFramework' " /> - <_MSTestCoreRuntimeAsset Include="@(RuntimeCopyLocalItems)" Condition=" '%(Filename)' == 'MSTest.TestFramework' " /> - <_MSTestCoreResourceAsset Include="@(ResourceCopyLocalItems)" Condition=" '%(Filename)' == 'MSTest.TestFramework.resources' " /> - - - - - $(_TestFrameworkExtensionsRoot)MSTest.TestFramework.dll - - - - - - - - - - - diff --git a/src/TestFramework/TestFramework.Windows.UIAutomation/TestFramework.Windows.UIAutomation.csproj b/src/TestFramework/TestFramework.Windows.UIAutomation/TestFramework.Windows.UIAutomation.csproj index 247ae3097d..e7aa395bcc 100644 --- a/src/TestFramework/TestFramework.Windows.UIAutomation/TestFramework.Windows.UIAutomation.csproj +++ b/src/TestFramework/TestFramework.Windows.UIAutomation/TestFramework.Windows.UIAutomation.csproj @@ -24,7 +24,7 @@ $(CommonProductDescription)]]> - + diff --git a/src/TestFramework/TestFramework/Attributes/DeploymentItemAttribute.cs b/src/TestFramework/TestFramework/Attributes/DeploymentItemAttribute.cs index 3c3e5b5520..2a29c9735c 100644 --- a/src/TestFramework/TestFramework/Attributes/DeploymentItemAttribute.cs +++ b/src/TestFramework/TestFramework/Attributes/DeploymentItemAttribute.cs @@ -3,7 +3,7 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; -#if !NETSTANDARD2_0 && !WINDOWS_UWP && !WIN_UI +#if !NETSTANDARD2_0 /// /// Used to specify a deployment item (file or directory) for per-test deployment. The specified files @@ -19,6 +19,8 @@ namespace Microsoft.VisualStudio.TestTools.UnitTesting; /// If specified on a test class, the class needs to contain at least one test method. This means that the /// attribute cannot be combined with a test class that would contain only an AssemblyInitialize or /// ClassInitialize method. +/// Deployment items are not supported by UWP or WinUI test hosts. Tests using this attribute in +/// those hosts fail before their test body executes. /// /// /// diff --git a/src/TestFramework/TestFramework.Extensions/buildTransitive/others/MSTest.TestFramework.targets b/src/TestFramework/TestFramework/MSTest.TestFramework.targets similarity index 100% rename from src/TestFramework/TestFramework.Extensions/buildTransitive/others/MSTest.TestFramework.targets rename to src/TestFramework/TestFramework/MSTest.TestFramework.targets diff --git a/src/TestFramework/TestFramework.Extensions/PACKAGE.md b/src/TestFramework/TestFramework/PACKAGE.md similarity index 86% rename from src/TestFramework/TestFramework.Extensions/PACKAGE.md rename to src/TestFramework/TestFramework/PACKAGE.md index 8fd562407a..9a4010b0ce 100644 --- a/src/TestFramework/TestFramework.Extensions/PACKAGE.md +++ b/src/TestFramework/TestFramework/PACKAGE.md @@ -2,7 +2,9 @@ MSTest is Microsoft supported Test Framework. -This package includes the libraries for writing tests with MSTest. To ensure discovery and execution of your tests, install the MSTest.TestAdapter package. +This package contains the shared non-UI libraries for writing MSTest tests and +helper libraries. Add `MSTest.TestAdapter` for ordinary test applications, +`MSTest.Uwp` for UWP, or `MSTest.WinUI` for WinUI. ## Getting started @@ -22,9 +24,7 @@ Supported platforms: - .NET 4.6.2+ - .NET 10.0+ -- .NET 10.0 Windows.18362+ (WinUI) -- UWP 10.0.16299 -- UWP 10.0.17763 with .NET 10+ +- .NET Standard 2.0 (including classic UWP helper libraries) ## Documentation @@ -36,13 +36,13 @@ are defined in `MSTest.TestFramework.dll`. The .NET Framework-only private reflection and test-configuration helpers are also defined there. Consumers compiled against their former `MSTest.TestFramework.Extensions.dll` definitions must recompile; assembly-qualified configuration names must use the core assembly. -UI APIs remain in Extensions. Package IDs, package ownership and supported targets -are unchanged. UWP/WinUI select matching core and Extensions assemblies; their -`TestContext` still excludes desktop directory properties, and -`DeploymentItemAttribute` remains unavailable there and on .NET Standard 2.0. -Modern UWP/WinUI core assemblies and their resources ship beside the existing -UI Extensions assets in `buildTransitive/net10.0/uwp` and -`buildTransitive/net10.0/winui`; ordinary consumers keep their `lib` assets. +The Extensions project and assembly are retired. UI APIs now belong to +`MSTest.Uwp` and `MSTest.WinUI`; migrate package/assembly references and +recompile. All applications and ordinary helper libraries use the same non-UI +core selected through `lib/`. Modern UI consumers therefore see the shared +directory and deployment APIs, but UI hosts return null for all six directory +getters, even when same-named property-bag values exist, and reject +`DeploymentItemAttribute` before the test body executes. ### Predicate-based collection assertions diff --git a/src/TestFramework/TestFramework/TestContext.cs b/src/TestFramework/TestFramework/TestContext.cs index 30261854e0..723d2edf56 100644 --- a/src/TestFramework/TestFramework/TestContext.cs +++ b/src/TestFramework/TestFramework/TestContext.cs @@ -37,13 +37,11 @@ public static TestContext? Current internal static readonly string FullyQualifiedTestClassNameLabel = nameof(FullyQualifiedTestClassName); internal static readonly string TestNameLabel = nameof(TestName); -#if !WINDOWS_UWP && !WIN_UI internal static readonly string TestRunDirectoryLabel = nameof(TestRunDirectory); internal static readonly string DeploymentDirectoryLabel = nameof(DeploymentDirectory); internal static readonly string ResultsDirectoryLabel = nameof(ResultsDirectory); internal static readonly string TestRunResultsDirectoryLabel = nameof(TestRunResultsDirectory); internal static readonly string TestResultsDirectoryLabel = nameof(TestResultsDirectory); -#endif /// /// Gets test properties for a test. @@ -84,7 +82,6 @@ public static TestContext? Current public abstract DbConnection? DataConnection { get; } #endif -#if !WINDOWS_UWP && !WIN_UI #region Test run deployment directories /// @@ -100,6 +97,10 @@ public static TestContext? Current /// \<MachineName> // TestRunResultsDirectory /// \Out // DeploymentDirectory /// + /// + /// UWP and WinUI test hosts do not support deployment directories. All test-run directory + /// properties return in those hosts, even if a same-named property is present in . + /// /// public virtual string? TestRunDirectory => GetProperty(TestRunDirectoryLabel); @@ -108,6 +109,7 @@ public static TestContext? Current /// /// /// When app domains are disabled, this can instead point at the test assembly directory. + /// Returns in UWP and WinUI test hosts. /// public virtual string? DeploymentDirectory => GetProperty(DeploymentDirectoryLabel); @@ -117,6 +119,7 @@ public static TestContext? Current /// /// In the current implementation this returns the same path as (the In directory). /// When run directory information is unavailable, the platform services layer can fall back to the application base directory. + /// Returns in UWP and WinUI test hosts. /// public virtual string? ResultsDirectory => GetProperty(ResultsDirectoryLabel); @@ -135,6 +138,7 @@ public static TestContext? Current /// /// /// When run directory information is unavailable, the platform services layer can return the same path for both properties. + /// UWP and WinUI test hosts return . /// /// public virtual string? TestRunResultsDirectory => GetProperty(TestRunResultsDirectoryLabel); @@ -143,6 +147,7 @@ public static TestContext? Current /// Gets the directory for test result files (the "In" directory). This is the same path as /// and is typically the parent of . When run directory information is unavailable, /// the platform services layer can return the same path for both properties. + /// UWP and WinUI test hosts return . /// public virtual string? TestResultsDirectory => GetProperty(TestResultsDirectoryLabel); @@ -162,6 +167,9 @@ public static TestContext? Current /// [ClassCleanup], or [AssemblyCleanup] — where there is no single owning test. /// /// + /// UWP and WinUI test hosts do not provide this directory and always return . + /// + /// /// The directory is deleted automatically when the test passes and retained when the test /// fails, so a failed test's artifacts remain available for inspection. Retention of all /// directories (including passing tests) can be forced for debugging via the @@ -192,7 +200,6 @@ public static TestContext? Current public virtual string? TestTempDirectory => null; #endregion -#endif /// /// Gets the Fully-qualified name of the class containing the test method currently being executed. diff --git a/src/TestFramework/TestFramework/TestFramework.csproj b/src/TestFramework/TestFramework/TestFramework.csproj index 63a7491993..cd3a341343 100644 --- a/src/TestFramework/TestFramework/TestFramework.csproj +++ b/src/TestFramework/TestFramework/TestFramework.csproj @@ -1,26 +1,7 @@ - - - - <_UsesMSBuildSdkExtras Condition=" '$(OS)' == 'Windows_NT' ">true - - - - + netstandard2.0;$(NetFrameworkMinimum);$(SupportedNetFrameworks) - $(TargetFrameworks);$(UwpMinimum);$(ModernUwpMinimum);$(WinUiMinimum) - - - - $(DefineConstants);WINDOWS_UWP - - - - $(DefineConstants);WIN_UI - 10.0.18362.0 - 10.0.17763.0 - 10.0.17763.0 @@ -28,13 +9,12 @@ MSTest.TestFramework $(DefineConstants);TRACE - - NotPublishable - false + MSTest.TestFramework + true + $(CommonPackageTags) MSTest TestFramework Framework + $(DefineConstants);EXCLUDE_RANGE_INDEX_POLYFILL;EXCLUDE_OS_POLYFILL MSTest.TestFramework - MSTest.TestFramework.Extensions <_CodeCoverageProjectReference Include="$(MSBuildProjectFullPath)" diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ClassicUwpTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ClassicUwpTests.cs index 37c7fa9caa..9af2ec7587 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ClassicUwpTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ClassicUwpTests.cs @@ -20,7 +20,7 @@ public sealed class ClassicUwpTests : AcceptanceTestBase [TestMethod] [DataRow("MSTest.Sdk")] [DataRow("MSTest")] - [DataRow("MSTest.TestAdapter")] + [DataRow("MSTest.Uwp")] [OSCondition(OperatingSystems.Windows, IgnoreMessage = "Classic UWP execution is supported only on Windows.")] public async Task ClassicUwp_ConsumesUapAssets_AndRunsPlainAndUiTestsThroughMtp(string package) { @@ -32,7 +32,7 @@ public async Task ClassicUwp_ConsumesUapAssets_AndRunsPlainAndUiTestsThroughMtp( { string references = package == "MSTest" ? $"" - : $""; + : $""; source = source .Replace(" ", string.Empty, StringComparison.Ordinal) .Replace(" ", string.Empty, StringComparison.Ordinal) @@ -287,11 +287,11 @@ private static void AssertCounter(XElement counters, string name, int expected, - - @@ -446,11 +446,28 @@ namespace $AssetName$ [TestClass] public sealed class ClassicUwpPackageTests { + public TestContext TestContext { get; set; } + [TestMethod] public void PlainTestMethod_RunsInClassicUwpPackage() { Assert.AreEqual("$PackageIdentityName$", Package.Current.Id.Name); Assert.IsFalse(string.IsNullOrWhiteSpace(Package.Current.Id.FamilyName)); + string[] directories = { "TestRunDirectory", "DeploymentDirectory", "ResultsDirectory", "TestRunResultsDirectory", "TestResultsDirectory", "TestTempDirectory" }; + foreach (string directory in directories) + { + TestContext.Properties[directory] = "not-a-ui-directory"; + } + + Assert.IsNull(TestContext.TestRunDirectory); + Assert.IsNull(TestContext.DeploymentDirectory); + Assert.IsNull(TestContext.ResultsDirectory); + Assert.IsNull(TestContext.TestRunResultsDirectory); + Assert.IsNull(TestContext.TestResultsDirectory); + Assert.IsNull(TestContext.TestTempDirectory); + TestContext.WriteLine(typeof(TestContext).Assembly.Location); + TestContext.WriteLine(typeof(UITestMethodAttribute).Assembly.Location); + TestContext.WriteLine(TestContext.GetType().Assembly.Location); } [UITestMethod] diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CoreFrameworkAssemblyTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CoreFrameworkAssemblyTests.cs index 509497bf45..80ddcd8b6a 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CoreFrameworkAssemblyTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CoreFrameworkAssemblyTests.cs @@ -15,23 +15,25 @@ public sealed class CoreFrameworkAssemblyTests : AcceptanceTestBase", StringComparison.Ordinal); using TestAsset asset = await TestAsset.GenerateAssetAsync("CoreFrameworkConsumer", source); string cache = Path.Join(asset.TargetAssetPath, ".packages"); var environment = new Dictionary { ["NUGET_PACKAGES"] = cache }; @@ -49,24 +51,29 @@ public async Task PackedConsumersUseMatchingCoreAndExtensions( Assert.AreEqual( Path.GetFullPath(cache), Path.GetFullPath(assets.RootElement.GetProperty("project").GetProperty("restore").GetProperty("packagesPath").GetString()!)); - string package = Path.Join(Constants.ArtifactsPackagesShipping, $"MSTest.TestFramework.{MSTestVersion}.nupkg"); - string restored = Path.Join(cache, "mstest.testframework", MSTestVersion); - string cachedPackage = Path.Join(restored, $"mstest.testframework.{MSTestVersion}.nupkg"); - Assert.AreEqual( - Convert.ToHexString(SHA256.HashData(File.ReadAllBytes(package))), - Convert.ToHexString(SHA256.HashData(File.ReadAllBytes(cachedPackage)))); - string extensionsAsset = desktop ? $"buildTransitive/{targetFramework.Split('-')[0]}" : coreAsset; - (string Name, string Asset)[] assemblies = + List<(string Package, string Name, string Asset)> assemblies = [ - ("MSTest.TestFramework", coreAsset), - ("MSTest.TestFramework.Extensions", extensionsAsset), + ("MSTest.TestFramework", "MSTest.TestFramework", coreAsset), ]; + if (uiPackage.Length != 0) + { + assemblies.Add((uiPackage, uiPackage, $"lib/{uiTfm}")); + assemblies.Add((uiPackage, "MSTest.TestAdapter", $"buildTransitive/{uiTfm}")); + assemblies.Add((uiPackage, "MSTestAdapter.PlatformServices", $"buildTransitive/{uiTfm}")); + } + string output = Path.Join(asset.TargetAssetPath, "bin", "Release", targetFramework); string[] resolved = File.ReadAllLines(Path.Join(asset.TargetAssetPath, "resolved-framework-assets.txt")); var expectedResolved = new List(); - using ZipArchive archive = ZipFile.OpenRead(package); - foreach ((string name, string folder) in assemblies) + foreach ((string packageId, string name, string folder) in assemblies) { + string package = Path.Join(Constants.ArtifactsPackagesShipping, $"{packageId}.{MSTestVersion}.nupkg"); + string restored = Path.Join(cache, packageId.ToLowerInvariant(), MSTestVersion); + string cachedPackage = Path.Join(restored, $"{packageId.ToLowerInvariant()}.{MSTestVersion}.nupkg"); + Assert.AreEqual( + Convert.ToHexString(SHA256.HashData(File.ReadAllBytes(package))), + Convert.ToHexString(SHA256.HashData(File.ReadAllBytes(cachedPackage)))); + using ZipArchive archive = ZipFile.OpenRead(package); string relative = $"{folder}/{name}.dll"; using Stream packedAssembly = archive.GetEntry(relative)!.Open(); string hash = Convert.ToHexString(SHA256.HashData(packedAssembly)); @@ -80,7 +87,8 @@ public async Task PackedConsumersUseMatchingCoreAndExtensions( } Assert.AreSequenceEqual(expectedResolved.Order(StringComparer.Ordinal), resolved.Order(StringComparer.Ordinal)); - using Stream packedResource = archive.GetEntry($"{coreAsset}/fr/MSTest.TestFramework.resources.dll")!.Open(); + using ZipArchive corePackage = ZipFile.OpenRead(Path.Join(Constants.ArtifactsPackagesShipping, $"MSTest.TestFramework.{MSTestVersion}.nupkg")); + using Stream packedResource = corePackage.GetEntry($"{coreAsset}/fr/MSTest.TestFramework.resources.dll")!.Open(); string copiedResource = Path.Join(output, "fr", "MSTest.TestFramework.resources.dll"); Assert.AreEqual( Convert.ToHexString(SHA256.HashData(packedResource)), @@ -91,15 +99,19 @@ public async Task PackedConsumersUseMatchingCoreAndExtensions( workingDirectory: asset.TargetAssetPath, cancellationToken: TestContext.CancellationToken); Assert.AreEqual(0, exit, $"{muxer.StandardOutput}{muxer.StandardError}"); - Assert.AreEqual( - $""" + string expectedOutput = uiPackage.Length == 0 + ? $""" + {Path.Join(output, "MSTest.TestFramework.dll")} + {copiedResource} + Packed framework ownership and API shape passed. + """ + : $""" {Path.Join(output, "MSTest.TestFramework.dll")} - {Path.Join(output, "MSTest.TestFramework.Extensions.dll")} + {Path.Join(output, uiPackage + ".dll")} {copiedResource} Packed framework ownership and API shape passed. - """.ReplaceLineEndings(), - muxer.StandardOutput.ReplaceLineEndings()); - TestContext.WriteLine($"Package: {package}; cache: {restored}"); + """; + Assert.AreEqual(expectedOutput.ReplaceLineEndings(), muxer.StandardOutput.ReplaceLineEndings()); TestContext.WriteLine($"Package folders: {string.Join("; ", packageFolders)}"); TestContext.WriteLine(string.Join(Environment.NewLine, resolved)); TestContext.WriteLine(muxer.StandardOutput); @@ -124,11 +136,12 @@ Packed framework ownership and API shape passed. + $UiReference$ - <_FrameworkCompile Include="@(ReferencePath)" Condition=" ('%(Filename)' == 'MSTest.TestFramework' OR '%(Filename)' == 'MSTest.TestFramework.Extensions') AND '%(Extension)' == '.dll' " /> - <_FrameworkRuntime Include="@(ReferenceCopyLocalPaths)" Condition=" ('%(Filename)' == 'MSTest.TestFramework' OR '%(Filename)' == 'MSTest.TestFramework.Extensions') AND '%(Extension)' == '.dll' " /> + <_FrameworkCompile Include="@(ReferencePath)" Condition=" ('%(Filename)' == 'MSTest.TestFramework' OR '%(Filename)' == '$UiPackage$' OR '%(Filename)' == 'MSTest.TestAdapter' OR '%(Filename)' == 'MSTestAdapter.PlatformServices') AND '%(Extension)' == '.dll' " /> + <_FrameworkRuntime Include="@(ReferenceCopyLocalPaths)" Condition=" ('%(Filename)' == 'MSTest.TestFramework' OR '%(Filename)' == '$UiPackage$' OR '%(Filename)' == 'MSTest.TestAdapter' OR '%(Filename)' == 'MSTestAdapter.PlatformServices') AND '%(Extension)' == '.dll' " /> @@ -140,21 +153,39 @@ Packed framework ownership and API shape passed. Assembly core = typeof(TestMethodAttribute).Assembly; Assert.AreSame(core, typeof(TestContext).Assembly); - Assembly extensions = Assembly.Load("MSTest.TestFramework.Extensions"); - Assert.IsNull(extensions.GetType(typeof(TestContext).FullName!)); + Assert.IsFalse(File.Exists(Path.Join(AppContext.BaseDirectory, "MSTest.TestFramework.Extensions.dll"))); Assert.IsNotNull(core.GetType("Microsoft.VisualStudio.TestTools.UnitTesting.ITestClassInstanceFactory")); Assert.IsNotNull(core.GetType("Microsoft.VisualStudio.TestTools.UnitTesting.ITestClassInstanceLease")); - Assert.AreEqual($Desktop$, core.GetType("Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute") is not null); + Assert.IsNotNull(core.GetType("Microsoft.VisualStudio.TestTools.UnitTesting.DeploymentItemAttribute")); string[] directories = ["TestRunDirectory", "DeploymentDirectory", "ResultsDirectory", "TestRunResultsDirectory", "TestResultsDirectory", "TestTempDirectory"]; foreach (string directory in directories) { - Assert.AreEqual($Desktop$, typeof(TestContext).GetProperty(directory) is not null, directory); + Assert.IsNotNull(typeof(TestContext).GetProperty(directory), directory); } Assert.IsNull(typeof(TestContext).GetProperty("DataRow")); Assert.IsNull(typeof(TestContext).GetProperty("DataConnection")); Console.WriteLine(core.Location); - Console.WriteLine(extensions.Location); + if ("$UiPackage$".Length != 0) + { + Assembly ui = Assembly.Load("$UiPackage$"); + Assert.IsNull(ui.GetType(typeof(TestContext).FullName!)); + Assembly services = Assembly.Load("MSTestAdapter.PlatformServices"); + Type implementation = services.GetType("Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.TestContextImplementation", true)!; + var properties = directories.ToDictionary(name => name, name => (object?)"must-not-be-a-directory"); + var context = (TestContext)implementation.GetConstructors(BindingFlags.Instance | BindingFlags.NonPublic) + .Single(constructor => constructor.GetParameters().Length == 5) + .Invoke([null, null, properties, null, null]); + foreach (string directory in directories) + { + Assert.AreEqual("must-not-be-a-directory", context.Properties[directory]); + Assert.IsNull(typeof(TestContext).GetProperty(directory)!.GetValue(context), directory); + } + + ((IDisposable)context).Dispose(); + Console.WriteLine(ui.Location); + } + Console.WriteLine(core.GetSatelliteAssembly(System.Globalization.CultureInfo.GetCultureInfo("fr")).Location); Console.WriteLine("Packed framework ownership and API shape passed."); """; diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CppCliMtpTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CppCliMtpTests.cs index 6be46f0ba4..603ab242cd 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CppCliMtpTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CppCliMtpTests.cs @@ -209,9 +209,6 @@ public void Placeholder() $(ClosureDir)\MSTest.TestFramework.dll - - $(ClosureDir)\MSTest.TestFramework.Extensions.dll - diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CppCliVSTestTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CppCliVSTestTests.cs index a3de105dcf..9a1c5cd338 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CppCliVSTestTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/CppCliVSTestTests.cs @@ -169,9 +169,6 @@ private static string ExtractShippingPackage(TempDirectory destination, string p $MSTestFrameworkDir$\MSTest.TestFramework.dll - - $MSTestFrameworkDir$\MSTest.TestFramework.Extensions.dll - diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/FrameworkTargetingTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/FrameworkTargetingTests.cs index 308e12bd1b..1c0be64190 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/FrameworkTargetingTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/FrameworkTargetingTests.cs @@ -97,11 +97,10 @@ await DotnetCli.RunAsync( string importedTargets = File.ReadAllText(Path.Combine(asset.TargetAssetPath, "obj", $"{assetName}.csproj.nuget.g.targets")) .Replace('\\', '/'); Assert.Contains($"buildTransitive/{targetFramework}/MSTest.TestAdapter.targets", importedTargets); - Assert.Contains($"buildTransitive/{targetFramework}/MSTest.TestFramework.targets", importedTargets); + Assert.Contains("buildTransitive/MSTest.TestFramework.targets", importedTargets); var host = TestHost.LocateFrom(asset.TargetAssetPath, assetName, targetFramework); await AssertMatchingAssemblyAsync("MSTest.TestFramework", MSTestVersion, $"lib/{targetFramework}/MSTest.TestFramework.dll", host.DirectoryName); - await AssertMatchingAssemblyAsync("MSTest.TestFramework", MSTestVersion, $"buildTransitive/{targetFramework}/MSTest.TestFramework.Extensions.dll", host.DirectoryName); await AssertMatchingAssemblyAsync("MSTest.TestAdapter", MSTestVersion, $"buildTransitive/{targetFramework}/MSTest.TestAdapter.dll", host.DirectoryName); await AssertMatchingAssemblyAsync("MSTest.TestAdapter", MSTestVersion, $"buildTransitive/{targetFramework}/MSTestAdapter.PlatformServices.dll", host.DirectoryName); await AssertMatchingAssemblyAsync("Microsoft.Testing.Platform", MicrosoftTestingPlatformVersion, $"lib/{targetFramework}/Microsoft.Testing.Platform.dll", host.DirectoryName); diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ModernUwpTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ModernUwpTests.cs index 5a13169654..7c379e54d6 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ModernUwpTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/ModernUwpTests.cs @@ -54,11 +54,12 @@ public async Task ModernUwp_BuildsMtpPackageForArchitecture(string platform) Net10TargetFramework); } - [DataRow(Net10TargetFramework)] - [DataRow(Net11TargetFramework)] + [DataRow(Net10TargetFramework, false, DisplayName = "ModernUwp_Net10")] + [DataRow(Net11TargetFramework, false, DisplayName = "ModernUwp_Net11")] + [DataRow(Net10TargetFramework, true, DisplayName = "ModernUwp_UnsupportedDeployment")] [TestMethod] [OSCondition(OperatingSystems.Windows, IgnoreMessage = "Modern UWP execution is supported only on Windows.")] - public async Task ModernUwp_ConsumesUwpAssets_AndRunsPlainAndUiTestsThroughMtp(string targetFramework) + public async Task ModernUwp_ConsumesUwpAssets_AndRunsPlainAndUiTestsThroughMtp(string targetFramework, bool unsupportedDeployment) { string uniqueSuffix = Guid.NewGuid().ToString("N"); string assetName = $"ModernUwp{uniqueSuffix[..12]}"; @@ -69,6 +70,10 @@ public async Task ModernUwp_ConsumesUwpAssets_AndRunsPlainAndUiTestsThroughMtp(s .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion) .PatchCodeWithReplace("$MicrosoftTestingPlatformVersion$", MicrosoftTestingPlatformVersion) .PatchCodeWithReplace("$TargetFramework$", targetFramework); + if (unsupportedDeployment) + { + sourceCode += UnsupportedDeploymentSource.PatchCodeWithReplace("$AssetName$", assetName); + } TestAsset testAsset = await TestAsset.GenerateAssetAsync(assetName, sourceCode); string executionDirectory = Path.Combine(Path.GetTempPath(), nameof(ModernUwpTests), uniqueSuffix); @@ -129,7 +134,7 @@ await WindowsApplicationModelTestTools.ExecuteWithPackageCleanupAsync( TestContext.CancellationToken); Assert.AreEqual( - 0, + unsupportedDeployment ? 1 : 0, run.ExitCode, $"MTP failed to execute the real Modern UWP project '{build.ProjectPath}'. TRX: '{run.TrxPath}'. " + $"Binlog: '{build.BinlogPath}'.{Environment.NewLine}Standard output:{Environment.NewLine}{run.StandardOutput}" + @@ -145,7 +150,7 @@ await WindowsApplicationModelTestTools.ExecuteWithPackageCleanupAsync( run.StandardOutput, $"MTP reported zero discovered tests for '{build.ProjectPath}'."); - AssertModernUwpTrx(run.TrxPath, build); + AssertModernUwpTrx(run.TrxPath, build, unsupportedDeployment); }); cleanupSucceeded = true; } @@ -177,7 +182,7 @@ private static async Task EnsureGeneratedCSharpFilesHaveUtf8BomAsync( } } - private static void AssertModernUwpTrx(string trxPath, UwpBuildResult build) + private static void AssertModernUwpTrx(string trxPath, UwpBuildResult build, bool unsupportedDeployment) { Assert.IsTrue( File.Exists(trxPath), @@ -186,29 +191,37 @@ private static void AssertModernUwpTrx(string trxPath, UwpBuildResult build) XNamespace ns = "http://microsoft.com/schemas/VisualStudio/TeamTest/2010"; var trx = XDocument.Load(trxPath); XElement[] results = [.. trx.Descendants(ns + "UnitTestResult")]; - Assert.HasCount(2, results, $"Expected exactly the plain and UI Modern UWP tests in '{trxPath}'."); - - string[] actualTestNames = results - .Select(result => (string?)result.Attribute("testName")) - .Where(name => name is not null) - .Cast() - .Order(StringComparer.Ordinal) - .ToArray(); - string[] expectedTestNames = + int failures = unsupportedDeployment ? 2 : 0; + string[] expectedResults = unsupportedDeployment + ? + [ + "InheritedClassDeployment:Failed", + "InheritedMethodDeployment:Failed", + "PlainTestMethod_RunsInPackagedUwp:Passed", + "UITestMethod_RunsOnCoreWindowDispatcher:Passed", + ] + : [ - "PlainTestMethod_RunsInPackagedUwp", - "UITestMethod_RunsOnCoreWindowDispatcher", + "PlainTestMethod_RunsInPackagedUwp:Passed", + "UITestMethod_RunsOnCoreWindowDispatcher:Passed", ]; - Assert.AreSequenceEqual(expectedTestNames, actualTestNames, $"Unexpected test results were written to '{trxPath}'."); - Assert.IsTrue( - results.All(result => (string?)result.Attribute("outcome") == "Passed"), - $"Every Modern UWP result must pass. TRX: '{trxPath}'."); + Assert.AreSequenceEqual( + expectedResults, + results.Select(result => $"{result.Attribute("testName")!.Value}:{result.Attribute("outcome")!.Value}").Order(StringComparer.Ordinal), + $"Unexpected Modern UWP identities/outcomes in '{trxPath}'."); + foreach (XElement result in results.Where(result => (string?)result.Attribute("outcome") == "Failed")) + { + Assert.Contains( + "DeploymentItemAttribute is not supported by UWP or WinUI test hosts.", + result.Descendants(ns + "Message").Single().Value); + Assert.DoesNotContain("DEPLOYMENT_BODY_EXECUTED", result.Value); + } XElement counters = trx.Descendants(ns + "Counters").Single(); - AssertCounter(counters, "total", 2, trxPath); - AssertCounter(counters, "executed", 2, trxPath); + AssertCounter(counters, "total", 2 + failures, trxPath); + AssertCounter(counters, "executed", 2 + failures, trxPath); AssertCounter(counters, "passed", 2, trxPath); - AssertCounter(counters, "failed", 0, trxPath); + AssertCounter(counters, "failed", failures, trxPath); AssertCounter(counters, "error", 0, trxPath); AssertCounter(counters, "inconclusive", 0, trxPath); AssertCounter(counters, "notExecuted", 0, trxPath); @@ -220,6 +233,34 @@ private static void AssertCounter(XElement counters, string name, int expected, (string?)counters.Attribute(name), $"Unexpected '{name}' counter in '{trxPath}'."); + private const string UnsupportedDeploymentSource = """ + + #file UnsupportedDeploymentTests.cs + using Microsoft.VisualStudio.TestTools.UnitTesting; + + namespace $AssetName$; + + public abstract class MethodDeploymentBase + { + [TestMethod] + [DeploymentItem("not-deployed.txt")] + public void InheritedMethodDeployment() => Assert.Fail("DEPLOYMENT_BODY_EXECUTED"); + } + + [TestClass] + public sealed class InheritedMethodDeploymentTests : MethodDeploymentBase; + + [DeploymentItem("not-deployed.txt")] + public abstract class ClassDeploymentBase; + + [TestClass] + public sealed class InheritedClassDeploymentTests : ClassDeploymentBase + { + [TestMethod] + public void InheritedClassDeployment() => Assert.Fail("DEPLOYMENT_BODY_EXECUTED"); + } + """; + private const string ModernUwpSourceCode = """ #file $AssetName$.csproj @@ -404,11 +445,28 @@ namespace $AssetName$; [TestClass] public sealed class ModernUwpPackageTests { + public TestContext TestContext { get; set; } = null!; + [TestMethod] public void PlainTestMethod_RunsInPackagedUwp() { Assert.AreEqual("$PackageIdentityName$", Package.Current.Id.Name); Assert.IsFalse(string.IsNullOrWhiteSpace(Package.Current.Id.FamilyName)); + string[] directories = ["TestRunDirectory", "DeploymentDirectory", "ResultsDirectory", "TestRunResultsDirectory", "TestResultsDirectory", "TestTempDirectory"]; + foreach (string directory in directories) + { + TestContext.Properties[directory] = "not-a-ui-directory"; + } + + Assert.IsNull(TestContext.TestRunDirectory); + Assert.IsNull(TestContext.DeploymentDirectory); + Assert.IsNull(TestContext.ResultsDirectory); + Assert.IsNull(TestContext.TestRunResultsDirectory); + Assert.IsNull(TestContext.TestResultsDirectory); + Assert.IsNull(TestContext.TestTempDirectory); + TestContext.WriteLine(typeof(TestContext).Assembly.Location); + TestContext.WriteLine(typeof(UITestMethodAttribute).Assembly.Location); + TestContext.WriteLine(TestContext.GetType().Assembly.Location); } [UITestMethod] diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.Composition.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.Composition.cs new file mode 100644 index 0000000000..7c66611069 --- /dev/null +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.Composition.cs @@ -0,0 +1,522 @@ +// 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.Security.Cryptography; +using System.Text.Json; + +using Microsoft.Testing.Platform.Acceptance.IntegrationTests; +using Microsoft.Testing.Platform.Acceptance.IntegrationTests.Helpers; + +namespace MSTest.Acceptance.IntegrationTests; + +public sealed partial class SdkTests +{ + private const string CompositionCentralPackageManagementSource = """ + + #file Directory.Packages.props + + + true + false + + + """; + + [TestMethod] + [TestCategory("WindowsApplicationModel")] + [DataRow("Default", "MSTest.TestAdapter", false)] + [DataRow("Default", "MSTest.TestAdapter", true)] + [DataRow("Uwp", "MSTest.Uwp", false)] + [DataRow("Uwp", "MSTest.Uwp", true)] + [DataRow("WinUI", "MSTest.WinUI", false)] + [DataRow("WinUI", "MSTest.WinUI", true)] + public async Task MSTestSdk_ExplicitApplicationModel_SelectsCompositionBeforeLateToolingImports( + string applicationModel, string expectedAdapterPackageId, bool useCentralPackageManagement) + { + string lateProperties = applicationModel switch + { + "Uwp" => "true", + "WinUI" => "true", + _ => "false", + }; + string earlyProperties = applicationModel == "Default" ? "true" : string.Empty; + DotnetMuxerResult result = await EvaluateWindowsApplicationModelAsync( + $"Explicit{applicationModel}Sdk", + $""" + {applicationModel} + None + {earlyProperties} + """, + expectedAdapterPackageId: expectedAdapterPackageId, + useCentralPackageManagement: useCentralPackageManagement, + lateApplicationModelProperties: lateProperties); + + result.AssertOutputContains($";Model={applicationModel};AdapterPackage={expectedAdapterPackageId};EndComposition"); + } + + [TestMethod] + [OSCondition(OperatingSystems.Windows)] + [DataRow("MSTest.TestAdapter", "MSTest.Uwp")] + [DataRow("MSTest.TestAdapter", "MSTest.WinUI")] + [DataRow("MSTest.Uwp", "MSTest.WinUI")] + public async Task ExplicitPackages_RejectConflictingAdaptersBeforeCompilation(string firstPackage, string secondPackage) + { + using TestAsset asset = await TestAsset.GenerateAssetAsync( + "ConflictingMSTestPackages", + $$""" + #file ConflictingMSTestPackages.csproj + + + net11.0-windows10.0.26100.0 + + + + + + + """); + DotnetMuxerResult result = await DotnetCli.RunAsync( + "msbuild -restore -t:PrepareForBuild -bl:conflicting-adapters.binlog", + workingDirectory: asset.TargetAssetPath, + failIfReturnValueIsNotZero: false, + cancellationToken: TestContext.CancellationToken); + result.AssertExitCodeIs(1); + result.AssertOutputContains("Reference exactly one MSTest adapter composition: MSTest.TestAdapter, MSTest.Uwp, or MSTest.WinUI."); + } + + [TestMethod] + [TestCategory("WindowsApplicationModel")] + [OSCondition(OperatingSystems.Windows, IgnoreMessage = "Classic UWP requires desktop MSBuild and the UWP workload.")] + [MemberCondition( + typeof(AcceptanceTestBase), + nameof(AcceptanceTestBase.IsWindowsApplicationModelTestEnvironment), + IgnoreMessage = "Requires the dedicated preflight-gated Windows application-model test environment.")] + public async Task MSTestSdk_ClassicUwpTargetFramework_InfersUwpComposition() + { + const string Source = """ + #file ClassicUwp.csproj + + + + + uap10.0.16299 + 10.0.16299.0 + 10.0.16299.0 + AppContainerExe + x64 + x64 + false + true + true + false + None + + + + + + + + + + + + """; + + using TestAsset testAsset = await TestAsset.GenerateAssetAsync( + "ClassicUwpCompositionSdk", + Source + .PatchCodeWithReplace("$MSBuildSdkExtrasVersion$", MSBuildSdkExtrasVersion) + .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion)); + VisualStudioTestTools tools = await WindowsApplicationModelTestTools.LocateClassicUwpVisualStudioToolsAsync(TestContext.CancellationToken); + string projectPath = Path.Combine(testAsset.TargetAssetPath, "ClassicUwp.csproj"); + BoundedCommandLineResult result = await RunWindowsApplicationModelCommandAsync( + $"\"{tools.MSBuildPath}\" \"{projectPath}\" /restore /t:PrintClassicComposition /p:Configuration=Release /p:Platform=x64 /bl:\"{Path.Combine(testAsset.TargetAssetPath, "classic-uwp.binlog")}\"", + testAsset.TargetAssetPath, + TestContext.CancellationToken); + Assert.AreEqual(0, result.ExitCode, $"{result.StandardOutput}{Environment.NewLine}{result.ErrorOutput}"); + Assert.Contains("ClassicComposition:Model=Uwp;AdapterPackage=MSTest.Uwp;EndComposition", result.StandardOutput); + await AssertResolvedMSTestCompositionAsync(testAsset.TargetAssetPath, "uap10.0.16299", "MSTest.Uwp"); + await AssertResolvedMSTestReferencesAsync(testAsset.TargetAssetPath, "MSTest.Uwp"); + } + + [TestMethod] + [TestCategory("WindowsApplicationModel")] + [DataRow("Default", "MSTest.TestAdapter")] + [DataRow("Uwp", "MSTest.Uwp")] + [DataRow("WinUI", "MSTest.WinUI")] + public async Task MSTestSdk_UwpToolingOptOut_RespectsExplicitApplicationModel(string applicationModel, string expectedAdapterPackageId) + { + DotnetMuxerResult result = await EvaluateWindowsApplicationModelAsync( + $"UwpToolingOptOut{applicationModel}Sdk", + $""" + {applicationModel} + true + false + None + """, + expectedAdapterPackageId: expectedAdapterPackageId); + + result.AssertOutputContains($";Model={applicationModel};AdapterPackage={expectedAdapterPackageId};EndComposition"); + } + + [TestMethod] + [TestCategory("WindowsApplicationModel")] + [DataRow("Default", "NativeAOT", "MSTest.TestAdapter")] + [DataRow("Uwp", "NativeAOT", "MSTest.Uwp")] + [DataRow("WinUI", "NativeAOT", "MSTest.WinUI")] + [DataRow("Uwp", "VSTest", "MSTest.Uwp")] + [DataRow("WinUI", "VSTest", "MSTest.WinUI")] + public async Task MSTestSdk_AdapterInjection_UsesSelectedCompositionWithCentralPackageManagement( + string applicationModel, string runner, string expectedAdapterPackageId) + { + string runnerProperties = runner == "VSTest" + ? "true" + : "truewin-x64None"; + DotnetMuxerResult result = await EvaluateWindowsApplicationModelAsync( + $"{applicationModel}{runner}CompositionSdk", + $""" + {applicationModel} + None + {runnerProperties} + """, + expectedAdapterPackageId: expectedAdapterPackageId, + useCentralPackageManagement: true); + + result.AssertOutputContains($";Model={applicationModel};AdapterPackage={expectedAdapterPackageId};EndComposition"); + if (runner == "NativeAOT") + { + result.AssertOutputContains("MSTest.SourceGeneration"); + } + } + + [TestMethod] + [TestCategory("WindowsApplicationModel")] + [DataRow("Desktop", "", "Invalid value 'Desktop' for MSTestApplicationModel.", DisplayName = "Unknown application model")] + [DataRow("Default", "true", "MSTestApplicationModel 'Default' conflicts", DisplayName = "Ordinary model conflicts with WinUI")] + [DataRow("Default", "true", "MSTestApplicationModel 'Default' conflicts", DisplayName = "Ordinary model conflicts with UWP tooling")] + [DataRow("Default", "true", "MSTestApplicationModel 'Default' conflicts", DisplayName = "Ordinary model conflicts with inferred UWP")] + [DataRow("Uwp", "true", "MSTestApplicationModel 'Uwp' conflicts", DisplayName = "UWP model conflicts with WinUI")] + [DataRow("WinUI", "true", "MSTestApplicationModel 'WinUI' conflicts", DisplayName = "WinUI model conflicts with UWP tooling")] + [DataRow("WinUI", "true", "MSTestApplicationModel 'WinUI' conflicts", DisplayName = "WinUI model conflicts with inferred UWP")] + public async Task MSTestSdk_ApplicationModel_RejectsInvalidOrConflictingChoices( + string applicationModel, string toolingProperties, string expectedError) + { + DotnetMuxerResult result = await EvaluateWindowsApplicationModelAsync( + "InvalidApplicationModelSdk", + $""" + {applicationModel} + None + {toolingProperties} + """, + failIfReturnValueIsNotZero: false); + + Assert.AreNotEqual(0, result.ExitCode); + result.AssertOutputContains(expectedError); + } + + [TestMethod] + [TestCategory("WindowsApplicationModel")] + [DataRow("Default", false, null)] + [DataRow("Default", true, "MSTest.TestAdapter")] + [DataRow("Uwp", false, "MSTest.Uwp")] + [DataRow("Uwp", true, "MSTest.Uwp")] + [DataRow("WinUI", false, "MSTest.WinUI")] + [DataRow("WinUI", true, "MSTest.WinUI")] + public async Task MSTestSdk_Helper_KeepsOnlyRequiredCompileTimeComposition( + string applicationModel, bool enableSourceGeneration, string? expectedAdapterPackageId) + { + const string Source = """ + #file Helper.csproj + + + $TargetFramework$ + true + false + $ApplicationModel$ + $EnableSourceGeneration$ + true + + + + <_HelperBuilderHooks>@(TestingPlatformBuilderHook) + + + + + + + + #file HelperTests.cs + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class HelperTests + { + [$TestMethodAttribute$] + public void TestFromHelper() => Assert.AreEqual("Helper", typeof(HelperTests).Assembly.GetName().Name); + } + """; + + string targetFramework = applicationModel == "Default" ? TargetFrameworks.NetCurrent : $"{TargetFrameworks.NetCurrent}-windows10.0.26100.0"; + string source = Source + .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion) + .PatchCodeWithReplace("$TargetFramework$", targetFramework) + .PatchCodeWithReplace("$ApplicationModel$", applicationModel) + .PatchCodeWithReplace("$TestMethodAttribute$", applicationModel == "Default" ? "TestMethod" : "Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer.UITestMethod") + .PatchCodeWithReplace("$EnableSourceGeneration$", enableSourceGeneration.ToString()); + if (enableSourceGeneration) + { + source += CompositionCentralPackageManagementSource; + } + + using TestAsset testAsset = await TestAsset.GenerateAssetAsync($"{applicationModel}HelperSdk", source); + DotnetMuxerResult result = await DotnetCli.RunAsync( + $"build \"{testAsset.TargetAssetPath}\" -c Release -bl:\"{Path.Combine(testAsset.TargetAssetPath, "helper.binlog")}\"", + cancellationToken: TestContext.CancellationToken); + result.AssertExitCodeIs(0); + + await AssertResolvedMSTestCompositionAsync(testAsset.TargetAssetPath, targetFramework, expectedAdapterPackageId); + await AssertResolvedMSTestReferencesAsync(testAsset.TargetAssetPath, expectedAdapterPackageId); + string[] copyLocal = await File.ReadAllLinesAsync(Path.Combine(testAsset.TargetAssetPath, "copy-local-assets.txt"), TestContext.CancellationToken); + Assert.DoesNotContain(IsMSTestApplicationPayload, copyLocal); + Assert.DoesNotContain( + "031F8871-2660-4208-8F6B-FC142B40ABFF", + await File.ReadAllTextAsync(Path.Combine(testAsset.TargetAssetPath, "builder-hooks.txt"), TestContext.CancellationToken)); + Assert.IsEmpty(Directory.GetFiles(Path.Combine(testAsset.TargetAssetPath, "bin", "Release", targetFramework), "*.dll", SearchOption.AllDirectories) + .Where(IsMSTestApplicationPayload)); + await AssertGeneratedHelperSourcesAsync(testAsset.TargetAssetPath, targetFramework, enableSourceGeneration); + } + + [TestMethod] + [TestCategory("WindowsApplicationModel")] + [DataRow("Uwp", false)] + [DataRow("WinUI", true)] + public async Task MSTestSdk_UiApplication_WithOrdinarySourceGeneratedHelper_DoesNotResolveOrdinaryAdapter( + string applicationModel, bool useCentralPackageManagement) + { + const string Source = """ + #file Application.csproj + + + $UiTargetFramework$ + true + true + $ApplicationModel$ + None + false + None + Exe + + + + + + + + + + + #file ApplicationTests.cs + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public sealed class ApplicationTests : HelperTests; + + #file Helper/Helper.csproj + + + $TargetFramework$ + false + true + true + + + + #file Helper/HelperTests.cs + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public class HelperTests + { + [TestMethod] + public void TestFromHelper() => Assert.AreEqual("Helper", typeof(HelperTests).Assembly.GetName().Name); + } + """; + + string uiTargetFramework = $"{TargetFrameworks.NetCurrent}-windows10.0.26100.0"; + string source = Source + .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion) + .PatchCodeWithReplace("$UiTargetFramework$", uiTargetFramework) + .PatchCodeWithReplace("$TargetFramework$", TargetFrameworks.NetCurrent) + .PatchCodeWithReplace("$ApplicationModel$", applicationModel); + if (useCentralPackageManagement) + { + source += CompositionCentralPackageManagementSource; + } + + using TestAsset testAsset = await TestAsset.GenerateAssetAsync($"{applicationModel}ApplicationWithHelperSdk", source); + DotnetMuxerResult result = await DotnetCli.RunAsync( + $"build \"{testAsset.TargetAssetPath}\" -c Release -bl:\"{Path.Combine(testAsset.TargetAssetPath, "application.binlog")}\"", + cancellationToken: TestContext.CancellationToken); + result.AssertExitCodeIs(0); + + string expectedAdapterPackageId = $"MSTest.{applicationModel}"; + await AssertResolvedMSTestCompositionAsync(testAsset.TargetAssetPath, uiTargetFramework, expectedAdapterPackageId); + await AssertResolvedMSTestReferencesAsync(testAsset.TargetAssetPath, expectedAdapterPackageId); + string helperDirectory = Path.Combine(testAsset.TargetAssetPath, "Helper"); + await AssertResolvedMSTestCompositionAsync(helperDirectory, TargetFrameworks.NetCurrent, "MSTest.TestAdapter"); + await AssertGeneratedHelperSourcesAsync(helperDirectory, TargetFrameworks.NetCurrent, enableSourceGeneration: true); + + string[] references = await File.ReadAllLinesAsync(Path.Combine(testAsset.TargetAssetPath, "resolved-mstest-assets.txt"), TestContext.CancellationToken); + foreach (string assembly in new[] { "MSTest.TestAdapter.dll", "MSTestAdapter.PlatformServices.dll" }) + { + string packagePath = Assert.ContainsSingle(references.Where(path => path.EndsWith(assembly, StringComparison.OrdinalIgnoreCase))); + string applicationPath = Path.Combine(testAsset.TargetAssetPath, "bin", "Release", uiTargetFramework, assembly); + Assert.AreSequenceEqual( + SHA256.HashData(await File.ReadAllBytesAsync(packagePath, TestContext.CancellationToken)), + SHA256.HashData(await File.ReadAllBytesAsync(applicationPath, TestContext.CancellationToken)), + $"The application must copy {assembly} from {expectedAdapterPackageId}, not its ordinary helper."); + Assert.IsFalse(File.Exists(Path.Combine(helperDirectory, "bin", "Release", TargetFrameworks.NetCurrent, assembly))); + } + } + + [TestMethod] + [TestCategory("WindowsApplicationModel")] + [DataRow("Uwp", false)] + [DataRow("Uwp", true)] + [DataRow("WinUI", false)] + [DataRow("WinUI", true)] + public async Task MSTestSdk_MixedOrdinaryAndUiTargetFrameworks_SelectOneCompositionPerInnerFramework( + string applicationModel, bool useCentralPackageManagement) + { + const string ReportTarget = """ + + + + + + """; + string uiTargetFramework = $"{TargetFrameworks.NetCurrent}-windows10.0.26100.0"; + string source = SingleTestSourceCode + .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion) + .PatchCodeWithReplace("$TargetFramework$", $"{TargetFrameworks.NetCurrent};{uiTargetFramework}") + .PatchCodeWithReplace("$ExtraProperties$", $""" + true + None + false + None + {applicationModel} + """) + .PatchCodeWithReplace("", ReportTarget); + if (useCentralPackageManagement) + { + source += CompositionCentralPackageManagementSource; + } + + using TestAsset testAsset = await TestAsset.GenerateAssetAsync($"Mixed{applicationModel}CompositionSdk", source); + DotnetMuxerResult result = await DotnetCli.RunAsync( + $"build \"{testAsset.TargetAssetPath}\" -c Release -bl:\"{Path.Combine(testAsset.TargetAssetPath, "multi-tfm.binlog")}\"", + cancellationToken: TestContext.CancellationToken); + result.AssertExitCodeIs(0); + + result.AssertOutputContains($"InnerComposition:TargetFramework={TargetFrameworks.NetCurrent};Model=Default;AdapterPackage=MSTest.TestAdapter;EndComposition"); + result.AssertOutputContains($"InnerComposition:TargetFramework={uiTargetFramework};Model={applicationModel};AdapterPackage=MSTest.{applicationModel};EndComposition"); + await AssertResolvedMSTestCompositionAsync(testAsset.TargetAssetPath, TargetFrameworks.NetCurrent, "MSTest.TestAdapter"); + await AssertResolvedMSTestCompositionAsync(testAsset.TargetAssetPath, uiTargetFramework, $"MSTest.{applicationModel}"); + await AssertResolvedMSTestReferencesAsync(testAsset.TargetAssetPath, "MSTest.TestAdapter", $"resolved-mstest-assets-{TargetFrameworks.NetCurrent}.txt"); + await AssertResolvedMSTestReferencesAsync(testAsset.TargetAssetPath, $"MSTest.{applicationModel}", $"resolved-mstest-assets-{uiTargetFramework}.txt"); + } + + private static bool IsMSTestApplicationPayload(string path) + => Path.GetFileName(path) is "MSTest.TestAdapter.dll" or "MSTestAdapter.PlatformServices.dll" or "MSTest.Uwp.dll" or "MSTest.WinUI.dll" + or "MSTest.TestAdapter.resources.dll" or "MSTestAdapter.PlatformServices.resources.dll" or "MSTest.Uwp.resources.dll" or "MSTest.WinUI.resources.dll"; + + private async Task AssertGeneratedHelperSourcesAsync(string projectDirectory, string targetFramework, bool enableSourceGeneration) + { + string generatedDirectory = Path.Combine(projectDirectory, "obj", "Release", targetFramework, "generated"); + string[] files = Directory.Exists(generatedDirectory) + ? Directory.GetFiles(generatedDirectory, "*MSTestReflectionMetadata*.g.cs", SearchOption.AllDirectories) + : []; + Assert.HasCount(enableSourceGeneration ? 3 : 0, files, generatedDirectory); + if (enableSourceGeneration) + { + string registration = Assert.ContainsSingle(files.Where(path => path.EndsWith("MSTestReflectionMetadata.Registration.g.cs", StringComparison.Ordinal))); + Assert.Contains("ReflectionMetadataHook.Register", await File.ReadAllTextAsync(registration, TestContext.CancellationToken)); + } + } + + private async Task AssertResolvedMSTestCompositionAsync(string projectDirectory, string targetFramework, string? expectedAdapterPackageId) + { + using var assets = JsonDocument.Parse( + await File.ReadAllTextAsync(Path.Combine(projectDirectory, "obj", "project.assets.json"), TestContext.CancellationToken)); + JsonProperty framework = Assert.ContainsSingle( + assets.RootElement.GetProperty("project").GetProperty("frameworks").EnumerateObject() + .Where(property => property.Name == targetFramework || property.Value.GetProperty("targetAlias").GetString() == targetFramework)); + // Inspect only this inner framework's resolved closure, never the union of all assets targets. + JsonElement targets = assets.RootElement.GetProperty("targets"); + string targetName = framework.Name; + if (targetFramework.StartsWith("uap", StringComparison.Ordinal) && !targets.TryGetProperty(targetName, out _)) + { + targetName = $"UAP,Version=v{targetFramework["uap".Length..]}"; + } + + JsonElement target = targets.GetProperty(targetName); + string[] compositionPackages = + [ + "MSTest.TestFramework", "MSTest.TestFramework.Extensions", "MSTest.TestAdapter", "MSTest.Uwp", "MSTest.WinUI", + ]; + string[] actual = target.EnumerateObject() + .Where(package => compositionPackages.Any(id => package.Name.StartsWith($"{id}/", StringComparison.OrdinalIgnoreCase))) + .Select(package => package.Name) + .Order(StringComparer.Ordinal) + .ToArray(); + string[] expected = expectedAdapterPackageId is null + ? [$"MSTest.TestFramework/{MSTestVersion}"] + : [$"MSTest.TestFramework/{MSTestVersion}", $"{expectedAdapterPackageId}/{MSTestVersion}"]; + Assert.AreSequenceEqual(expected.Order(StringComparer.Ordinal).ToArray(), actual, targetFramework); + + string? uiAsset = expectedAdapterPackageId switch + { + "MSTest.Uwp" when targetFramework.StartsWith("uap", StringComparison.Ordinal) => "lib/uap10.0.16299/MSTest.Uwp.dll", + "MSTest.Uwp" => "lib/net10.0-windows10.0.17763/MSTest.Uwp.dll", + "MSTest.WinUI" => "lib/net10.0-windows10.0.18362/MSTest.WinUI.dll", + _ => null, + }; + if (uiAsset is not null) + { + JsonElement compile = target.GetProperty($"{expectedAdapterPackageId}/{MSTestVersion}").GetProperty("compile"); + Assert.Contains(uiAsset, compile.EnumerateObject().Select(asset => asset.Name), targetFramework); + } + } + + private async Task AssertResolvedMSTestReferencesAsync(string projectDirectory, string? expectedAdapterPackageId, string reportName = "resolved-mstest-assets.txt") + { + string[] references = await File.ReadAllLinesAsync(Path.Combine(projectDirectory, reportName), TestContext.CancellationToken); + Assert.ContainsSingle(references.Where(path => path.EndsWith("MSTest.TestFramework.dll", StringComparison.OrdinalIgnoreCase))); + Assert.DoesNotContain(path => path.EndsWith("MSTest.TestFramework.Extensions.dll", StringComparison.OrdinalIgnoreCase), references); + foreach (string assembly in new[] { "MSTest.TestAdapter.dll", "MSTestAdapter.PlatformServices.dll", "MSTest.Uwp.dll", "MSTest.WinUI.dll" }) + { + string[] matches = references.Where(path => path.EndsWith(assembly, StringComparison.OrdinalIgnoreCase)).ToArray(); + if (expectedAdapterPackageId is null + || (assembly == "MSTest.Uwp.dll" && expectedAdapterPackageId != "MSTest.Uwp") + || (assembly == "MSTest.WinUI.dll" && expectedAdapterPackageId != "MSTest.WinUI")) + { + Assert.IsEmpty(matches, assembly); + } + else + { + string path = Assert.ContainsSingle(matches).Replace('\\', '/').ToLowerInvariant(); + Assert.Contains($"/{expectedAdapterPackageId.ToLowerInvariant()}/{MSTestVersion.ToLowerInvariant()}/", path, assembly); + } + } + } +} diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.cs index 688f5ad7d6..8e6fb47ec0 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.cs @@ -14,7 +14,7 @@ namespace MSTest.Acceptance.IntegrationTests; [TestClass] -public sealed class SdkTests : AcceptanceTestBase +public sealed partial class SdkTests : AcceptanceTestBase { private const string AssetName = "MSTestSdk"; @@ -425,11 +425,13 @@ public async Task SatelliteResourceLanguages_FiltersClassicUwpAdapterResources(s - + - + + @@ -467,11 +469,13 @@ public async Task SatelliteResourceLanguages_FiltersClassicUwpMtpAdapterResource - + - + + @@ -805,9 +809,11 @@ public async Task SettingIsTestApplicationToFalseReducesAddedExtensionsAndMakesP SL.Task cscTask = binLog.FindChildrenRecursive(task => task.Name == "Csc").Single(); SL.Item[] references = [.. cscTask.FindChildrenRecursive(p => p.Name == "References").Single().Children.OfType()]; - // Ensure that MSTest.Framework is referenced + // Ordinary helpers reference only the shared framework, not the retired extensions assembly. Assert.Contains(r => r.Text.EndsWith("MSTest.TestFramework.dll", StringComparison.OrdinalIgnoreCase), references); - Assert.Contains(r => r.Text.EndsWith("MSTest.TestFramework.Extensions.dll", StringComparison.OrdinalIgnoreCase), references); + Assert.DoesNotContain(r => r.Text.EndsWith("MSTest.TestFramework.Extensions.dll", StringComparison.OrdinalIgnoreCase), references); + Assert.DoesNotContain(r => r.Text.EndsWith("MSTest.Uwp.dll", StringComparison.OrdinalIgnoreCase), references); + Assert.DoesNotContain(r => r.Text.EndsWith("MSTest.WinUI.dll", StringComparison.OrdinalIgnoreCase), references); // No adapter, no extensions, no vstest sdk Assert.DoesNotContain(r => r.Text.EndsWith("MSTest.TestAdapter.dll", StringComparison.OrdinalIgnoreCase), references); @@ -1244,20 +1250,24 @@ public void TestMethod1() [TestMethod] [TestCategory("WindowsApplicationModel")] [OSCondition(OperatingSystems.Windows, IgnoreMessage = "UWP is Windows-only.")] - public async Task MSTestSdk_ModernUwp_DefaultsToMtpWithAppModelController() + [DataRow("net10.0-windows10.0.26100.0", "net10.0")] + [DataRow("net11.0-windows10.0.26100.0", "net11.0")] + public async Task MSTestSdk_ModernUwp_DefaultsToMtpWithAppModelController(string targetFramework, string controllerTfm) { DotnetMuxerResult result = await EvaluateWindowsApplicationModelAsync( "ModernUwpSdk", """ true <_IncludeApplicationDefinition>true - """); + """, + targetFramework: targetFramework, + expectedAdapterPackageId: "MSTest.Uwp"); result.AssertOutputContains("WindowsTestContract:UseVSTest=false;GenerateEntryPoint=false;GenerateHelper=true;PackagedApp=true"); result.AssertOutputContains("Controller=mstest-appmodel-controller.exe"); - result.AssertOutputContains("ControllerTfm=net11.0"); + result.AssertOutputContains($"ControllerTfm={controllerTfm}"); result.AssertOutputContains("ControllerExtensions=msbuild;packagedapp;codecoverage;trx;mstest;EndContract"); - result.AssertOutputContains("MSTest.TestAdapter"); + result.AssertOutputContains("MSTest.Uwp"); result.AssertOutputContains("MSTest.TestFramework"); result.AssertOutputContains("Microsoft.Testing.Extensions.PackagedApp"); result.AssertOutputContains("TestContainer"); @@ -1276,7 +1286,8 @@ public async Task MSTestSdk_ModernUwp_AllowsExplicitMtpSelection() true false <_IncludeApplicationDefinition>true - """); + """, + expectedAdapterPackageId: "MSTest.Uwp"); result.AssertOutputContains("WindowsTestContract:UseVSTest=false;GenerateEntryPoint=false;GenerateHelper=true;PackagedApp=true"); result.AssertOutputContains("Controller=mstest-appmodel-controller.exe"); @@ -1375,10 +1386,19 @@ public void UseUwpToolsFalse_RunsThroughDirectMtp() string adapterPath = resolvedAssets.Single( path => path.EndsWith("MSTest.TestAdapter.dll", StringComparison.OrdinalIgnoreCase)); - string frameworkExtensionsPath = resolvedAssets.Single( - path => path.EndsWith("MSTest.TestFramework.Extensions.dll", StringComparison.OrdinalIgnoreCase)); + string frameworkPath = resolvedAssets.Single( + path => path.EndsWith("MSTest.TestFramework.dll", StringComparison.OrdinalIgnoreCase)); Assert.DoesNotContain($"{Path.DirectorySeparatorChar}uwp{Path.DirectorySeparatorChar}", adapterPath, adapterPath); - Assert.DoesNotContain($"{Path.DirectorySeparatorChar}uwp{Path.DirectorySeparatorChar}", frameworkExtensionsPath, frameworkExtensionsPath); + Assert.DoesNotContain($"{Path.DirectorySeparatorChar}uwp{Path.DirectorySeparatorChar}", frameworkPath, frameworkPath); + Assert.DoesNotContain( + path => path.EndsWith("MSTest.TestFramework.Extensions.dll", StringComparison.OrdinalIgnoreCase) + || path.EndsWith("MSTest.Uwp.dll", StringComparison.OrdinalIgnoreCase) + || path.EndsWith("MSTest.WinUI.dll", StringComparison.OrdinalIgnoreCase), + resolvedAssets); + await AssertResolvedMSTestCompositionAsync( + testAsset.TargetAssetPath, + $"{TargetFrameworks.NetCurrent}-windows10.0.26100.0", + "MSTest.TestAdapter"); Assert.DoesNotContain( path => path.Contains("Microsoft.Testing.Extensions.PackagedApp", StringComparison.OrdinalIgnoreCase), resolvedAssets); @@ -1429,7 +1449,8 @@ public async Task MSTestSdk_UnpackagedWinUIWithUwpXamlReferences_DoesNotConflict true false <_IncludeApplicationDefinition>true - """); + """, + expectedAdapterPackageId: "MSTest.WinUI"); result.AssertOutputContains("WindowsTestContract:UseVSTest=false;GenerateEntryPoint=false;GenerateHelper=true;PackagedApp=false;OutputType=Exe"); result.AssertOutputContains(";Controller=;ControllerTfm=;ControllerExtensions="); @@ -1445,7 +1466,8 @@ public async Task MSTestSdk_UnpackagedWinUI_DefaultsToMtpWithoutPackagedAppLaunc true None <_IncludeApplicationDefinition>true - """); + """, + expectedAdapterPackageId: "MSTest.WinUI"); result.AssertOutputContains("WindowsTestContract:UseVSTest=false;GenerateEntryPoint=false;GenerateHelper=true;PackagedApp=false"); result.AssertOutputContains("OutputType=Exe"); @@ -1464,7 +1486,8 @@ public async Task MSTestSdk_UnpackagedWinUIWithExplicitPackagedAppExtension_Keep None true <_IncludeApplicationDefinition>true - """); + """, + expectedAdapterPackageId: "MSTest.WinUI"); result.AssertOutputContains("WindowsTestContract:UseVSTest=false;GenerateEntryPoint=false;GenerateHelper=true;PackagedApp=true"); result.AssertOutputContains(";Controller=;ControllerTfm=;ControllerExtensions="); @@ -1496,13 +1519,13 @@ public async Task MSTestSdk_UnpackagedWinUI_AllowsVSTest() true """, failIfReturnValueIsNotZero: false, - target: "PrepareForBuild;PrintWindowsTestContract"); + expectedAdapterPackageId: "MSTest.WinUI"); result.AssertExitCodeIs(0); result.AssertOutputContains("WindowsTestContract:UseVSTest=true;GenerateEntryPoint=false;GenerateHelper=false;PackagedApp=;OutputType=Exe;IsTestProject=true;"); result.AssertOutputContains(";Controller=;ControllerTfm=;ControllerExtensions=;EndContract"); result.AssertOutputContains("Microsoft.NET.Test.Sdk"); - result.AssertOutputContains("MSTest.TestAdapter"); + result.AssertOutputContains("MSTest.WinUI"); result.AssertOutputDoesNotContain("Microsoft.Testing.Extensions.PackagedApp"); } @@ -1526,9 +1549,9 @@ public async Task MSTestSdk_WinUIWithUwpTools_RejectsConflictingApplicationModel } [TestMethod] - [DataRow("net10.0", "Windows_NT", "mstest-appmodel-controller.exe", "net10.0", "msbuild;packagedapp;codecoverage;trx;mstest")] - [DataRow("net11.0", "Windows_NT", "mstest-appmodel-controller.exe", "net11.0", "msbuild;packagedapp;codecoverage;trx;mstest")] - [DataRow("net11.0", "Unix", "", "", "")] + [DataRow("net10.0-windows10.0.26100.0", "Windows_NT", "mstest-appmodel-controller.exe", "net10.0", "msbuild;packagedapp;codecoverage;trx;mstest")] + [DataRow("net11.0-windows10.0.26100.0", "Windows_NT", "mstest-appmodel-controller.exe", "net11.0", "msbuild;packagedapp;codecoverage;trx;mstest")] + [DataRow("net11.0-windows10.0.26100.0", "Unix", "", "", "")] public async Task MSTestSdk_PackagedWinUI_SelectsLauncherOnlyOnWindows( string targetFramework, string operatingSystem, string controller, string controllerTfm, string controllerExtensions) { @@ -1539,7 +1562,8 @@ public async Task MSTestSdk_PackagedWinUI_SelectsLauncherOnlyOnWindows( <_IncludeApplicationDefinition>true {{operatingSystem}} """, - targetFramework: targetFramework); + targetFramework: targetFramework, + expectedAdapterPackageId: "MSTest.WinUI"); result.AssertOutputContains( "WindowsTestContract:UseVSTest=false;GenerateEntryPoint=false;GenerateHelper=true;PackagedApp=true;OutputType=Exe;"); @@ -1556,7 +1580,8 @@ public async Task MSTestSdk_WinUISeparateHost_KeepsGeneratedEntryPoint() """ true None - """); + """, + expectedAdapterPackageId: "MSTest.WinUI"); result.AssertOutputContains("WindowsTestContract:UseVSTest=false;GenerateEntryPoint=true;GenerateHelper=true;PackagedApp=false"); result.AssertOutputContains("OutputType=Exe"); @@ -1580,8 +1605,11 @@ private async Task EvaluateWindowsApplicationModelAsync( string assetName, string applicationModelProperties, bool failIfReturnValueIsNotZero = true, - string target = "PrintWindowsTestContract", - string? targetFramework = null) + string target = "PrepareForBuild;PrintWindowsTestContract", + string? targetFramework = null, + string expectedAdapterPackageId = "MSTest.TestAdapter", + bool useCentralPackageManagement = false, + string lateApplicationModelProperties = "") { const string Source = """ #file $AssetName$.csproj @@ -1589,6 +1617,7 @@ private async Task EvaluateWindowsApplicationModelAsync( $TargetFramework$ Exe + true true $(NoWarn);NETSDK1201;NU1507 $ApplicationModelProperties$ @@ -1599,29 +1628,59 @@ private async Task EvaluateWindowsApplicationModelAsync( + DependsOnTargets="ResolveReferences;_CalculateGenerateTestingPlatformEntryPoint"> + + """; - using TestAsset testAsset = await TestAsset.GenerateAssetAsync( - assetName, - Source - .PatchCodeWithReplace("$AssetName$", assetName) - .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion) - .PatchCodeWithReplace("$TargetFramework$", targetFramework ?? TargetFrameworks.NetCurrent) - .PatchCodeWithReplace("$ApplicationModelProperties$", applicationModelProperties)); + targetFramework ??= $"{TargetFrameworks.NetCurrent}-windows10.0.26100.0"; + string source = Source + .PatchCodeWithReplace("$AssetName$", assetName) + .PatchCodeWithReplace("$MSTestVersion$", MSTestVersion) + .PatchCodeWithReplace("$TargetFramework$", targetFramework) + .PatchCodeWithReplace("$ApplicationModelProperties$", applicationModelProperties); + if (useCentralPackageManagement) + { + source += CompositionCentralPackageManagementSource; + } + + if (lateApplicationModelProperties.Length > 0) + { + source += $$""" + + #file Directory.Build.targets + + + {{lateApplicationModelProperties}} + + + """; + } + + using TestAsset testAsset = await TestAsset.GenerateAssetAsync(assetName, source); string binlogPath = Path.Combine(testAsset.TargetAssetPath, $"{assetName}.binlog"); - return await DotnetCli.RunAsync( - $"build {testAsset.TargetAssetPath} -restore -t:{target} -bl:\"{binlogPath}\"", + DotnetMuxerResult result = await DotnetCli.RunAsync( + $"build \"{testAsset.TargetAssetPath}\" -restore -t:{target} -bl:\"{binlogPath}\"", failIfReturnValueIsNotZero: failIfReturnValueIsNotZero, cancellationToken: TestContext.CancellationToken); + if (result.ExitCode == 0) + { + await AssertResolvedMSTestCompositionAsync(testAsset.TargetAssetPath, targetFramework, expectedAdapterPackageId); + await AssertResolvedMSTestReferencesAsync(testAsset.TargetAssetPath, expectedAdapterPackageId); + } + + return result; } } diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SourceGenerationNonAotTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SourceGenerationNonAotTests.cs index dcbc31aa81..18393e84e9 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SourceGenerationNonAotTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SourceGenerationNonAotTests.cs @@ -391,7 +391,7 @@ public async Task MSTestSdk_SourceGenerationOptIn_DoesNotFlowTransitively() .OfType() .ToArray(); - Assert.Contains("MSTest.TestAdapter", dependencyIds); + Assert.DoesNotContain("MSTest.TestAdapter", dependencyIds); Assert.DoesNotContain("MSTest.SourceGeneration", dependencyIds); } diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/UnpackagedWinUITests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/UnpackagedWinUITests.cs index 6a5d47c83c..3df5d656dc 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/UnpackagedWinUITests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/UnpackagedWinUITests.cs @@ -276,13 +276,7 @@ anywhere. What is under test here (no package identity, WinUI hosting MTP, [UITe - - - + @@ -353,9 +347,26 @@ namespace $AssetName$; [TestClass] public class TestClass1 { + public TestContext TestContext { get; set; } = null!; + [TestMethod] public void PlainTestMethod_Runs() { + string[] directories = ["TestRunDirectory", "DeploymentDirectory", "ResultsDirectory", "TestRunResultsDirectory", "TestResultsDirectory", "TestTempDirectory"]; + foreach (string directory in directories) + { + TestContext.Properties[directory] = "not-a-ui-directory"; + } + + Assert.IsNull(TestContext.TestRunDirectory); + Assert.IsNull(TestContext.DeploymentDirectory); + Assert.IsNull(TestContext.ResultsDirectory); + Assert.IsNull(TestContext.TestRunResultsDirectory); + Assert.IsNull(TestContext.TestResultsDirectory); + Assert.IsNull(TestContext.TestTempDirectory); + TestContext.WriteLine(typeof(TestContext).Assembly.Location); + TestContext.WriteLine(typeof(UITestMethodAttribute).Assembly.Location); + TestContext.WriteLine(TestContext.GetType().Assembly.Location); } [TestMethod] @@ -504,8 +515,7 @@ anywhere. What is under test here (no package identity, WinUI hosting MTP, [UITe - - + diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WinUITests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WinUITests.cs index 763e0285fa..118d8c5a80 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WinUITests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WinUITests.cs @@ -30,6 +30,59 @@ public async Task SimpleWinUITestCase() testHostResult.AssertOutputContainsSummary(failed: 0, passed: 1, skipped: 0); } + [TestMethod] + [OSCondition(OperatingSystems.Windows)] + [DataRow("", DisplayName = "Deployment_Reflection")] + [DataRow("Rooting", DisplayName = "Deployment_Rooting")] + [DataRow("ReflectionFree", DisplayName = "Deployment_ReflectionFree")] + public async Task DeploymentItemsFailBeforeBodiesIncludingInheritedAttributes(string sourceGenMode) + { + const string assetName = "WinUIDeploymentContract"; + string generator = sourceGenMode.Length == 0 + ? string.Empty + : $""; + string source = DeploymentSource + .Replace("$TargetFramework$", WinUITargetFramework, StringComparison.Ordinal) + .Replace("$MSTestVersion$", MSTestVersion, StringComparison.Ordinal) + .Replace("$PlatformVersion$", MicrosoftTestingPlatformVersion, StringComparison.Ordinal) + .Replace("$Generator$", generator, StringComparison.Ordinal) + .Replace("$SourceGenMode$", sourceGenMode, StringComparison.Ordinal) + .Replace("$ReflectionType$", sourceGenMode.Length == 0 ? "ReflectionOperations" : "SourceGeneratedReflectionOperations", StringComparison.Ordinal); + using TestAsset asset = await TestAsset.GenerateAssetAsync(assetName, source); + DotnetMuxerResult build = await DotnetCli.RunAsync( + "build -c Release -warnaserror -bl:deployment.binlog", + workingDirectory: asset.TargetAssetPath, + cancellationToken: TestContext.CancellationToken); + build.AssertExitCodeIs(0); + if (sourceGenMode.Length != 0) + { + Assert.IsNotEmpty(Directory.GetFiles(Path.Join(asset.TargetAssetPath, "obj"), "*MSTestReflectionMetadata*.g.cs", SearchOption.AllDirectories)); + } + + var host = TestHost.LocateFrom(asset.TargetAssetPath, assetName, WinUITargetFramework); + TestHostResult result = await host.ExecuteAsync( + "--report-trx --report-trx-filename deployment.trx", + cancellationToken: TestContext.CancellationToken); + result.AssertExitCodeIs(ExitCode.AtLeastOneTestFailed); + result.AssertOutputContainsSummary(failed: 4, passed: 1, skipped: 0); + string reportPath = Assert.ContainsSingle(Directory.GetFiles(asset.TargetAssetPath, "deployment.trx", SearchOption.AllDirectories)); + XNamespace ns = "http://microsoft.com/schemas/VisualStudio/TeamTest/2010"; + var report = XDocument.Load(reportPath); + XElement[] results = [.. report.Descendants(ns + "UnitTestResult")]; + Assert.AreSequenceEqual( + ["ClassDeployment:Failed", "InheritedClassDeployment:Failed", "InheritedMethodDeployment:Failed", "MetadataProviderIsSelected:Passed", "MethodDeployment:Failed"], + results.Select(test => $"{test.Attribute("testName")!.Value}:{test.Attribute("outcome")!.Value}").Order(StringComparer.Ordinal)); + foreach (XElement failed in results.Where(test => (string?)test.Attribute("outcome") == "Failed")) + { + Assert.Contains( + "DeploymentItemAttribute is not supported by UWP or WinUI test hosts.", + failed.Descendants(ns + "Message").Single().Value); + Assert.DoesNotContain("DEPLOYMENT_BODY_EXECUTED", failed.Value); + } + + TestContext.WriteLine($"Packed WinUI deployment guard: {sourceGenMode}; TRX: {reportPath}"); + } + public sealed class TestAssetFixture() : TestAssetFixtureBase() { public const string ProjectName = "WinUITests"; @@ -60,8 +113,7 @@ and GetCurrentPackagePath() returning null). - - + @@ -82,4 +134,77 @@ public void TestMethod1() } public TestContext TestContext { get; set; } + + private const string DeploymentSource = """ + #file WinUIDeploymentContract.csproj + + + $TargetFramework$ + Exe + true + true + None + enable + enable + true + $SourceGenMode$ + + + + + + $Generator$ + + + + #file DeploymentTests.cs + using System.Reflection; + using Microsoft.VisualStudio.TestTools.UnitTesting; + + [TestClass] + public sealed class MethodDeploymentTests + { + [TestMethod] + [DeploymentItem("not-deployed.txt")] + public void MethodDeployment() => Assert.Fail("DEPLOYMENT_BODY_EXECUTED"); + + [TestMethod] + public void MetadataProviderIsSelected() + { + Assembly services = AppDomain.CurrentDomain.GetAssemblies().Single(assembly => assembly.GetName().Name == "MSTestAdapter.PlatformServices"); + Type providerType = services.GetType("Microsoft.VisualStudio.TestPlatform.MSTest.TestAdapter.PlatformServiceProvider", true)!; + object provider = providerType.GetProperty("Instance", BindingFlags.Static | BindingFlags.NonPublic)!.GetValue(null)!; + object reflection = providerType.GetProperty("ReflectionOperations")!.GetValue(provider)!; + Assert.AreEqual("$ReflectionType$", reflection.GetType().Name); + } + } + + [TestClass] + [DeploymentItem("not-deployed.txt")] + public sealed class ClassDeploymentTests + { + [TestMethod] + public void ClassDeployment() => Assert.Fail("DEPLOYMENT_BODY_EXECUTED"); + } + + public abstract class MethodDeploymentBase + { + [TestMethod] + [DeploymentItem("not-deployed.txt")] + public void InheritedMethodDeployment() => Assert.Fail("DEPLOYMENT_BODY_EXECUTED"); + } + + [TestClass] + public sealed class InheritedMethodDeploymentTests : MethodDeploymentBase; + + [DeploymentItem("not-deployed.txt")] + public abstract class ClassDeploymentBase; + + [TestClass] + public sealed class InheritedClassDeploymentTests : ClassDeploymentBase + { + [TestMethod] + public void InheritedClassDeployment() => Assert.Fail("DEPLOYMENT_BODY_EXECUTED"); + } + """; } diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WindowsApplicationModelPackageTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WindowsApplicationModelPackageTests.cs index e19d2d9f06..088a95bf01 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WindowsApplicationModelPackageTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WindowsApplicationModelPackageTests.cs @@ -25,10 +25,10 @@ public void ModernUwp_ResolvedAssetsRequireMatchingFrameworkAndSpecializedPayloa string report = $$""" TargetFramework={{targetFramework}} UseUwpTools=true - /buildTransitive/net10.0/uwp/MSTest.TestFramework.dll - /buildTransitive/net10.0/uwp/MSTest.TestAdapter.dll - /buildTransitive/net10.0/uwp/MSTestAdapter.PlatformServices.dll - /buildTransitive/net10.0/uwp/MSTest.TestFramework.Extensions.dll + /lib/{{targetFramework.Split('-')[0]}}/MSTest.TestFramework.dll + /buildTransitive/net10.0-windows10.0.17763/MSTest.TestAdapter.dll + /buildTransitive/net10.0-windows10.0.17763/MSTestAdapter.PlatformServices.dll + /lib/net10.0-windows10.0.17763/MSTest.Uwp.dll """; File.WriteAllText(reportPath, report); @@ -37,17 +37,17 @@ public void ModernUwp_ResolvedAssetsRequireMatchingFrameworkAndSpecializedPayloa File.WriteAllText( reportPath, - report.Replace("/buildTransitive/net10.0/uwp/MSTest.TestFramework.dll", $"/lib/{targetFramework.Split('-')[0]}/MSTest.TestFramework.dll", StringComparison.Ordinal)); + report.Replace($"/lib/{targetFramework.Split('-')[0]}/MSTest.TestFramework.dll", "/lib/netstandard2.0/MSTest.TestFramework.dll", StringComparison.Ordinal)); AssertFailedException wrongFramework = Assert.ThrowsExactly(() => WindowsApplicationModelTestTools.AssertResolvedMSTestAssets( reportPath, WindowsApplicationModelAssetKind.ModernUwp, targetFramework)); - Assert.Contains("/buildTransitive/net10.0/uwp/MSTest.TestFramework.dll", wrongFramework.Message); + Assert.Contains($"/lib/{targetFramework.Split('-')[0]}/MSTest.TestFramework.dll", wrongFramework.Message); - File.WriteAllText(reportPath, report.Replace("/uwp/", "/", StringComparison.Ordinal)); + File.WriteAllText(reportPath, report.Replace("/buildTransitive/net10.0-windows10.0.17763/", "/buildTransitive/net10.0/", StringComparison.Ordinal)); AssertFailedException ordinaryPayload = Assert.ThrowsExactly(() => WindowsApplicationModelTestTools.AssertResolvedMSTestAssets( reportPath, WindowsApplicationModelAssetKind.ModernUwp, targetFramework)); - Assert.Contains("/buildTransitive/net10.0/uwp/MSTest.TestFramework.dll", ordinaryPayload.Message); + Assert.Contains("/buildTransitive/net10.0-windows10.0.17763/MSTest.TestAdapter.dll", ordinaryPayload.Message); } [TestMethod] @@ -162,20 +162,17 @@ public void PackedMSTestTestFramework_DeploymentItemAvailabilityMatchesTargetFra [TestMethod] [OSCondition(OperatingSystems.Windows, IgnoreMessage = "Windows-specific framework assets are produced only by Windows packs.")] [DataRow("lib/net462/MSTest.TestFramework.dll", true, true, DisplayName = "DeploymentItem_Net462_IsAvailable")] - [DataRow("lib/uap10.0/MSTest.TestFramework.dll", false, false, DisplayName = "DeploymentItem_ClassicUwp_IsUnavailable")] - [DataRow("buildTransitive/net10.0/uwp/MSTest.TestFramework.dll", false, false, DisplayName = "DeploymentItem_ModernUwp_IsUnavailable")] - [DataRow("buildTransitive/net10.0/winui/MSTest.TestFramework.dll", false, false, DisplayName = "DeploymentItem_WinUI_IsUnavailable")] public void PackedMSTestTestFramework_DeploymentItemAvailabilityMatchesWindowsTargetFramework(string assemblyPath, bool expectedAvailable, bool directoriesAvailable) => AssertCoreContract(assemblyPath, expectedAvailable, directoriesAvailable); [TestMethod] [OSCondition(OperatingSystems.Windows, IgnoreMessage = "Windows application-model package assets are produced only by Windows packs.")] - [DataRow("lib/uap10.0/MSTest.TestFramework.Extensions.dll", false)] - [DataRow("buildTransitive/net10.0/uwp/MSTest.TestFramework.Extensions.dll", false)] - [DataRow("buildTransitive/net10.0/winui/MSTest.TestFramework.Extensions.dll", true)] - public void PackedMSTestTestFramework_SealsConcreteUIAttributes(string assemblyPath, bool winUI) + [DataRow("MSTest.Uwp", "lib/uap10.0.16299/MSTest.Uwp.dll", false)] + [DataRow("MSTest.Uwp", "lib/net10.0-windows10.0.17763/MSTest.Uwp.dll", false)] + [DataRow("MSTest.WinUI", "lib/net10.0-windows10.0.18362/MSTest.WinUI.dll", true)] + public void PackedUIFramework_SealsConcreteUIAttributes(string packageId, string assemblyPath, bool winUI) { - using ZipArchive archive = ZipFile.OpenRead(GetExactCurrentPackagePath("MSTest.TestFramework")); + using ZipArchive archive = ZipFile.OpenRead(GetExactCurrentPackagePath(packageId)); Dictionary types = ReadTypeAttributes(archive, assemblyPath); const string prefix = "Microsoft.VisualStudio.TestTools.UnitTesting.AppContainer."; @@ -188,77 +185,106 @@ public void PackedMSTestTestFramework_SealsConcreteUIAttributes(string assemblyP private static readonly string[] RequiredTestAdapterEntries = [ - // Classic UWP. - "build/uap10.0/MSTest.TestAdapter.props", - "build/uap10.0/MSTest.TestAdapter.targets", - "buildTransitive/uap10.0/MSTest.TestAdapter.dll", - "buildTransitive/uap10.0/MSTestAdapter.PlatformServices.dll", - "buildTransitive/uap10.0/MSTest.TestAdapter.props", - "buildTransitive/uap10.0/MSTest.TestAdapter.targets", - "buildTransitive/uap10.0/Parallelize.targets", - - // Modern UWP, WinUI, and their normal net10.0 selection targets. + "buildTransitive/net462/MSTest.TestFramework.dll", + "buildTransitive/net462/MSTest.TestAdapter.dll", + "buildTransitive/net462/MSTestAdapter.PlatformServices.dll", "build/net10.0/MSTest.TestAdapter.props", "build/net10.0/MSTest.TestAdapter.targets", "buildTransitive/net10.0/MSTest.TestAdapter.props", "buildTransitive/net10.0/MSTest.TestAdapter.targets", "buildTransitive/net10.0/Parallelize.targets", - "buildTransitive/net10.0/uwp/MSTest.TestAdapter.dll", - "buildTransitive/net10.0/uwp/MSTestAdapter.PlatformServices.dll", - "buildTransitive/net10.0/winui/MSTest.TestAdapter.dll", - "buildTransitive/net10.0/winui/MSTestAdapter.PlatformServices.dll", + "buildTransitive/net10.0/MSTest.TestAdapter.dll", + "buildTransitive/net10.0/MSTestAdapter.PlatformServices.dll", + "buildTransitive/net11.0/MSTest.TestAdapter.dll", + "buildTransitive/net11.0/MSTestAdapter.PlatformServices.dll", ]; private static readonly string[] RequiredTestFrameworkEntries = [ - // Classic UWP. - "lib/uap10.0/MSTest.TestFramework.dll", - "lib/uap10.0/MSTest.TestFramework.xml", - "lib/uap10.0/MSTest.TestFramework.Extensions.dll", - "lib/uap10.0/MSTest.TestFramework.Extensions.xml", - "build/uap10.0/MSTest.TestFramework.targets", - "buildTransitive/uap10.0/MSTest.TestFramework.targets", - - // Modern UWP, WinUI, and their normal net10.0 framework assets. + "lib/netstandard2.0/MSTest.TestFramework.dll", + "lib/net462/MSTest.TestFramework.dll", "lib/net10.0/MSTest.TestFramework.dll", "lib/net10.0/MSTest.TestFramework.xml", - "build/net10.0/MSTest.TestFramework.targets", - "buildTransitive/net10.0/MSTest.TestFramework.targets", - "buildTransitive/net10.0/uwp/MSTest.TestFramework.Extensions.dll", - "buildTransitive/net10.0/uwp/MSTest.TestFramework.Extensions.xml", - "buildTransitive/net10.0/uwp/MSTest.TestFramework.dll", - "buildTransitive/net10.0/uwp/MSTest.TestFramework.xml", - "buildTransitive/net10.0/uwp/fr/MSTest.TestFramework.resources.dll", - "buildTransitive/net10.0/winui/MSTest.TestFramework.Extensions.dll", - "buildTransitive/net10.0/winui/MSTest.TestFramework.Extensions.xml", - "buildTransitive/net10.0/winui/MSTest.TestFramework.dll", - "buildTransitive/net10.0/winui/MSTest.TestFramework.xml", - "buildTransitive/net10.0/winui/fr/MSTest.TestFramework.resources.dll", + "lib/net11.0/MSTest.TestFramework.dll", + "lib/net10.0/fr/MSTest.TestFramework.resources.dll", + "lib/net11.0/fr/MSTest.TestFramework.resources.dll", + "buildTransitive/MSTest.TestFramework.targets", ]; [TestMethod] [OSCondition(OperatingSystems.Windows, IgnoreMessage = "Windows application-model package assets are produced only by Windows packs.")] - public void PackedMSTestTestAdapter_ContainsRequiredWindowsApplicationModelAssets() - => AssertPackageContainsAllEntries( - GetExactCurrentPackagePath("MSTest.TestAdapter"), - RequiredTestAdapterEntries); + public void PackedMSTestTestAdapter_ContainsOnlyOrdinaryAssets() + { + string package = GetExactCurrentPackagePath("MSTest.TestAdapter"); + AssertPackageContainsAllEntries(package, RequiredTestAdapterEntries); + using ZipArchive archive = ZipFile.OpenRead(package); + Assert.DoesNotContain( + entry => entry.FullName.Contains("uap", StringComparison.OrdinalIgnoreCase) + || entry.FullName.Contains("windows", StringComparison.OrdinalIgnoreCase) + || entry.FullName.Contains("/winui/", StringComparison.OrdinalIgnoreCase) + || entry.FullName.Contains("/uwp/", StringComparison.OrdinalIgnoreCase) + || entry.FullName.Contains("TestFramework.Extensions", StringComparison.Ordinal), + archive.Entries); + using var reader = new StreamReader(archive.GetEntry("MSTest.TestAdapter.nuspec")!.Open()); + var nuspec = XDocument.Parse(reader.ReadToEnd()); + Assert.DoesNotContain( + group => ((string?)group.Attribute("targetFramework"))?.Contains("UAP", StringComparison.OrdinalIgnoreCase) == true + || ((string?)group.Attribute("targetFramework"))?.Contains("windows", StringComparison.OrdinalIgnoreCase) == true, + nuspec.Descendants().Where(element => element.Name.LocalName == "group")); + } + + [TestMethod] + [OSCondition(OperatingSystems.Windows)] + [DataRow("MSTest.Uwp", "uap10.0.16299")] + [DataRow("MSTest.Uwp", "net10.0-windows10.0.17763")] + [DataRow("MSTest.WinUI", "net10.0-windows10.0.18362")] + public void PackedUIFramework_OwnsItsPayloadWithoutAnotherAdapter(string packageId, string framework) + { + string package = GetExactCurrentPackagePath(packageId); + AssertPackageContainsAllEntries( + package, + [ + $"lib/{framework}/{packageId}.dll", + $"lib/{framework}/{packageId}.xml", + $"buildTransitive/{framework}/{packageId}.props", + $"buildTransitive/{framework}/{packageId}.targets", + $"buildTransitive/{framework}/MSTest.TestAdapter.dll", + $"buildTransitive/{framework}/MSTestAdapter.PlatformServices.dll", + $"buildTransitive/{framework}/_localization/fr/MSTestAdapter.PlatformServices.resources.dll", + ]); + using ZipArchive archive = ZipFile.OpenRead(package); + Assert.DoesNotContain(entry => entry.Name == "MSTest.TestFramework.dll", archive.Entries); + using var reader = new StreamReader(archive.GetEntry(packageId + ".nuspec")!.Open()); + var nuspec = XDocument.Parse(reader.ReadToEnd()); + XElement[] dependencies = nuspec.Descendants().Where(element => element.Name.LocalName == "dependency").ToArray(); + Assert.DoesNotContain( + dependency => (string?)dependency.Attribute("id") is "MSTest.TestAdapter" or "MSTest.Uwp" or "MSTest.WinUI", + dependencies); + XElement[] core = dependencies.Where(dependency => (string?)dependency.Attribute("id") == "MSTest.TestFramework").ToArray(); + Assert.IsNotEmpty(core); + foreach (XElement dependency in core) + { + Assert.AreEqual(AcceptanceTestBase.MSTestVersion, (string?)dependency.Attribute("version")); + } + } [TestMethod] [OSCondition(OperatingSystems.Windows, IgnoreMessage = "Classic UWP package assets are produced only by Windows packs.")] - public void PackedMSTestTestAdapter_ClassicUwpDoesNotDuplicateRuntimeDependencies() + public void PackedMSTestUwp_ClassicUwpDoesNotDuplicateRuntimeDependencies() { - using ZipArchive archive = ZipFile.OpenRead(GetExactCurrentPackagePath("MSTest.TestAdapter")); + using ZipArchive archive = ZipFile.OpenRead(GetExactCurrentPackagePath("MSTest.Uwp")); string[] assemblies = archive.Entries .Select(entry => entry.FullName) - .Where(path => path.StartsWith("buildTransitive/uap10.0/", StringComparison.Ordinal) + .Where(path => path.StartsWith("buildTransitive/uap10.0.16299/", StringComparison.Ordinal) + && !path["buildTransitive/uap10.0.16299/".Length..].Contains('/') && path.EndsWith(".dll", StringComparison.OrdinalIgnoreCase)) .Order(StringComparer.Ordinal) .ToArray(); Assert.AreSequenceEqual( [ - "buildTransitive/uap10.0/MSTest.TestAdapter.dll", - "buildTransitive/uap10.0/MSTestAdapter.PlatformServices.dll", + "buildTransitive/uap10.0.16299/MSTest.TestAdapter.dll", + "buildTransitive/uap10.0.16299/MSTestAdapter.PlatformServices.dll", ], assemblies); } @@ -267,10 +293,10 @@ public void PackedMSTestTestAdapter_ClassicUwpDoesNotDuplicateRuntimeDependencie [DataRow("Microsoft.Testing.Extensions.TrxReport")] [DataRow("Microsoft.Testing.Extensions.Retry")] [OSCondition(OperatingSystems.Windows, IgnoreMessage = "Classic UWP package assets are produced only by Windows packs.")] - public void PackedMSTestTestAdapter_ClassicUwpDeclaresBootstrapDependencies(string packageId) + public void PackedMSTestUwp_ClassicUwpDeclaresBootstrapDependencies(string packageId) { - using ZipArchive archive = ZipFile.OpenRead(GetExactCurrentPackagePath("MSTest.TestAdapter")); - using var reader = new StreamReader(archive.GetEntry("MSTest.TestAdapter.nuspec")!.Open()); + using ZipArchive archive = ZipFile.OpenRead(GetExactCurrentPackagePath("MSTest.Uwp")); + using var reader = new StreamReader(archive.GetEntry("MSTest.Uwp.nuspec")!.Open()); var nuspec = XDocument.Parse(reader.ReadToEnd()); XElement[] groups = nuspec.Descendants().Where(element => element.Name.LocalName == "group").ToArray(); XElement classicGroup = groups.Single(group => (string?)group.Attribute("targetFramework") == "UAP10.0.16299"); @@ -288,12 +314,12 @@ public void PackedMSTestTestAdapter_ClassicUwpDeclaresBootstrapDependencies(stri [TestMethod] [OSCondition(OperatingSystems.Windows, IgnoreMessage = "Windows application-model package assets are produced only by Windows packs.")] - public void PackedMSTestTestAdapter_UwpPropsRegisterMSTestBuilderHook() + public void PackedMSTestUwp_TargetsRegisterMSTestBuilderHook() { - string packagePath = GetExactCurrentPackagePath("MSTest.TestAdapter"); + string packagePath = GetExactCurrentPackagePath("MSTest.Uwp"); using ZipArchive archive = ZipFile.OpenRead(packagePath); - ZipArchiveEntry propsEntry = archive.GetEntry("buildTransitive/uap10.0/MSTest.TestAdapter.props") - ?? throw new AssertFailedException($"Package '{packagePath}' does not contain the classic UWP props."); + ZipArchiveEntry propsEntry = archive.GetEntry("buildTransitive/uap10.0.16299/MSTest.Uwp.targets") + ?? throw new AssertFailedException($"Package '{packagePath}' does not contain the classic UWP targets."); using var reader = new StreamReader(propsEntry.Open()); string props = reader.ReadToEnd(); @@ -306,7 +332,7 @@ public void PackedMSTestTestAdapter_UwpPropsRegisterMSTestBuilderHook() [TestMethod] [OSCondition(OperatingSystems.Windows, IgnoreMessage = "Windows application-model package assets are produced only by Windows packs.")] - public void PackedMSTestTestFramework_ContainsRequiredWindowsApplicationModelAssets() + public void PackedMSTestTestFramework_ContainsSharedCoreAssets() => AssertPackageContainsAllEntries( GetExactCurrentPackagePath("MSTest.TestFramework"), RequiredTestFrameworkEntries); diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WindowsApplicationModelTestTools.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WindowsApplicationModelTestTools.cs index 5bb02d4bcb..f546100a63 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WindowsApplicationModelTestTools.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WindowsApplicationModelTestTools.cs @@ -212,42 +212,41 @@ public static void AssertResolvedMSTestAssets( WindowsApplicationModelAssetKind.ClassicUwp => ( [ - "/buildTransitive/uap10.0/MSTest.TestAdapter.dll", - "/buildTransitive/uap10.0/MSTestAdapter.PlatformServices.dll", - "/lib/uap10.0/MSTest.TestFramework.dll", - "/lib/uap10.0/MSTest.TestFramework.Extensions.dll", + "/buildTransitive/uap10.0.16299/MSTest.TestAdapter.dll", + "/buildTransitive/uap10.0.16299/MSTestAdapter.PlatformServices.dll", + "/lib/netstandard2.0/MSTest.TestFramework.dll", + "/lib/uap10.0.16299/MSTest.Uwp.dll", ], [ - "/lib/netstandard2.0/MSTest.TestFramework.dll", - "/lib/netstandard2.0/MSTest.TestFramework.Extensions.dll", + "/mstest.testadapter/", + "/mstest.winui/", + "MSTest.TestFramework.Extensions.dll", ]), WindowsApplicationModelAssetKind.ModernUwp => ( [ - "/buildTransitive/net10.0/uwp/MSTest.TestFramework.dll", - "/buildTransitive/net10.0/uwp/MSTest.TestAdapter.dll", - "/buildTransitive/net10.0/uwp/MSTestAdapter.PlatformServices.dll", - "/buildTransitive/net10.0/uwp/MSTest.TestFramework.Extensions.dll", + $"/lib/{targetFramework.Split('-')[0]}/MSTest.TestFramework.dll", + "/buildTransitive/net10.0-windows10.0.17763/MSTest.TestAdapter.dll", + "/buildTransitive/net10.0-windows10.0.17763/MSTestAdapter.PlatformServices.dll", + "/lib/net10.0-windows10.0.17763/MSTest.Uwp.dll", ], [ - $"/lib/{targetFramework.Split('-')[0]}/MSTest.TestFramework.dll", - "/buildTransitive/net10.0/MSTest.TestAdapter.dll", - "/buildTransitive/net10.0/MSTestAdapter.PlatformServices.dll", - "/buildTransitive/net10.0/MSTest.TestFramework.Extensions.dll", + "/mstest.testadapter/", + "/mstest.winui/", + "MSTest.TestFramework.Extensions.dll", ]), WindowsApplicationModelAssetKind.WinUI => ( [ - "/buildTransitive/net10.0/winui/MSTest.TestFramework.dll", - "/buildTransitive/net10.0/winui/MSTest.TestAdapter.dll", - "/buildTransitive/net10.0/winui/MSTestAdapter.PlatformServices.dll", - "/buildTransitive/net10.0/winui/MSTest.TestFramework.Extensions.dll", + $"/lib/{targetFramework.Split('-')[0]}/MSTest.TestFramework.dll", + "/buildTransitive/net10.0-windows10.0.18362/MSTest.TestAdapter.dll", + "/buildTransitive/net10.0-windows10.0.18362/MSTestAdapter.PlatformServices.dll", + "/lib/net10.0-windows10.0.18362/MSTest.WinUI.dll", ], [ - $"/lib/{targetFramework.Split('-')[0]}/MSTest.TestFramework.dll", - "/buildTransitive/net10.0/MSTest.TestAdapter.dll", - "/buildTransitive/net10.0/MSTestAdapter.PlatformServices.dll", - "/buildTransitive/net10.0/MSTest.TestFramework.Extensions.dll", + "/mstest.testadapter/", + "/mstest.uwp/", + "MSTest.TestFramework.Extensions.dll", ]), _ => throw new ArgumentOutOfRangeException(nameof(assetKind), assetKind, "Unknown Windows application model."), }; diff --git a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/PackagedWinUITests.cs b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/PackagedWinUITests.cs index 132f8892e9..ff5345e70a 100644 --- a/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/PackagedWinUITests.cs +++ b/test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/PackagedWinUITests.cs @@ -104,8 +104,7 @@ await ExecuteWithPackageCleanupAsync( } [TestMethod] - [DataRow("MSTest")] - [DataRow("MSTest.TestAdapter")] + [DataRow("MSTest.WinUI")] public async Task PackagedAppContainerWinUI_ExplicitIntegrationPublishesTrx(string package) { GeneratedPackagedWinUIAsset generatedAsset = await GeneratePackagedWinUIAssetAsync(appContainer: true, package: package); @@ -651,9 +650,7 @@ private async Task GeneratePackagedWinUIAssetAsync( string source = SourceCode; if (package is not null) { - string references = package == "MSTest" - ? $"" - : $""; + string references = $""; source = source .Replace("MSTest.Sdk/$MSTestVersion$", "Microsoft.NET.Sdk", StringComparison.Ordinal) .Replace( @@ -970,18 +967,17 @@ private static void AssertResolvedWinUIAssets(string reportPath, bool usingSdk = string[] required = [ - "/buildTransitive/net10.0/winui/MSTest.TestFramework.dll", - "/buildTransitive/net10.0/winui/MSTest.TestAdapter.dll", - "/buildTransitive/net10.0/winui/MSTestAdapter.PlatformServices.dll", - "/buildTransitive/net10.0/winui/MSTest.TestFramework.Extensions.dll", + "/lib/net10.0/MSTest.TestFramework.dll", + "/buildTransitive/net10.0-windows10.0.18362/MSTest.TestAdapter.dll", + "/buildTransitive/net10.0-windows10.0.18362/MSTestAdapter.PlatformServices.dll", + "/lib/net10.0-windows10.0.18362/MSTest.WinUI.dll", "/lib/net10.0-windows10.0.19041/Microsoft.Testing.Extensions.PackagedApp.dll", ]; string[] rejected = [ - "/lib/net10.0/MSTest.TestFramework.dll", - "/buildTransitive/net10.0/MSTest.TestAdapter.dll", - "/buildTransitive/net10.0/MSTestAdapter.PlatformServices.dll", - "/buildTransitive/net10.0/MSTest.TestFramework.Extensions.dll", + "/mstest.testadapter/", + "/mstest.uwp/", + "MSTest.TestFramework.Extensions.dll", "/lib/net10.0/Microsoft.Testing.Extensions.PackagedApp.dll", ]; @@ -1444,10 +1440,26 @@ namespace $AssetName$; public sealed class PackagedWinUITestCases { private static readonly object s_executionMarkerLock = new(); + public TestContext TestContext { get; set; } = null!; [TestMethod] public void PlainTestMethod_Runs() { + string[] directories = ["TestRunDirectory", "DeploymentDirectory", "ResultsDirectory", "TestRunResultsDirectory", "TestResultsDirectory", "TestTempDirectory"]; + foreach (string directory in directories) + { + TestContext.Properties[directory] = "not-a-ui-directory"; + } + + Assert.IsNull(TestContext.TestRunDirectory); + Assert.IsNull(TestContext.DeploymentDirectory); + Assert.IsNull(TestContext.ResultsDirectory); + Assert.IsNull(TestContext.TestRunResultsDirectory); + Assert.IsNull(TestContext.TestResultsDirectory); + Assert.IsNull(TestContext.TestTempDirectory); + TestContext.WriteLine(typeof(TestContext).Assembly.Location); + TestContext.WriteLine(typeof(UITestMethodAttribute).Assembly.Location); + TestContext.WriteLine(TestContext.GetType().Assembly.Location); RecordExecution(nameof(PlainTestMethod_Runs)); } diff --git a/test/UnitTests/Bazel.SdkPackages.UnitTests/SdkPackageTests.cs b/test/UnitTests/Bazel.SdkPackages.UnitTests/SdkPackageTests.cs index c5da51b665..24fd40c317 100644 --- a/test/UnitTests/Bazel.SdkPackages.UnitTests/SdkPackageTests.cs +++ b/test/UnitTests/Bazel.SdkPackages.UnitTests/SdkPackageTests.cs @@ -67,7 +67,7 @@ public async Task Generate_MetaPackagePreservesDependencyAndAssetFlow() using JsonDocument request = JsonDocument.Parse(File.ReadAllText(PathFor("pack.json"))); Assert.AreEqual("MSTest", request.RootElement.GetProperty("metadata").GetProperty("id").GetString()); JsonElement[] groups = request.RootElement.GetProperty("dependencyGroups").EnumerateArray().ToArray(); - Assert.AreSequenceEqual(new[] { "net8.0", "net9.0", "net10.0", "net11.0" }, groups.Select(group => group.GetProperty("targetFramework").GetString()).ToArray()); + Assert.AreSequenceEqual(new[] { "net10.0", "net11.0" }, groups.Select(group => group.GetProperty("targetFramework").GetString()).ToArray()); foreach (JsonElement group in groups) { Dictionary dependencies = group.GetProperty("dependencies").EnumerateArray().ToDictionary(item => item.GetProperty("id").GetString()!); @@ -88,7 +88,7 @@ public async Task Generate_MetaPackagePreservesDependencyAndAssetFlow() } Assert.AreSequenceEqual( - new[] { "PACKAGE.md", "lib/net8.0/_._", "lib/net9.0/_._", "lib/net10.0/_._", "lib/net11.0/_._" }, + new[] { "PACKAGE.md", "lib/net10.0/_._", "lib/net11.0/_._" }, request.RootElement.GetProperty("files").EnumerateArray().Select(item => item.GetProperty("target").GetString()).ToArray(), SequenceOrder.InAnyOrder); Assert.IsFalse(File.Exists(PathFor("generated.props"))); @@ -105,6 +105,9 @@ public async Task Generate_MetaPackagePreservesDependencyAndAssetFlow() [DataRow("framework-drift", "differs from SupportedNetFrameworks")] [DataRow("meta-private-assets", "test SDK build-asset flow changed")] [DataRow("meta-reference", "Unsupported meta-package project reference")] + [DataRow("meta-retired-framework", "Unsupported meta-package project reference")] + [DataRow("meta-ui-reference", "Unsupported meta-package project reference")] + [DataRow("meta-ui-condition", "Unsupported meta-package project reference")] public async Task Generate_RejectsContractDriftBeforeWritingOutputs(string scenario, string expectedError) { JsonObject input = CreateInput(sdk: !scenario.StartsWith("meta-", StringComparison.Ordinal)); @@ -140,6 +143,15 @@ public async Task Generate_RejectsContractDriftBeforeWritingOutputs(string scena case "meta-reference": ReplaceInFile(PathFor("Package.csproj"), "MSTest.TestAdapter.csproj", "Unknown.csproj"); break; + case "meta-retired-framework": + ReplaceInFile(PathFor("Package.csproj"), @"TestFramework\TestFramework\TestFramework.csproj", @"TestFramework\TestFramework.Extensions\TestFramework.Extensions.csproj"); + break; + case "meta-ui-reference": + ReplaceInFile(PathFor("Package.csproj"), @"MSTest.Uwp\MSTest.Uwp.csproj", @"MSTest.WinUI\MSTest.WinUI.csproj"); + break; + case "meta-ui-condition": + ReplaceInFile(PathFor("Package.csproj"), "'$(TargetFramework)' == '$(UwpMinimum)'", "'$(TargetFramework)' != '$(UwpMinimum)'"); + break; default: Assert.Fail($"Unknown scenario: {scenario}"); break; @@ -165,7 +177,7 @@ private JsonObject CreateInput(bool sdk) """); string repositoryProperties = Write("Directory.Build.props", """ - net8.0;net9.0;net10.0;net11.0 + net10.0;net11.0 MIT """); @@ -191,8 +203,9 @@ private JsonObject CreateInput(bool sdk) """ : """ - - + + + @@ -238,7 +251,7 @@ private JsonObject CreateInput(bool sdk) else { string placeholder = Write("_._", ""); - files.AddRange(new[] { "net8.0", "net9.0", "net10.0", "net11.0" }.Select(framework => new { source = placeholder, target = $"lib/{framework}/_._" })); + files.AddRange(new[] { "net10.0", "net11.0" }.Select(framework => new { source = placeholder, target = $"lib/{framework}/_._" })); } return JsonSerializer.SerializeToNode(new @@ -249,7 +262,7 @@ private JsonObject CreateInput(bool sdk) repositoryProperties, sourceProperties, centralPackages, - frameworks = new[] { "net8.0", "net9.0", "net10.0", "net11.0" }, + frameworks = new[] { "net10.0", "net11.0" }, templates, files, output = PathFor("package.nupkg"), diff --git a/test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj b/test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj index 6718960379..f983f31988 100644 --- a/test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj +++ b/test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj @@ -38,7 +38,7 @@ - + diff --git a/test/UnitTests/MSTest.SourceGeneration.UnitTests/MSTest.SourceGeneration.UnitTests.csproj b/test/UnitTests/MSTest.SourceGeneration.UnitTests/MSTest.SourceGeneration.UnitTests.csproj index b161a7398d..8675118066 100644 --- a/test/UnitTests/MSTest.SourceGeneration.UnitTests/MSTest.SourceGeneration.UnitTests.csproj +++ b/test/UnitTests/MSTest.SourceGeneration.UnitTests/MSTest.SourceGeneration.UnitTests.csproj @@ -20,7 +20,7 @@ - + diff --git a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csproj b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csproj index 1a18c2ad23..e157dde90a 100644 --- a/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csproj +++ b/test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csproj @@ -23,10 +23,9 @@ - + - diff --git a/test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csproj b/test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csproj index f36d8e4224..b5fbfbf306 100644 --- a/test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csproj +++ b/test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csproj @@ -29,7 +29,6 @@ (PrivateAssets="all"), so reference it directly to compile against its (internals-visible) types. --> - diff --git a/test/UnitTests/TestFramework.UnitTests/Extensions/TestContextTests.cs b/test/UnitTests/TestFramework.UnitTests/Extensions/TestContextTests.cs index b2a6a30267..ce5511fb00 100644 --- a/test/UnitTests/TestFramework.UnitTests/Extensions/TestContextTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Extensions/TestContextTests.cs @@ -37,17 +37,14 @@ public void MissingAndNullPropertiesHaveDefinedDefaults() testName.Should().ThrowExactly().WithMessage("*TestName*"); context.CurrentTestOutcome.Should().Be(UnitTestOutcome.Unknown); context.TestRunCount.Should().Be(0); -#if !WIN_UI context.TestTempDirectory.Should().BeNull(); context.TestRunDirectory.Should().BeNull(); context.DeploymentDirectory.Should().BeNull(); context.ResultsDirectory.Should().BeNull(); context.TestRunResultsDirectory.Should().BeNull(); context.TestResultsDirectory.Should().BeNull(); -#endif } -#if !WIN_UI public void DirectoryPropertiesUseIndependentKeys() { using var context = new Context(); @@ -62,7 +59,6 @@ public void DirectoryPropertiesUseIndependentKeys() context.TestRunResultsDirectory.Should().Be("machine"); context.TestResultsDirectory.Should().Be("results"); } -#endif public void MetadataAndCancellationArePerContext() { diff --git a/test/UnitTests/TestFramework.UnitTests/Extensions/WinUIExtensionTests.cs b/test/UnitTests/TestFramework.UnitTests/Extensions/WinUIExtensionTests.cs index 878b72b2c5..5ffbbdb96f 100644 --- a/test/UnitTests/TestFramework.UnitTests/Extensions/WinUIExtensionTests.cs +++ b/test/UnitTests/TestFramework.UnitTests/Extensions/WinUIExtensionTests.cs @@ -35,7 +35,7 @@ public void TargetAttributeValidatesAndPreservesApplicationType() public void UnpackagedProcessHasNoPackageIdentityOrPath() { - Type model = typeof(UITestMethodAttribute).Assembly.GetType("Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.AppContainer.AppModel", true)!; + Type model = Assembly.Load("MSTestAdapter.PlatformServices").GetType("Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices.AppContainer.AppModel", true)!; model.GetMethod("IsPackagedProcess")!.Invoke(null, null).Should().Be(false); model.GetMethod("GetCurrentPackagePath")!.Invoke(null, null).Should().BeNull(); } diff --git a/test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csproj b/test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csproj index bd63425ca5..87155b9eaf 100644 --- a/test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csproj +++ b/test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csproj @@ -25,7 +25,8 @@ - + + @@ -41,7 +42,7 @@ - + diff --git a/test/Utilities/Microsoft.Testing.TestInfrastructure/AcceptanceSourceGen.cs b/test/Utilities/Microsoft.Testing.TestInfrastructure/AcceptanceSourceGen.cs index 14707ff066..6997932f95 100644 --- a/test/Utilities/Microsoft.Testing.TestInfrastructure/AcceptanceSourceGen.cs +++ b/test/Utilities/Microsoft.Testing.TestInfrastructure/AcceptanceSourceGen.cs @@ -138,8 +138,8 @@ private static string BuildPropsContent(string packageId, string versionProperty always runs first, into the default bin/Release) leaves a referenced project's outputs on disk, e.g. 'SomeRef/bin/Release//*.dll'. When this (later) source-gen build evaluates the host project, the SDK's default item globs would otherwise pull those stray DLLs in as None/Content items, and RAR then - treats a wrong-TFM copy (for example a net10.0 'MSTest.TestFramework.Extensions.dll', assembly version - 9.0.0.0) as a candidate for the net8.0 leg -> MSB3277, which MSBuildTreatWarningsAsErrors promotes to an + treats a wrong-TFM copy (for example a net11.0 'MSTest.TestFramework.dll') as a candidate for + the net10.0 leg -> MSB3277, which MSBuildTreatWarningsAsErrors promotes to an error. The root-level 'bin/**;obj/**' does not match the nested 'SomeRef/bin/**', so exclude nested bin/obj as well to keep a referenced project's leftover reflection outputs out of this build's globs. --> From 33faf4889ca048ccdcb508c2088b15dd5f1efd21 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 12 Nov 2026 17:02:52 +0100 Subject: [PATCH 2/3] Validate resolved adapter closures and pin UI core dependencies Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- .../common/MSTest.TestAdapter.targets | 12 +++-- .../uwp/MSTest.TestAdapter.targets | 9 +++- .../PlatformPackage/PlatformPackage.targets | 8 +++ .../SdkTests.Composition.cs | 51 +++++++++++++++---- .../WindowsApplicationModelPackageTests.cs | 2 +- 5 files changed, 66 insertions(+), 16 deletions(-) diff --git a/src/Adapter/MSTest.TestAdapter/buildTransitive/common/MSTest.TestAdapter.targets b/src/Adapter/MSTest.TestAdapter/buildTransitive/common/MSTest.TestAdapter.targets index 0dab08588c..135e0da736 100644 --- a/src/Adapter/MSTest.TestAdapter/buildTransitive/common/MSTest.TestAdapter.targets +++ b/src/Adapter/MSTest.TestAdapter/buildTransitive/common/MSTest.TestAdapter.targets @@ -17,11 +17,17 @@ <_MSTestAdapterPayloadRoot Condition=" '$(_MSTestAdapterPayloadRoot)' == '' ">$(MSBuildThisFileDirectory) <_MSTestAdapterLocalizationRoot Condition=" '$(_MSTestAdapterLocalizationRoot)' == '' ">$(MSBuildThisFileDirectory)..\_localization\ + <_MSTestAdapterCompositionDependsOn Condition=" '$(UsingMicrosoftNETSdk)' == 'true' AND '$(TargetFramework)' != '' ">ResolvePackageAssets - - - + + + <_MSTestResolvedAdapterComposition Include="@(PackageDependencies)" + Condition=" '%(PackageDependencies.Identity)' == 'MSTest.TestAdapter' OR '%(PackageDependencies.Identity)' == 'MSTest.Uwp' OR '%(PackageDependencies.Identity)' == 'MSTest.WinUI' " /> + + $(EnableMSTestRunner) false + <_MSTestAdapterCompositionDependsOn Condition=" '$(UsingMicrosoftNETSdk)' == 'true' AND '$(TargetFramework)' != '' ">ResolvePackageAssets @@ -27,8 +28,12 @@ - - + + <_MSTestResolvedAdapterComposition Include="@(PackageDependencies)" + Condition=" '%(PackageDependencies.Identity)' == 'MSTest.TestAdapter' OR '%(PackageDependencies.Identity)' == 'MSTest.Uwp' OR '%(PackageDependencies.Identity)' == 'MSTest.WinUI' " /> + + diff --git a/src/TestFramework/PlatformPackage/PlatformPackage.targets b/src/TestFramework/PlatformPackage/PlatformPackage.targets index aadff46308..a8d5f3328b 100644 --- a/src/TestFramework/PlatformPackage/PlatformPackage.targets +++ b/src/TestFramework/PlatformPackage/PlatformPackage.targets @@ -1,5 +1,13 @@ + + + <_ProjectReferencesWithVersions Condition=" '%(Filename)' == 'TestFramework' "> + [$(PackageVersion)] + + + + <_PlatformPackageTfm Condition=" '$(TargetFramework)' == '$(UwpMinimum)' ">uap10.0.16299 diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.Composition.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.Composition.cs index 7c66611069..de514814cd 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.Composition.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/SdkTests.Composition.cs @@ -56,14 +56,20 @@ public async Task MSTestSdk_ExplicitApplicationModel_SelectsCompositionBeforeLat [TestMethod] [OSCondition(OperatingSystems.Windows)] - [DataRow("MSTest.TestAdapter", "MSTest.Uwp")] - [DataRow("MSTest.TestAdapter", "MSTest.WinUI")] - [DataRow("MSTest.Uwp", "MSTest.WinUI")] - public async Task ExplicitPackages_RejectConflictingAdaptersBeforeCompilation(string firstPackage, string secondPackage) + [DataRow("MSTest.TestAdapter", "MSTest.Uwp", "Direct")] + [DataRow("MSTest.TestAdapter", "MSTest.WinUI", "Direct")] + [DataRow("MSTest.Uwp", "MSTest.WinUI", "Direct")] + [DataRow("MSTest.TestAdapter", "MSTest.Uwp", "ExcludedBuildAssets")] + [DataRow("MSTest.TestAdapter", "MSTest.WinUI", "ExcludedBuildAssets")] + [DataRow("MSTest.Uwp", "MSTest.WinUI", "ExcludedBuildAssets")] + [DataRow("MSTest.TestAdapter", "MSTest.Uwp", "ProjectReferenceWithExcludedBuildAssets")] + [DataRow("MSTest.TestAdapter", "MSTest.WinUI", "ProjectReferenceWithExcludedBuildAssets")] + [DataRow("MSTest.Uwp", "MSTest.WinUI", "ProjectReferenceWithExcludedBuildAssets")] + public async Task ExplicitPackages_RejectConflictingAdaptersBeforeCompilation(string firstPackage, string secondPackage, string referenceKind) { - using TestAsset asset = await TestAsset.GenerateAssetAsync( - "ConflictingMSTestPackages", - $$""" + string excludedAssets = referenceKind == "Direct" ? string.Empty : " ExcludeAssets=\"build;buildTransitive\""; + string secondReference = $""""""; + string source = $$""" #file ConflictingMSTestPackages.csproj @@ -71,15 +77,40 @@ public async Task ExplicitPackages_RejectConflictingAdaptersBeforeCompilation(st - + {{(referenceKind == "ProjectReferenceWithExcludedBuildAssets" ? """""" : secondReference)}} - """); + """; + if (referenceKind == "ProjectReferenceWithExcludedBuildAssets") + { + source += $$""" + + #file Dependency/Dependency.csproj + + + net11.0-windows10.0.26100.0 + + + {{secondReference}} + + + """; + } + + using TestAsset asset = await TestAsset.GenerateAssetAsync( + "ConflictingMSTestPackages", + source); DotnetMuxerResult result = await DotnetCli.RunAsync( - "msbuild -restore -t:PrepareForBuild -bl:conflicting-adapters.binlog", + "msbuild ConflictingMSTestPackages.csproj -restore -t:PrepareForBuild -bl:conflicting-adapters.binlog", workingDirectory: asset.TargetAssetPath, failIfReturnValueIsNotZero: false, cancellationToken: TestContext.CancellationToken); + using var assets = JsonDocument.Parse( + await File.ReadAllTextAsync(Path.Combine(asset.TargetAssetPath, "obj", "project.assets.json"), TestContext.CancellationToken)); + string[] packages = Assert.ContainsSingle(assets.RootElement.GetProperty("targets").EnumerateObject()).Value + .EnumerateObject().Select(package => package.Name).ToArray(); + Assert.Contains($"{firstPackage}/{MSTestVersion}", packages); + Assert.Contains($"{secondPackage}/{MSTestVersion}", packages); result.AssertExitCodeIs(1); result.AssertOutputContains("Reference exactly one MSTest adapter composition: MSTest.TestAdapter, MSTest.Uwp, or MSTest.WinUI."); } diff --git a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WindowsApplicationModelPackageTests.cs b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WindowsApplicationModelPackageTests.cs index 088a95bf01..7917bcfdbe 100644 --- a/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WindowsApplicationModelPackageTests.cs +++ b/test/IntegrationTests/MSTest.Acceptance.IntegrationTests/WindowsApplicationModelPackageTests.cs @@ -264,7 +264,7 @@ public void PackedUIFramework_OwnsItsPayloadWithoutAnotherAdapter(string package Assert.IsNotEmpty(core); foreach (XElement dependency in core) { - Assert.AreEqual(AcceptanceTestBase.MSTestVersion, (string?)dependency.Attribute("version")); + Assert.AreEqual($"[{AcceptanceTestBase.MSTestVersion}]", (string?)dependency.Attribute("version")); } } From 00428d48c212cf3630dcf6fa31d131c5ae745c98 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Amaury=20Lev=C3=A9?= Date: Thu, 12 Nov 2026 17:24:25 +0100 Subject: [PATCH 3/3] Align native UI package dependencies and record final validation Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com> --- docs/decisions/bazel-build.md | 50 ++++++++++++++- docs/decisions/mstest-platform-packages.md | 75 +++++++++++++++++++--- eng/bazel/MSTestPackageVersion.cs | 35 +++++++--- eng/bazel/mstest-packages.bzl | 29 +++++++-- eng/bazel/validate-mstest-packages.ps1 | 6 ++ 5 files changed, 169 insertions(+), 26 deletions(-) diff --git a/docs/decisions/bazel-build.md b/docs/decisions/bazel-build.md index 501201b010..ea4669b439 100644 --- a/docs/decisions/bazel-build.md +++ b/docs/decisions/bazel-build.md @@ -4172,7 +4172,7 @@ Paths are under `eng\bazel` unless qualified otherwise. | `windows\validate-app-model.ps1` | Consume the path index, reject overwritten prefixes, and follow the current controller TFMs without changing activation/handshake checks. | | `docs\decisions\bazel-build.md` | Append only this dated decision/evidence entry. | -### Static validation and remaining integration evidence +### Initial static validation before integrated execution The local code patch is based on `e1c66e5cbfa844384a59343c3727821f97e2a09a`. SHA-256 of raw @@ -4225,3 +4225,51 @@ net11 package consumption, classic UAP, and real activation. No native classic UAP producer was introduced. No commit, push, publication, or other-worktree change was made by this lane. Archiving API provenance is not a compatibility waiver or evidence that old binary consumers still work. + +### Primary integrated follow-through + +The primary shipping snapshot is +`33faf4889ca048ccdcb508c2088b15dd5f1efd21`. Its corrected 42-project MSBuild +source pack passes with zero warnings/errors and the normal package verifier. +The defined shipping selections execute 177 passing cases, zero skipped: +140 MSTest acceptance, 11 MTP acceptance, and 26 context/WinUI source units. +Those include real classic and modern UWP, packaged/unpackaged WinUI, +net10/net11 selection, SDK/helper/mixed-TFM composition, net462 configuration, +native SDK routing, and Hosting. These are MSBuild shipping-package results, +not native Bazel package consumer evidence. + +Executed native commands: + +| Command | Observed result | +| --- | --- | +| `.\eng\bazel.ps1 test //:sdk_package_tests --jobs=2 --test_output=errors` | Bazel target passed. Do not substitute the fifteen source-declared cases for a verified executed-method count. | +| `.\eng\bazel\windows\validate.ps1 -ArtifactsDirectory $run` | Five native library probes passed, desktop/Uwp/WinUI core hashes match, and both targeting/asset-selection analysis tests pass (2 passed, 0 failed/skipped). Hosting build also exits 0. | +| `.\eng\bazel.ps1 build //:mstest_uwp_package //:mstest_winui_package --jobs=2 --noshow_progress --show_result=0` | Final stable-input build exits 0. The maintained `Assert-PackageLayout` assertions execute against both produced archives and pass, including exact `[5.0.0-preview.bazel]` core dependencies. This is scoped archive validation, not the blocked full validator/ordinary native consumer. | +| `.\eng\bazel.ps1 build //:mstest_platform_package_closure --jobs=2 --noshow_progress --show_result=0` | Analysis passes after copying the frozen external-target list before appending net462 dependencies. Compilation then exits 1 on net462 `platform_services` CS0234: `System.Reflection.Metadata`/`PortableExecutable` references are missing. Full native layout/ordinary consumer execution is not reached. | + +The original ordinary native core already omitted portable +`TargetFrameworkAttribute` metadata. The new Windows validator now accepts +that undeclared value while rejecting declared wrong/Windows metadata and +still comparing core bytes under the independently planned framework major. +It does not change native producer metadata or weaken shared-core API checks. + +The net462 source imports and missing native dependency are unchanged in the +prerequisite; the retired Extensions library depended only on core. This is +static baseline attribution, **not an executed pristine-baseline proof**. +No unrelated native dependency repair is included. The ordinary/full native +package consumer remains an explicit validation gap; real MSBuild net462 and +configuration consumers pass independently. + +The new native UI packages reuse the existing version-request tool to pin +only `MSTest.Uwp`/`MSTest.WinUI` to exactly their matching core version; +other dependency ranges are unchanged. Classic native UAP production remains +unsupported rather than simulated. + +The final bounded UI rerun retains patch SHA-256 +`6E3C2D1C7284BE2B387DDFFC5A5E26E07AC845023DF04372FD0D72986ACA362E` +on the shipping snapshot above; all recorded native/package inputs remain +byte-identical through build and validation. Its exact commands, input hashes, +archive hashes and results are in task evidence +`bazel-native/20261112-162052-18d945ec/result.json`. Only the task-owned +`Q:\tfb\pkg37010c6b` Bazel server is shut down, exit 0. No global cache, +registration, other-worktree output, or other server is changed. diff --git a/docs/decisions/mstest-platform-packages.md b/docs/decisions/mstest-platform-packages.md index e06e543ade..32ea1d680d 100644 --- a/docs/decisions/mstest-platform-packages.md +++ b/docs/decisions/mstest-platform-packages.md @@ -116,6 +116,33 @@ core, which does not expose `DeploymentItem`. supported, a declared wrong/Windows TFM is rejected, and desktop/UI core bytes are compared under the independently planned framework major. No broad native metadata, runtime, or source changes are introduced by this correction. +- Final package-boundary review found two gaps in the first committed snapshot, + `51457e73fbb982343390f33e5bb5c884361625ab`: imported markers alone miss a + competing package whose build assets are excluded, and NuGet packs an ordinary + core ProjectReference as a minimum version. Commit + `33faf4889ca048ccdcb508c2088b15dd5f1efd21` uses the SDK's current-inner-TFM + `ResolvePackageAssets`/`PackageDependencies` for composition validation, retaining + markers for non-SDK projects. A package-local `_GetProjectReferenceVersions` + hook pins the UI package's core dependency to exactly `[$(PackageVersion)]`, + following the repository's existing project-reference packaging hook. +- The same retained 12 cases execute against both package states: before the + correction, six direct/transitive excluded-build cases incorrectly reach + successful `PrepareForBuild`, and three nuspec assertions observe a bare + minimum instead of an exact range. Those nine intended assertions fail; + three direct conflict controls pass (12 executed, 0 skipped, exit 2). + After the corrected 42-project pack, all 12 pass (0 skipped, exit 0). + The conflict tests assert both package IDs in the actual resolved inner target, + including a real ProjectReference, before checking the pre-compilation error. + The retained test patch has SHA-256 + `733315AC5F3A0654FAC0A8BF7600F72C3B933212488BC9D8E365B5077CFC7296`; + both package states and reports remain in the task's `boundary` evidence. +- The final host refresh initially passed a global `TargetFramework` to a + desktop helper that implicitly restores. That produced inappropriate net12 + assets and pruning diagnostics; a no-restore attempt then exposed the missing + normal targets. Restoring the owning graph without that override fixed setup. + A later `.cmd` invocation split semicolon-containing logger arguments after + the build; the clean producer rerun omits those arguments. None of these + setup/command failures is credited as product or red-phase evidence. ## Alternatives and decision @@ -148,8 +175,9 @@ after pack. Source builds and restore retain the full graph. The SDK may infer a safe early application-model default and expose a bounded explicit override where restore precedes desktop UWP tooling imports. Selection must apply to every runner and source-generated helper injection path. Conflict -checks inspect the current inner TFM's resolved closure, never every target in a -multi-targeted assets file. Package builder hooks must honor +checks inspect the current inner TFM's SDK-resolved package closure, even when +build assets are excluded, never every target in a multi-targeted assets file. +Non-SDK projects retain their imported-marker check. Package builder hooks must honor `IsTestApplication=false` without dropping source-generation compile hooks. ## Validation and demonstration @@ -172,7 +200,8 @@ zero tests with application execution. ### Executed shipping-layout evidence -All runs below use Release, repository SDK +The final shipping production/test snapshot is +`33faf4889ca048ccdcb508c2088b15dd5f1efd21`. All runs below use Release, repository SDK `12.0.100-alpha.1.26556.115`, MSTest `5.0.0-dev`, and MTP `3.0.0-dev`. The outer acceptance hosts target net12.0; generated consumers target the frameworks named by their cases. Producer dependencies use the verified @@ -204,13 +233,17 @@ Independent discovery uses the same project/filter with `--list-tests json`, clearing `TestingPlatformCommandLineArguments` and `TestRunnerAdditionalArguments`. Expected identities are reconciled with source and verified against fresh TRX by the existing `verify_execution.py` gate. -Every passing row below has exit 0 and zero skips. +Every passing row below has exit 0 and zero skips. After the final dependency +and resolved-closure corrections, the same defined follow-through reruns 140 +MSTest acceptance cases, 11 MTP acceptance cases, and 26 source-unit cases: +**177/177 pass**. The separately repeated 12-case boundary proof is not added +again to that unique total. | Requirement | Exact selection / executed cases | Result | | --- | --- | --- | | Core/UI ownership, matching compile/runtime/satellite bytes, package closure, and pre-body UI deployment failure | `CoreFrameworkAssemblyTests`, `WindowsApplicationModelPackageTests`, and `.WinUITests.` | 43/43 passed. `DeploymentItemsFailBeforeBodiesIncludingInheritedAttributes` executes reflection, Rooting, and ReflectionFree and checks exact failed identities/messages, not merely a failed child exit. | | SDK defaults/explicit choices, CPM, ordinary/UI multi-TFM, helper/source-generation isolation, and net462 | `SdkTests.MSTestSdk_`, `SettingIsTestApplicationToFalseReducesAddedExtensionsAndMakesProjectNotExecutable`, `TestApplicationRunsTestsFromReferencedMSTestSdkTestLibrary`, `SourceGenerationNonAotTests.MSTestSdk_SourceGenerationOptIn_DoesNotFlowTransitively`, `FrameworkTargetingTests.PackedPackages_UseMatchingFrameworkAssetsAndRuntime`, `NetFrameworkRunnerCompatibilityTests` | 65/65 passed. Helper runtime payloads stay private; only the MSTest builder hook is excluded, without changing unrelated MTP dependency hooks. | -| Direct conflicting package pairs | `SdkTests.ExplicitPackages_RejectConflictingAdaptersBeforeCompilation` | 3/3 passed for ordinary+Uwp, ordinary+WinUI, and Uwp+WinUI. `PrepareForBuild` reports the composition diagnostic before compilation. | +| Conflicting direct/transitive package pairs, including excluded build assets | `SdkTests.ExplicitPackages_RejectConflictingAdaptersBeforeCompilation` | 9/9 passed for ordinary+Uwp, ordinary+WinUI, and Uwp+WinUI. Both packages are asserted in the real inner-TFM resolved graph, including ProjectReference consumers. `PrepareForBuild` reports the composition diagnostic before compilation. | | Actual classic/modern UWP and unpackaged WinUI | `ClassicUwpTests`, `ModernUwpTests`, `UnpackagedWinUITests` | 12/12 passed. Classic consumes SDK/metapackage/direct Uwp compositions; modern executes net10/net11 plus inherited unsupported deployment. x86/ARM64 layouts build; real execution is x64. Unpackaged dispatch, timeout cleanup, and constructor failure paths execute. | | Actual packaged WinUI | `PackagedFullTrustWinUI_RegistersActivatesConnectsBackRunsUiTestsAndCleansUp`, `PackagedAppContainerWinUI_RunsThroughMtpControllerAndPublishesTrx`, `PackagedAppContainerWinUI_ExplicitIntegrationPublishesTrx` | 3/3 passed, including direct `MSTest.WinUI`. Names/outcomes and package identity are checked in the real activated host's TRX. | | Hosting/core dependency and scope lifetime | `GeneratedMSTestHostingInjectionTests` | 8/8 passed across net462/net10/net11, including explicit unsupported AppDomain discovery/execution. | @@ -229,10 +262,14 @@ The exact frozen shipping package hashes are: | Package (`5.0.0-dev`) | SHA-256 | | --- | --- | -| MSTest.TestFramework | `910EE1E42522F58B709F246B3F485E9D651B4A43C5A7AC2D53DCE6266A844FA4` | -| MSTest.TestAdapter | `4919459CA1CE3F34DC9E6A81185C3FBD35BA81B29E8159C307D6E1C1AAB6F07D` | -| MSTest.Uwp | `9D758A77C1A34781F43208C7488D3BEC0302D80021DACF8A7B0CD54D2AE0AA67` | -| MSTest.WinUI | `C91FABBC15223E201E2AE4E6CD95E68FD6AA8767333575EAD37BFED939C3B77C` | +| MSTest.TestFramework | `1FA5C88A0DC7DAC56EE37CFB094CFE710F6868321FFE9C94196A41C2823C45A2` | +| MSTest.TestAdapter | `582FB397A048AFAFBC1926E5406A8124456A237957862DD27023CBEF309F1004` | +| MSTest.Uwp | `606224A38A8F1A733022126C6A82ACD55F62A4558B47CAA592B352862F9F3537` | +| MSTest.WinUI | `BE1954567CB3E281526FEE583A71CEAA3DEF96C3D7486AEB83540D316993C7D0` | + +These supersede the first package snapshot. Actual Uwp nuspec core dependencies +are `[5.0.0-dev]` in both classic and modern groups; WinUI has the same exact +range in its modern group. The existing physical package test checks them. ### Test-value evidence @@ -262,7 +299,15 @@ worktree's SHA-256 values. Red/green NuGets, TRX, build/execution binlogs, retai test identities, and both patch hashes are preserved in the task's `counterfactual` evidence directory. Package/SDK selection groups have executed green coverage but no additional -fault campaign; they are not credited with the two behavioral faults above. +general fault campaign. The bounded package-boundary correction separately +executes the retained 12 cases described above: 9 intended assertion failures +and 3 controls on the previous packages, then 12/12 passed on the corrected +packages. This is executed detection of excluded-build/transitive conflicts and +non-exact core ranges, not proof generalized to other package faults. +The four original runtime/test contract files are byte-identical between +`51457e73fbb982343390f33e5bb5c884361625ab` and +`33faf4889ca048ccdcb508c2088b15dd5f1efd21`; the final shipping selection reexecutes +their nine cases against the corrected package snapshot. Logs, binary logs, expected identities, and reports are task-owned evidence, not source additions. This package boundary introduces no report/UI layout, @@ -277,3 +322,13 @@ adoption. This targets main's next major MSTest release, not a servicing backport that changes an existing released package boundary. Architecture and release-branch surfaces not exercised locally must remain explicit validation gaps. No merge or Agent merge is authorized by this package-stage delivery. + +The native Bazel full package closure passes analysis but stops on net462 +PlatformServices CS0234: `System.Reflection.Metadata`/`PortableExecutable` +references are absent. The source imports and missing native dependency are +unchanged in the prerequisite; this is static comparison, not an executed +pristine-baseline run. The ordinary native package consumer therefore remains +unvalidated. Do not repair unrelated native wiring to hide that gap. Native +modern UI archive/probe results are recorded separately in the Bazel decision +entry; actual classic UAP production/activation is covered by the MSBuild +shipping runs, not simulated by the native modern-only producer. diff --git a/eng/bazel/MSTestPackageVersion.cs b/eng/bazel/MSTestPackageVersion.cs index fccc086b55..2692bad96a 100644 --- a/eng/bazel/MSTestPackageVersion.cs +++ b/eng/bazel/MSTestPackageVersion.cs @@ -7,9 +7,10 @@ using System.Text; using System.Text.Json.Nodes; -if (args.Length != 3) +bool exactFramework = args.Length == 4 && args[3] == "--exact-framework"; +if (args.Length != 3 && !exactFramework) { - throw new ArgumentException("Expected ."); + throw new ArgumentException("Expected [--exact-framework]."); } string version = File.ReadAllText(args[1]).Trim(); @@ -25,9 +26,25 @@ ?? throw new InvalidDataException("Expected a package request object."); if (request["dependencyGroups"] is not JsonArray groups || groups.Count == 0) { - throw new InvalidDataException("Expected nonempty platform dependency groups."); + throw new InvalidDataException("Expected nonempty dependency groups."); } +if (exactFramework) +{ + if (request["metadata"]?["id"]?.GetValue() is not ("MSTest.Uwp" or "MSTest.WinUI")) + { + throw new InvalidDataException("Only UI packages may pin the matching framework dependency."); + } + + string ownVersionFile = request["versionFile"]?.GetValue() + ?? throw new InvalidDataException("The UI package must declare its own version file."); + if (File.ReadAllText(ownVersionFile).Trim() != version) + { + throw new InvalidDataException("The UI package and core dependency versions must match exactly."); + } +} + +string dependencyId = exactFramework ? "MSTest.TestFramework" : "Microsoft.Testing.Platform"; foreach (JsonNode? group in groups) { if (group?["dependencies"] is not JsonArray dependencies) @@ -35,16 +52,16 @@ throw new InvalidDataException("A package dependency group is missing its dependencies."); } - JsonObject[] platform = dependencies.OfType() - .Where(dependency => dependency["id"]?.GetValue() == "Microsoft.Testing.Platform") + JsonObject[] bounded = dependencies.OfType() + .Where(dependency => dependency["id"]?.GetValue() == dependencyId) .ToArray(); - if (platform.Length != 1) + if (bounded.Length != 1) { - throw new InvalidDataException("Each bounded group must declare exactly one platform dependency."); + throw new InvalidDataException($"Each bounded group must declare exactly one {dependencyId} dependency."); } - _ = platform[0].Remove("versionFile"); - platform[0]["version"] = $"[{version}, {nextMajor}.0.0)"; + _ = bounded[0].Remove("versionFile"); + bounded[0]["version"] = exactFramework ? $"[{version}]" : $"[{version}, {nextMajor}.0.0)"; } File.WriteAllText(args[2], request.ToJsonString(), new UTF8Encoding(encoderShouldEmitUTF8Identifier: false)); diff --git a/eng/bazel/mstest-packages.bzl b/eng/bazel/mstest-packages.bzl index 885f554e3c..237ab7a4c6 100644 --- a/eng/bazel/mstest-packages.bzl +++ b/eng/bazel/mstest-packages.bzl @@ -56,6 +56,7 @@ def _package_impl(ctx): groups = [] version_files = [ctx.file.version_file] platform_version_file = None + core_version_file = None dependencies = [] for target in ctx.attr.deps: package = target[NuGetPackInfo] @@ -66,6 +67,10 @@ def _package_impl(ctx): if not version_file: fail("The native platform dependency must carry its generated version file.") platform_version_file = version_file + if ctx.attr.exact_core_dependency and package.package_id == "MSTest.TestFramework": + if not version_file: + fail("The native core dependency must carry its generated version file.") + core_version_file = version_file dependencies.append(struct( id = package.package_id, version = package.version or "", @@ -75,6 +80,10 @@ def _package_impl(ctx): if ctx.attr.bound_platform and not platform_version_file: fail("A bounded package must declare the native platform dependency.") + if ctx.attr.exact_core_dependency and not core_version_file: + fail("An exact core package must declare the native framework dependency.") + if core_version_file and platform_version_file: + fail("Core pinning and platform bounds must use separate package contracts.") if len(ctx.attr.directories) != len(ctx.attr.resource_directories): fail("Each assembly directory needs an explicit satellite-resource policy.") for framework in ctx.attr.target_frameworks: @@ -94,7 +103,7 @@ def _package_impl(ctx): external_dependencies = [] if ctx.attr.nuget_deps and framework not in ctx.split_attr.nuget_deps: fail("{} is missing external dependency metadata for {}".format(ctx.label, framework)) - external_targets = ctx.split_attr.nuget_deps.get(framework, []) + external_targets = list(ctx.split_attr.nuget_deps.get(framework, [])) if framework == "net462": external_targets += ctx.split_attr.netframework_nuget_deps.get(framework, []) for target in external_targets: @@ -133,7 +142,8 @@ def _package_impl(ctx): nupkg = ctx.actions.declare_file(ctx.label.name + "/" + ctx.label.name + ".nupkg") nuspec = ctx.actions.declare_file(ctx.label.name + "/" + ctx.label.name + ".nuspec") request = ctx.actions.declare_file(ctx.label.name + "/nuget_pack_request.json") - template = ctx.actions.declare_file(ctx.label.name + "/nuget_pack_request.template.json") if platform_version_file else request + range_version_file = core_version_file or platform_version_file + template = ctx.actions.declare_file(ctx.label.name + "/nuget_pack_request.template.json") if range_version_file else request ctx.actions.write(template, json.encode(struct( output = nupkg.path, nuspecOutput = nuspec.path, @@ -149,13 +159,18 @@ def _package_impl(ctx): dependencyGroups = groups, files = [struct(source = by_path[path].path, target = path) for path in sorted(by_path.keys())], ))) - if platform_version_file: + if range_version_file: + arguments = [template.path, range_version_file.path, request.path] + inputs = [template, range_version_file] + if core_version_file: + arguments.append("--exact-framework") + inputs.append(ctx.file.version_file) ctx.actions.run( executable = ctx.executable._range_tool, - arguments = [template.path, platform_version_file.path, request.path], - inputs = [template, platform_version_file], + arguments = arguments, + inputs = depset(inputs), outputs = [request], - mnemonic = "TestFxPlatformDependencyRange", + mnemonic = "TestFxFrameworkDependencyRange" if core_version_file else "TestFxPlatformDependencyRange", ) ctx.actions.run( executable = ctx.attr._packer[DefaultInfo].files_to_run, @@ -195,6 +210,7 @@ _package = rule( "netframework_nuget_deps": attr.label_list(providers = [DotnetAssemblyRuntimeInfo], cfg = _frameworks), "resolver_libraries": attr.label_list(providers = [DotnetAssemblyCompileInfo, DotnetAssemblyRuntimeInfo]), "bound_platform": attr.bool(), + "exact_core_dependency": attr.bool(), "package_id": attr.string(mandatory = True), "description": attr.string(mandatory = True), "readme": attr.label(allow_single_file = True, mandatory = True), @@ -338,6 +354,7 @@ def native_mstest_packages(): resource_directories = ["lib/{tfm}", "buildTransitive/{tfm}/_localization", "buildTransitive/{tfm}/_localization"], files = files, deps = [":framework_package", ":trx_abstractions_package", ":telemetry_package", ":platform_msbuild_package"], + exact_core_dependency = True, nuget_deps = ["@paket.source//microsoft.testplatform.objectmodel"], target_compatible_with = ["@platforms//os:windows"], ) diff --git a/eng/bazel/validate-mstest-packages.ps1 b/eng/bazel/validate-mstest-packages.ps1 index 66a650248e..42c5a5e654 100644 --- a/eng/bazel/validate-mstest-packages.ps1 +++ b/eng/bazel/validate-mstest-packages.ps1 @@ -221,6 +221,12 @@ function Assert-PackageLayout($Archive, $Metadata, [string] $Id) { if ($IsWindows -or $Id -ne 'MSTest.TestAdapter') { $ids += 'MSTest.TestFramework' } if ($group.targetFramework -eq 'net462') { $ids += @('System.Memory', 'System.Threading.Tasks.Extensions', 'System.Reflection.Metadata') } Assert-Names $ids @($dependencies | ForEach-Object id) "$Id dependencies" + if ($platformFrameworks.ContainsKey($Id)) { + $core = @($dependencies | Where-Object id -CEQ 'MSTest.TestFramework') + if ($core.Count -ne 1 -or $core[0].version -cne "[$mstestVersion]") { + throw "$Id must pin the matching core package version exactly." + } + } foreach ($dependency in $dependencies | Where-Object { $_.id -ne 'Microsoft.TestPlatform.ObjectModel' -and $_.id -notlike 'System.*' }) { if ($dependency.HasAttribute('exclude')) { throw "The adapter must retain build/analyzer assets from $($dependency.id)." } }