Drop the ObjectModel package reference from PlatformServices (Phase 7 capstone)#9633
Draft
Evangelink wants to merge 1 commit into
Conversation
605ee46 to
37c3973
Compare
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>
37c3973 to
16552c6
Compare
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Phase 7 (capstone) — drop the ObjectModel package reference
The final slice of the initiative to make
Microsoft.VisualStudio.TestPlatform.MSTestAdapter.PlatformServicesplatform-agnostic. After this, PlatformServices no longer references the VSTest object model (Microsoft.TestPlatform.ObjectModel) at all — every VSTest dependency now lives in theMSTest.TestAdapterlayer above it. Strict byte-for-byte, no behavior change.Production changes
Microsoft.TestPlatform.ObjectModelPackageReferencefromMSTestAdapter.PlatformServices.csproj.RunConfigurationSettingswas the last consumer of a transitively-provided VSTest package: it usedPlatformAbstractions'PlatformApartmentStateenum{MTA, STA}to parseExecutionThreadApartmentState. Replaced with a localinternal enum ApartmentStateSetting { MTA, STA }of the same shape (same member names and order —MTA=0, STA=1), preserving the exactEnum.TryParse→STA/MTA → System.Threading.ApartmentState / else-throwbehavior byte-for-byte on both the runsettings-XML and config paths. The member order is load-bearing (Enum.TryParseaccepts numeric strings"0"/"1", so the numbering must match) and is commented as such. (Parsing directly toSystem.Threading.ApartmentStatewould change the handling of theUnknownvalue — it has that extra member — so a faithful 2-member local enum is required. The property type stays the BCLSystem.Threading.ApartmentState; only the parse-enum is neutralized.)System.Configurationframework reference on .NET Framework.ConfigurationManager/ConfigurationElementCollection(used byTestDataSource) were previously pulled in transitively via the object-model package;System.Configurationis a framework assembly, so it is now referenced directly.Result: PlatformServices is fully platform-neutral
The compiled
MSTestAdapter.PlatformServicesassembly has zero references to anyMicrosoft.*.TestPlatform.*assembly on every real TFM (net462/net8.0/net9.0 + windows variants), verified via assembly metadata.Guard test (the finish line)
ObjectModelDecouplingTestsasserts the compiled PlatformServices assembly references no assembly whose name contains"TestPlatform"— catching ObjectModel, PlatformAbstractions, CoreUtilities, etc. (MSTest's own framework isMSTest.TestFramework, which doesn't match). This locks the platform-agnostic contract permanently.Test-project fix
PlatformServices.Desktop.IntegrationTestsuses ObjectModel'sXmlRunSettingsUtilitiesdirectly (previously transitive through the PlatformServices project reference), so it gets its own directMicrosoft.TestPlatform.ObjectModelPackageReference. Test projects may reference the object model; only the production assembly must be neutral.Verification
TestPlatformreferences (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.TestAdapterandMSTest.IntegrationTestsbuild clean.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.