Skip to content

Remove Polyfill NuGet package dependency#7597

Open
Evangelink wants to merge 5 commits intomainfrom
remove-polyfill-dependency
Open

Remove Polyfill NuGet package dependency#7597
Evangelink wants to merge 5 commits intomainfrom
remove-polyfill-dependency

Conversation

@Evangelink
Copy link
Copy Markdown
Member

Replace the Polyfill NuGet package with a self-contained eng/Polyfills.cs file and project-specific polyfill extension methods.

Changes

  • Remove Polyfill PackageReference from all 35 csproj files
  • Remove Polyfill configuration (PolyEnsure, PolyGuard, PolyStringInterpolation, PolyUseEmbeddedAttribute) from Directory.Build.props
  • Remove PackageVersion entry from Directory.Packages.props
  • Remove global <Using Include="Polyfills" /> directives from 12 csproj files
  • Remove explicit using Polyfills; from source files
  • Remove Polyfill-specific GlobalSuppressions entry

Replacements

  • eng/Polyfills.cs — Shared polyfill types and attributes for older TFMs (netstandard2.0, net462): nullable attributes, compiler attributes, ExperimentalAttribute, Index/Range, Lock, OperatingSystem, UnreachableException, Ensure helper, etc.
  • Project-specific polyfill extensions — Extension methods scoped to projects that need them to avoid IVT ambiguity:
    • src/Platform/Microsoft.Testing.Platform/Helpers/KeyValuePairDeconstruct.cs
    • src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/PolyfillExtensions.cs
    • src/TestFramework/TestFramework/Internal/PolyfillExtensions.cs
    • src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs
    • src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.cs

Call-site fixes

Fixed code that relied on Polyfill-provided APIs not available on older TFMs: SHA256.HashData, Convert.ToHexStringLower, Environment.ProcessId, File.Move (3-arg), File.ReadAllTextAsync, Enum.Parse<T>, Enum.GetNames<T>, Enum.IsDefined<T>, Enum.GetValues<T>, XElement.LoadAsync, XDocument.SaveAsync, Type.IsGenericMethodParameter, string.Join(char, ...), ConcurrentBag.Clear, ConcurrentDictionary.GetOrAdd (3-arg), and TextWriter.FlushAsync(CancellationToken).

Fixes #7596

Replace the Polyfill NuGet package with a self-contained eng/Polyfills.cs
file and project-specific polyfill extensions.

- Remove Polyfill PackageReference from all 35 csproj files
- Remove Polyfill configuration (PolyEnsure, PolyGuard, etc.) from Directory.Build.props
- Remove PackageVersion from Directory.Packages.props
- Remove global using Polyfills directives from csproj files
- Add eng/Polyfills.cs with type stubs and attributes for older TFMs
- Add project-specific polyfill extension methods where needed
- Fix call sites for APIs not available on netstandard2.0/net462

Fixes #7596
Copilot AI review requested due to automatic review settings March 24, 2026 10:32
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR removes the third-party Polyfill NuGet dependency across the repo and replaces it with a shared, source-included polyfill implementation (eng/Polyfills.cs) plus a few project-scoped polyfill extension files to keep older TFMs building cleanly.

Changes:

  • Removed Polyfill PackageReference entries (and related MSBuild config/global usings) across projects.
  • Added eng/Polyfills.cs and wired it into builds via Directory.Build.props.
  • Updated call sites to avoid APIs/overloads not available on older TFMs (e.g., Enum.Parse<T>, Environment.ProcessId, async XML load/save, etc.).

Reviewed changes

Copilot reviewed 67 out of 67 changed files in this pull request and generated 7 comments.

Show a summary per file
File Description
test/Utilities/TestFramework.ForTestingMSTest/TestFramework.ForTestingMSTest.csproj Removes Polyfill package reference.
test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csproj Removes Polyfill package reference and Polyfills using.
test/Utilities/Automation.CLI/Automation.CLI.csproj Removes Polyfill package reference.
test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csproj Removes Polyfill package reference.
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs Switches to Split(char) overload for compatibility.
test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csproj Removes Polyfill package reference and Polyfills using.
test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csproj Removes Polyfill package reference.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csproj Removes Polyfill package reference.
test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csproj Removes Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/ObjectModel/UnitTestElementTests.cs Replaces Enum.GetValues<T>() with non-generic overload for older TFMs.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csproj Removes Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.MockedMethodInfoWithExtraAttributes.cs Removes conditional using Polyfills;.
test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj Removes Polyfill package reference.
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csproj Removes Polyfill package reference.
test/IntegrationTests/MSTest.IntegrationTests/Utilities/TestCaseFilterFactory.cs Removes using Polyfills;.
test/IntegrationTests/MSTest.IntegrationTests/MSTest.IntegrationTests.csproj Removes Polyfill package reference.
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csproj Removes Polyfill package reference.
src/TestFramework/TestFramework/TestFramework.csproj Removes Polyfill package reference and Polyfills using.
src/TestFramework/TestFramework/Internal/TestDataSourceUtilities.cs Replaces string.Join(char, …) with string separator overload for older TFMs.
src/TestFramework/TestFramework/Internal/PolyfillExtensions.cs Adds TestFramework-scoped polyfill extensions.
src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj Removes Polyfill package reference and Polyfills using.
src/Platform/Microsoft.Testing.Platform/Services/ExecutableInfo.cs Replaces string.Join(char, …) usage with string separator overload.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/TcpMessageHandler.cs Adjusts flush logic to avoid FlushAsync(CancellationToken) dependency.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/ServerModePerCallOutputDevice.cs Replaces ConcurrentBag.Clear() with fallback loop for non-NETCOREAPP.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.cs Replaces string.Join(char, …) usage with string separator overload.
src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemFileSystem.cs Adds polyfilled File.Move(overwrite) and async file-read fallback.
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemEnvironment.cs Adds Environment.ProcessId fallback for older TFMs.
src/Platform/Microsoft.Testing.Platform/Helpers/Sha256Hasher.cs Adds hashing/hex formatting fallbacks for older TFMs.
src/Platform/Microsoft.Testing.Platform/Helpers/KeyValuePairDeconstruct.cs Adds Platform-scoped KeyValuePair Deconstruct polyfill.
src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs Replaces Enum.Parse<T> with non-generic overload for older TFMs.
src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.cs Replaces Enum.Parse<T> with non-generic overloads for older TFMs.
src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csproj Removes Polyfill package reference and Polyfills using.
src/Platform/Microsoft.Testing.Platform.AI/Microsoft.Testing.Platform.AI.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj Removes Polyfill package reference and Polyfills using.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.cs Adds async XML save fallback for non-NETCOREAPP.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCompareTool.cs Adds async XML load fallback for non-NETCOREAPP.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csproj Removes Polyfill package reference and Polyfills using.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/EmbeddedAttribute.cs Removes local EmbeddedAttribute in favor of shared polyfills file.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/PolyfillExtensions.cs Adds Abstractions-scoped polyfill extensions (StringBuilder.AppendJoin).
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/Microsoft.Testing.Extensions.TrxReport.Abstractions.csproj Removes Polyfill package reference and Polyfills using.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/GlobalSuppressions.cs Removes Polyfill-specific suppression entry.
src/Platform/Microsoft.Testing.Extensions.Telemetry/Microsoft.Testing.Extensions.Telemetry.csproj Removes Polyfill package reference and Polyfills using.
src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/Microsoft.Testing.Extensions.OpenTelemetry.csproj Removes Polyfill package reference and Polyfills using.
src/Platform/Microsoft.Testing.Extensions.MSBuild/Microsoft.Testing.Extensions.MSBuild.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HotReload/Microsoft.Testing.Extensions.HotReload.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HangDump/Microsoft.Testing.Extensions.HangDump.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureFoundry/Microsoft.Testing.Extensions.AzureFoundry.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/Microsoft.Testing.Extensions.AzureDevOpsReport.csproj Removes Polyfill package reference.
src/Analyzers/MSTest.SourceGeneration/Helpers/SystemPolyfills.cs Removes local type polyfills in favor of shared eng/Polyfills.cs.
src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.cs Adds analyzer-scoped polyfill extensions.
src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csproj Removes Polyfill package reference.
src/Analyzers/MSTest.Analyzers.CodeFixes/MSTest.Analyzers.CodeFixes.csproj Removes Polyfill package reference.
src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.cs Replaces Environment.ProcessId usage with fallback.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestSourceHost.cs Replaces string.Join(char, …) with string separator overload in updated call site.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.cs Replaces Enum.Parse<T> with non-generic overload.
src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs Adds adapter-scoped polyfill extensions (including CTS.CancelAsync for < net8).
src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.cs Replaces generic Enum APIs with non-generic overloads for older TFMs.
src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj Removes Polyfill package reference and Polyfills using.
src/Adapter/MSTestAdapter.PlatformServices/Extensions/MethodInfoExtensions.cs Replaces Type.IsGenericMethodParameter usage with portable logic.
src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj Removes Polyfill package reference and Polyfills using.
src/Adapter/MSTest.Engine/MSTest.Engine.csproj Removes Polyfill package reference.
eng/Polyfills.cs Adds shared repo-wide polyfill implementations and (conditionally) extension polyfills.
Directory.Packages.props Removes Polyfill package version entry.
Directory.Build.props Removes Polyfill MSBuild config and adds compilation of eng/Polyfills.cs.

Copilot AI review requested due to automatic review settings March 26, 2026 11:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

Copilot reviewed 73 out of 73 changed files in this pull request and generated 1 comment.

…d param

- Add Polyfills.Guard, Polyfills.Ensure, and Polyfills.Polyfill backward-
  compatible types in eng/Polyfills.cs (guarded by IS_CORE_MTP) to prevent
  TypeLoadException/MissingMethodException when old extension packages
  reference these types from the platform assembly via InternalsVisibleTo.
- Fix unused cancellationToken parameter in TrxReportEngine constructor
  for netstandard2.0 builds (addresses PR review comment).
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.

Consider removing Polyfill NuGet package dependency

2 participants