Skip to content

Drop the ObjectModel package reference from PlatformServices (Phase 7 capstone)#9633

Draft
Evangelink wants to merge 1 commit into
dev/amauryleve/vstest-decoupling-suspendcoveragefrom
dev/amauryleve/vstest-decoupling-drop-objectmodel
Draft

Drop the ObjectModel package reference from PlatformServices (Phase 7 capstone)#9633
Evangelink wants to merge 1 commit into
dev/amauryleve/vstest-decoupling-suspendcoveragefrom
dev/amauryleve/vstest-decoupling-drop-objectmodel

Conversation

@Evangelink

@Evangelink Evangelink commented Jul 5, 2026

Copy link
Copy Markdown
Member

Phase 7 (capstone) — drop the ObjectModel package reference

The final slice of the initiative to make Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServices platform-agnostic. After this, PlatformServices no longer references the VSTest object model (Microsoft.TestPlatform.ObjectModel) at all — every VSTest dependency now lives in the MSTest.TestAdapter layer above it. Strict byte-for-byte, no behavior change.

Production changes

  1. Remove the Microsoft.TestPlatform.ObjectModel PackageReference from MSTestAdapter.PlatformServices.csproj.
  2. RunConfigurationSettings was the last consumer of a transitively-provided VSTest package: it used PlatformAbstractions' PlatformApartmentState enum {MTA, STA} to parse ExecutionThreadApartmentState. Replaced with a local internal enum ApartmentStateSetting { MTA, STA } of the same shape (same member names and order — MTA=0, STA=1), preserving the exact Enum.TryParseSTA/MTA → System.Threading.ApartmentState / else-throw behavior byte-for-byte on both the runsettings-XML and config paths. The member order is load-bearing (Enum.TryParse accepts numeric strings "0"/"1", so the numbering must match) and is commented as such. (Parsing directly to System.Threading.ApartmentState would change the handling of the Unknown value — it has that extra member — so a faithful 2-member local enum is required. The property type stays the BCL System.Threading.ApartmentState; only the parse-enum is neutralized.)
  3. Add a direct System.Configuration framework reference on .NET Framework. ConfigurationManager/ConfigurationElementCollection (used by TestDataSource) were previously pulled in transitively via the object-model package; System.Configuration is a framework assembly, so it is now referenced directly.

Result: PlatformServices is fully platform-neutral

The compiled MSTestAdapter.PlatformServices assembly has zero references to any Microsoft.*.TestPlatform.* assembly on every real TFM (net462/net8.0/net9.0 + windows variants), verified via assembly metadata.

Guard test (the finish line)

ObjectModelDecouplingTests asserts the compiled PlatformServices assembly references no assembly whose name contains "TestPlatform" — catching ObjectModel, PlatformAbstractions, CoreUtilities, etc. (MSTest's own framework is MSTest.TestFramework, which doesn't match). This locks the platform-agnostic contract permanently.

Test-project fix

PlatformServices.Desktop.IntegrationTests uses ObjectModel's XmlRunSettingsUtilities directly (previously transitive through the PlatformServices project reference), so it gets its own direct Microsoft.TestPlatform.ObjectModel PackageReference. Test projects may reference the object model; only the production assembly must be neutral.

Verification

  • All real TFMs build 0-warning (UWP builds via full msbuild in CI).
  • Compiled dll: zero TestPlatform references (net462 + net8.0, metadata-verified).
  • MSTestAdapter.PlatformServices.UnitTests: 936/936 (net462), 898/898 (net8.0) — includes the new guard test and the STA/MTA parsing tests on both the runsettings-XML and config paths.
  • PlatformServices.Desktop.IntegrationTests: 15/15.
  • MSTestAdapter.UnitTests: 21/21. MSTest.TestAdapter and MSTest.IntegrationTests build clean.
  • Expert-reviewer pass.

Stacking

Stacks on #9632 (Phase 6e-4c3); base branch dev/amauryleve/vstest-decoupling-suspendcoverage. Review/merge after the earlier PRs in the chain reach the base. Do not squash-rebase the base.

@Evangelink Evangelink force-pushed the dev/amauryleve/vstest-decoupling-drop-objectmodel branch from 605ee46 to 37c3973 Compare July 5, 2026 13:57
This is the capstone of the initiative: MSTestAdapter.PlatformServices no longer
references the VSTest object model (Microsoft.TestPlatform.ObjectModel) at all.

Production changes:
- Remove the Microsoft.TestPlatform.ObjectModel PackageReference from
  MSTestAdapter.PlatformServices.csproj.
- The only remaining consumer of a transitively-provided VSTest package was
  RunConfigurationSettings, which used PlatformAbstractions' PlatformApartmentState
  enum {MTA, STA} to parse ExecutionThreadApartmentState. Replace it with a local
  internal enum of the same shape (same member names/order), preserving the exact
  Enum.TryParse-then-map-to-System.Threading.ApartmentState behavior byte-for-byte
  (a 2-member by-name parse is identical; parsing directly to ApartmentState would
  change the handling of the "Unknown" value, so a faithful local enum is required).
- Add a direct framework reference to System.Configuration on .NET Framework.
  ConfigurationManager/ConfigurationElementCollection (used by TestDataSource) were
  previously pulled in transitively via the object-model package; System.Configuration
  is a framework assembly, so it is now referenced directly.

Result: the compiled MSTestAdapter.PlatformServices assembly has ZERO references to
any Microsoft.*.TestPlatform.* assembly on every real target framework
(net462/net8.0/net9.0 + windows variants), verified via assembly metadata. All VSTest
coupling now lives in the MSTest.TestAdapter layer above it.

Guard test:
- ObjectModelDecouplingTests asserts the compiled PlatformServices assembly references
  no assembly whose name contains "TestPlatform" (catches ObjectModel,
  PlatformAbstractions, CoreUtilities, ...; MSTest's own framework is "MSTest.TestFramework",
  which does not match). This locks the platform-agnostic contract permanently.

Test-project fix:
- PlatformServices.Desktop.IntegrationTests uses ObjectModel's XmlRunSettingsUtilities
  directly (previously transitive through the PlatformServices project reference), so it
  gets its own direct Microsoft.TestPlatform.ObjectModel PackageReference. Test projects
  are allowed to reference the object model; only the production assembly must be neutral.

Verified: PlatformServices builds 0-warning on all real TFMs (UWP builds via full msbuild
in CI); PlatformServices.UnitTests 936 (net462) / 898 (net8.0) incl. the new guard test and
the STA/MTA parsing tests on both the runsettings-XML and config paths;
PlatformServices.Desktop.IntegrationTests 15/15; MSTestAdapter.UnitTests 21/21;
MSTest.TestAdapter and MSTest.IntegrationTests build clean.

Co-authored-by: Copilot App <223556219+Copilot@users.noreply.github.com>
@Evangelink Evangelink force-pushed the dev/amauryleve/vstest-decoupling-drop-objectmodel branch from 37c3973 to 16552c6 Compare July 5, 2026 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant