Remove Polyfill NuGet package dependency - #7597

Closed
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
remove-polyfill-dependency
Closed

Remove Polyfill NuGet package dependency#7597
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
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
CopilotAI review requested due to automatic review settings March 24, 2026 10:32

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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

Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs Outdated
Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.cs Outdated
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs Outdated
CopilotAI review requested due to automatic review settings March 26, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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).
Comment threadDirectory.Build.props Outdated
Comment threadeng/Polyfills.cs Outdated
Comment threadeng/Polyfills.cs
CopilotAI review requested due to automatic review settings April 9, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Removes the external Polyfill NuGet dependency across the repo and replaces it with an in-repo shared polyfill source file (eng/Polyfills.cs) plus a few project-scoped polyfill extension files, updating call sites to avoid newer BCL APIs on older TFMs.

Changes:

  • Removed PolyfillPackageReferences (and related Poly* configuration / Using Include="Polyfills" items) from projects and central package management.
  • Added eng/Polyfills.cs and several project-scoped polyfill extension files to replace previously generated APIs and avoid IVT ambiguity.
  • Updated code paths to use older-compatible APIs (e.g., enum parsing, file operations, hashing, async XML APIs, TextWriter.FlushAsync(CancellationToken)).
Show a summary per file
FileDescription
test/Utilities/TestFramework.ForTestingMSTest/TestFramework.ForTestingMSTest.csprojRemoves Polyfill package reference from test utility project.
test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csprojRemoves Polyfill package and Using Polyfills item.
test/Utilities/Automation.CLI/Automation.CLI.csprojRemoves Polyfill package reference.
test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csprojRemoves Polyfill package reference from unit tests.
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.csReplaces string split call with older-compatible overload usage.
test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/ObjectModel/UnitTestElementTests.csReplaces generic Enum API usage with non-generic alternative.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.MockedMethodInfoWithExtraAttributes.csRemoves conditional using Polyfills;.
test/UnitTests/MSTest.SourceGeneration.UnitTests/TestUtilities/GeneratorTester.csIntroduces extern alias usage to disambiguate referenced analyzer types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/ObjectModels/InlineTestMethodArgumentsInfoTests.csIntroduces extern alias usage for SourceGeneration object model types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/MSTest.SourceGeneration.UnitTests.csprojExcludes shared polyfills and adds analyzer reference aliasing.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Helpers/ConstantsTests.csUses extern alias for SourceGeneration Constants.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Generators/TestNodesGeneratorTests.csUses extern alias for generator type references.
test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csprojRemoves Polyfill package reference from analyzer unit tests.
test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csprojRemoves Polyfill package reference and Using Polyfills item.
test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.IntegrationTests/Utilities/TestCaseFilterFactory.csRemoves using Polyfills;.
test/IntegrationTests/MSTest.IntegrationTests/MSTest.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
src/TestFramework/TestFramework/TestFramework.csprojRemoves Polyfill package reference and Using Polyfills item.
src/TestFramework/TestFramework/Internal/TestDataSourceUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/TestFramework/TestFramework/Internal/PolyfillExtensions.csAdds TestFramework-scoped polyfill extension methods.
src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform/Services/ExecutableInfo.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/TcpMessageHandler.csAdds framework-conditional flush behavior (with/without CancellationToken overload).
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/ServerModePerCallOutputDevice.csAdds framework-conditional ConcurrentBag.Clear replacement.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csprojRemoves Polyfill package reference (core platform now uses source polyfills).
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemFileSystem.csAdds TFM-conditional implementations for File.Move overwrite and async read.
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemEnvironment.csAdds fallback ProcessId implementation for older TFMs.
src/Platform/Microsoft.Testing.Platform/Helpers/Sha256Hasher.csAdds TFM-conditional SHA256 hashing + hex formatting implementations.
src/Platform/Microsoft.Testing.Platform/Helpers/KeyValuePairDeconstruct.csAdds platform-scoped KeyValuePair deconstruction polyfill.
src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.csReplaces generic Enum.Parse usage with non-generic alternative on older TFMs.
src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.csReplaces generic Enum.Parse usage with non-generic alternatives.
src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform.AI/Microsoft.Testing.Platform.AI.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.csAdds TFM-conditional async XML save handling and cancellation token storage.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCompareTool.csAdds TFM-conditional async XML load handling.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/PolyfillExtensions.csAdds TrxReport.Abstractions-scoped polyfill extension methods.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/Microsoft.Testing.Extensions.TrxReport.Abstractions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/GlobalSuppressions.csRemoves Polyfill-generated suppression entry.
src/Platform/Microsoft.Testing.Extensions.Telemetry/Microsoft.Testing.Extensions.Telemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/Microsoft.Testing.Extensions.OpenTelemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.MSBuild/Microsoft.Testing.Extensions.MSBuild.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HotReload/Microsoft.Testing.Extensions.HotReload.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HangDump/Microsoft.Testing.Extensions.HangDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureFoundry/Microsoft.Testing.Extensions.AzureFoundry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/Microsoft.Testing.Extensions.AzureDevOpsReport.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.SourceGeneration/Helpers/SystemPolyfills.csRemoves local polyfill type definitions (now provided by shared polyfills).
src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.csAdds analyzer-scoped polyfill extension methods.
src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.Analyzers.CodeFixes/MSTest.Analyzers.CodeFixes.csprojRemoves Polyfill package reference.
src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.csReplaces Environment.ProcessId usage with older-compatible implementation.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestSourceHost.csReplaces string.Join(char, ...) with compatible overload.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.csReplaces generic Enum.Parse usage with non-generic alternative.
src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.csAdds adapter-scoped polyfill extension methods (including CancelAsync polyfill).
src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.csReplaces generic Enum APIs with non-generic alternatives for older TFMs.
src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTestAdapter.PlatformServices/Extensions/MethodInfoExtensions.csReplaces Type.IsGenericMethodParameter usage with older-compatible checks.
src/Adapter/MSTestAdapter.PlatformServices/Execution/Polyfills/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTest.Engine/MSTest.Engine.csprojRemoves Polyfill package reference.
eng/Polyfills.csAdds shared polyfill types/attributes and (for core platform) some extension-method polyfills.
Directory.Packages.propsRemoves central Polyfill package version entry.
Directory.Build.propsRemoves Polyfill configuration properties and globally includes eng/Polyfills.cs for C# projects.

Copilot's findings

Comments suppressed due to low confidence (1)

eng/Polyfills.cs:763

  • The CancelAsync polyfill uses an empty busy-wait loop (while (!...IsCancellationRequested) { }), which can burn CPU on netstandard2.0/net462 for no real benefit (the returned Task.Run(cts.Cancel) already completes after cancellation is requested and callbacks run). Please remove the spin-wait and return the task directly (or use a non-spinning wait strategy).
 public static global::System.Threading.Tasks.Task CancelAsync(this global::System.Threading.CancellationTokenSource cancellationTokenSource)
{
if (cancellationTokenSource.IsCancellationRequested)
{
return global::System.Threading.Tasks.Task.CompletedTask;
}
global::System.Threading.Tasks.Task task = global::System.Threading.Tasks.Task.Run(cancellationTokenSource.Cancel);
while (!cancellationTokenSource.IsCancellationRequested)
{
}
return task;
}
  • Files reviewed: 73/73 changed files
  • Comments generated: 3

Comment threadeng/Polyfills.cs
Comment on lines +405 to +407
public static Index FromStart(int value) => value >= 0 ? new Index(value) : throw new IndexOutOfRangeException(nameof(value));

public static Index FromEnd(int value) => value >= 0 ? new Index(~value) : throw new IndexOutOfRangeException(nameof(value));

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Index.FromStart/Index.FromEnd throw IndexOutOfRangeException for negative inputs, which differs from the BCL behavior (it throws ArgumentOutOfRangeException). To keep the polyfill behavior aligned and avoid surprising exception handling differences, switch these to ArgumentOutOfRangeException (consistent with the Index(int value, ...) ctor above).

Suggested change
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewArgumentOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewArgumentOutOfRangeException(nameof(value));

Copilot uses AI. Check for mistakes.
Comment threadeng/Polyfills.cs
throw new global::System.ArgumentNullException(paramName);
}

if (argument.Trim().Length == 0)

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Ensure.NotNullOrWhiteSpace uses argument.Trim().Length == 0, which allocates a new string and is less efficient than string.IsNullOrWhiteSpace(argument) (available on all supported TFMs once null is checked). Consider replacing the trim-based check to avoid unnecessary allocations in guard code.

This issue also appears on line 749 of the same file.

Suggested change
if(argument.Trim().Length==0)
if(global::System.String.IsNullOrWhiteSpace(argument))

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +86
var task = System.Threading.Tasks.Task.Run(cts.Cancel);

while (!cts.IsCancellationRequested)
{
}

return task;

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

AdapterCancellationTokenSourcePolyfill.CancelAsync contains a tight busy-wait loop (while (!cts.IsCancellationRequested) { }). This can cause avoidable CPU spikes on .NET Framework. Since you already have Task.Run(cts.Cancel), return that task (or implement a non-spinning completion mechanism) rather than spinning.

Suggested change
vartask=System.Threading.Tasks.Task.Run(cts.Cancel);
while(!cts.IsCancellationRequested)
{
}
returntask;
returnSystem.Threading.Tasks.Task.Run(cts.Cancel);

Copilot uses AI. Check for mistakes.
auto-merge was automatically disabled April 13, 2026 13:31

Pull request was closed

@Evangelink
Amaury Levé (Evangelink) deleted the remove-polyfill-dependency branch April 13, 2026 13:31
@nohwnd
Jakub Jareš (nohwnd) restored the remove-polyfill-dependency branch April 13, 2026 14:53
@nohwnd

Copy link
Copy Markdown
Member

@Youssef1313

Copy link
Copy Markdown
Member

Replacing with #7726

@Youssef1313
Youssef Fahmy (Youssef1313) deleted the remove-polyfill-dependency branch April 15, 2026 13:46
Sign up for freeto 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

4 participants

@Evangelink@nohwnd@Youssef1313
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Add copy buttons to all
 blocks\n(function() {\n function addCopyButtons() {\n document.querySelectorAll('pre code').forEach(function(codeBlock) {\n if (codeBlock.parentElement.hasAttribute('data-copy-added')) return;\n codeBlock.parentElement.setAttribute('data-copy-added', 'true');\n \n var btn = document.createElement('button');\n btn.textContent = 'Copy';\n btn.style.cssText = 'position:absolute;top:4px;right:4px;padding:2px 8px;font-size:11px;background:#4ecdc4;border:none;border-radius:4px;color:#1a1a2e;cursor:pointer;opacity:0.7;transition:opacity 0.2s;';\n btn.onmouseover = function() { this.style.opacity = '1'; };\n btn.onmouseout = function() { this.style.opacity = '0.7'; };\n btn.onclick = function() {\n navigator.clipboard.writeText(codeBlock.textContent).then(function() {\n btn.textContent = 'Copied!';\n setTimeout(function() { btn.textContent = 'Copy'; }, 1500);\n });\n };\n codeBlock.parentElement.style.position = 'relative';\n codeBlock.parentElement.appendChild(btn);\n });\n }\n \n addCopyButtons();\n \n // Re-run on dynamic content\n var observer = new MutationObserver(addCopyButtons);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Add Copy Buttons to Code Blocks");
}
} catch(__e) { console.warn('[Userscript:Add Copy Buttons to Code Blocks]', __e); }
})();
(function(){
try {
var __m = "github.com";
var __re = new RegExp('^' + "github\\.com" + '
Skip to content

Remove Polyfill NuGet package dependency - #7597

Closed
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
remove-polyfill-dependency
Closed

Remove Polyfill NuGet package dependency#7597
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
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
CopilotAI review requested due to automatic review settings March 24, 2026 10:32

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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

Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs Outdated
Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.cs Outdated
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs Outdated
CopilotAI review requested due to automatic review settings March 26, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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).
Comment threadDirectory.Build.props Outdated
Comment threadeng/Polyfills.cs Outdated
Comment threadeng/Polyfills.cs
CopilotAI review requested due to automatic review settings April 9, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Removes the external Polyfill NuGet dependency across the repo and replaces it with an in-repo shared polyfill source file (eng/Polyfills.cs) plus a few project-scoped polyfill extension files, updating call sites to avoid newer BCL APIs on older TFMs.

Changes:

  • Removed PolyfillPackageReferences (and related Poly* configuration / Using Include="Polyfills" items) from projects and central package management.
  • Added eng/Polyfills.cs and several project-scoped polyfill extension files to replace previously generated APIs and avoid IVT ambiguity.
  • Updated code paths to use older-compatible APIs (e.g., enum parsing, file operations, hashing, async XML APIs, TextWriter.FlushAsync(CancellationToken)).
Show a summary per file
FileDescription
test/Utilities/TestFramework.ForTestingMSTest/TestFramework.ForTestingMSTest.csprojRemoves Polyfill package reference from test utility project.
test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csprojRemoves Polyfill package and Using Polyfills item.
test/Utilities/Automation.CLI/Automation.CLI.csprojRemoves Polyfill package reference.
test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csprojRemoves Polyfill package reference from unit tests.
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.csReplaces string split call with older-compatible overload usage.
test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/ObjectModel/UnitTestElementTests.csReplaces generic Enum API usage with non-generic alternative.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.MockedMethodInfoWithExtraAttributes.csRemoves conditional using Polyfills;.
test/UnitTests/MSTest.SourceGeneration.UnitTests/TestUtilities/GeneratorTester.csIntroduces extern alias usage to disambiguate referenced analyzer types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/ObjectModels/InlineTestMethodArgumentsInfoTests.csIntroduces extern alias usage for SourceGeneration object model types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/MSTest.SourceGeneration.UnitTests.csprojExcludes shared polyfills and adds analyzer reference aliasing.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Helpers/ConstantsTests.csUses extern alias for SourceGeneration Constants.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Generators/TestNodesGeneratorTests.csUses extern alias for generator type references.
test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csprojRemoves Polyfill package reference from analyzer unit tests.
test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csprojRemoves Polyfill package reference and Using Polyfills item.
test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.IntegrationTests/Utilities/TestCaseFilterFactory.csRemoves using Polyfills;.
test/IntegrationTests/MSTest.IntegrationTests/MSTest.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
src/TestFramework/TestFramework/TestFramework.csprojRemoves Polyfill package reference and Using Polyfills item.
src/TestFramework/TestFramework/Internal/TestDataSourceUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/TestFramework/TestFramework/Internal/PolyfillExtensions.csAdds TestFramework-scoped polyfill extension methods.
src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform/Services/ExecutableInfo.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/TcpMessageHandler.csAdds framework-conditional flush behavior (with/without CancellationToken overload).
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/ServerModePerCallOutputDevice.csAdds framework-conditional ConcurrentBag.Clear replacement.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csprojRemoves Polyfill package reference (core platform now uses source polyfills).
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemFileSystem.csAdds TFM-conditional implementations for File.Move overwrite and async read.
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemEnvironment.csAdds fallback ProcessId implementation for older TFMs.
src/Platform/Microsoft.Testing.Platform/Helpers/Sha256Hasher.csAdds TFM-conditional SHA256 hashing + hex formatting implementations.
src/Platform/Microsoft.Testing.Platform/Helpers/KeyValuePairDeconstruct.csAdds platform-scoped KeyValuePair deconstruction polyfill.
src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.csReplaces generic Enum.Parse usage with non-generic alternative on older TFMs.
src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.csReplaces generic Enum.Parse usage with non-generic alternatives.
src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform.AI/Microsoft.Testing.Platform.AI.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.csAdds TFM-conditional async XML save handling and cancellation token storage.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCompareTool.csAdds TFM-conditional async XML load handling.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/PolyfillExtensions.csAdds TrxReport.Abstractions-scoped polyfill extension methods.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/Microsoft.Testing.Extensions.TrxReport.Abstractions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/GlobalSuppressions.csRemoves Polyfill-generated suppression entry.
src/Platform/Microsoft.Testing.Extensions.Telemetry/Microsoft.Testing.Extensions.Telemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/Microsoft.Testing.Extensions.OpenTelemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.MSBuild/Microsoft.Testing.Extensions.MSBuild.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HotReload/Microsoft.Testing.Extensions.HotReload.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HangDump/Microsoft.Testing.Extensions.HangDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureFoundry/Microsoft.Testing.Extensions.AzureFoundry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/Microsoft.Testing.Extensions.AzureDevOpsReport.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.SourceGeneration/Helpers/SystemPolyfills.csRemoves local polyfill type definitions (now provided by shared polyfills).
src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.csAdds analyzer-scoped polyfill extension methods.
src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.Analyzers.CodeFixes/MSTest.Analyzers.CodeFixes.csprojRemoves Polyfill package reference.
src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.csReplaces Environment.ProcessId usage with older-compatible implementation.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestSourceHost.csReplaces string.Join(char, ...) with compatible overload.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.csReplaces generic Enum.Parse usage with non-generic alternative.
src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.csAdds adapter-scoped polyfill extension methods (including CancelAsync polyfill).
src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.csReplaces generic Enum APIs with non-generic alternatives for older TFMs.
src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTestAdapter.PlatformServices/Extensions/MethodInfoExtensions.csReplaces Type.IsGenericMethodParameter usage with older-compatible checks.
src/Adapter/MSTestAdapter.PlatformServices/Execution/Polyfills/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTest.Engine/MSTest.Engine.csprojRemoves Polyfill package reference.
eng/Polyfills.csAdds shared polyfill types/attributes and (for core platform) some extension-method polyfills.
Directory.Packages.propsRemoves central Polyfill package version entry.
Directory.Build.propsRemoves Polyfill configuration properties and globally includes eng/Polyfills.cs for C# projects.

Copilot's findings

Comments suppressed due to low confidence (1)

eng/Polyfills.cs:763

  • The CancelAsync polyfill uses an empty busy-wait loop (while (!...IsCancellationRequested) { }), which can burn CPU on netstandard2.0/net462 for no real benefit (the returned Task.Run(cts.Cancel) already completes after cancellation is requested and callbacks run). Please remove the spin-wait and return the task directly (or use a non-spinning wait strategy).
 public static global::System.Threading.Tasks.Task CancelAsync(this global::System.Threading.CancellationTokenSource cancellationTokenSource)
{
if (cancellationTokenSource.IsCancellationRequested)
{
return global::System.Threading.Tasks.Task.CompletedTask;
}
global::System.Threading.Tasks.Task task = global::System.Threading.Tasks.Task.Run(cancellationTokenSource.Cancel);
while (!cancellationTokenSource.IsCancellationRequested)
{
}
return task;
}
  • Files reviewed: 73/73 changed files
  • Comments generated: 3

Comment threadeng/Polyfills.cs
Comment on lines +405 to +407
public static Index FromStart(int value) => value >= 0 ? new Index(value) : throw new IndexOutOfRangeException(nameof(value));

public static Index FromEnd(int value) => value >= 0 ? new Index(~value) : throw new IndexOutOfRangeException(nameof(value));

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Index.FromStart/Index.FromEnd throw IndexOutOfRangeException for negative inputs, which differs from the BCL behavior (it throws ArgumentOutOfRangeException). To keep the polyfill behavior aligned and avoid surprising exception handling differences, switch these to ArgumentOutOfRangeException (consistent with the Index(int value, ...) ctor above).

Suggested change
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewArgumentOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewArgumentOutOfRangeException(nameof(value));

Copilot uses AI. Check for mistakes.
Comment threadeng/Polyfills.cs
throw new global::System.ArgumentNullException(paramName);
}

if (argument.Trim().Length == 0)

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Ensure.NotNullOrWhiteSpace uses argument.Trim().Length == 0, which allocates a new string and is less efficient than string.IsNullOrWhiteSpace(argument) (available on all supported TFMs once null is checked). Consider replacing the trim-based check to avoid unnecessary allocations in guard code.

This issue also appears on line 749 of the same file.

Suggested change
if(argument.Trim().Length==0)
if(global::System.String.IsNullOrWhiteSpace(argument))

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +86
var task = System.Threading.Tasks.Task.Run(cts.Cancel);

while (!cts.IsCancellationRequested)
{
}

return task;

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

AdapterCancellationTokenSourcePolyfill.CancelAsync contains a tight busy-wait loop (while (!cts.IsCancellationRequested) { }). This can cause avoidable CPU spikes on .NET Framework. Since you already have Task.Run(cts.Cancel), return that task (or implement a non-spinning completion mechanism) rather than spinning.

Suggested change
vartask=System.Threading.Tasks.Task.Run(cts.Cancel);
while(!cts.IsCancellationRequested)
{
}
returntask;
returnSystem.Threading.Tasks.Task.Run(cts.Cancel);

Copilot uses AI. Check for mistakes.
auto-merge was automatically disabled April 13, 2026 13:31

Pull request was closed

@Evangelink
Amaury Levé (Evangelink) deleted the remove-polyfill-dependency branch April 13, 2026 13:31
@nohwnd
Jakub Jareš (nohwnd) restored the remove-polyfill-dependency branch April 13, 2026 14:53
@nohwnd

Copy link
Copy Markdown
Member

@Youssef1313

Copy link
Copy Markdown
Member

Replacing with #7726

@Youssef1313
Youssef Fahmy (Youssef1313) deleted the remove-polyfill-dependency branch April 15, 2026 13:46
Sign up for freeto 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

4 participants

@Evangelink@nohwnd@Youssef1313
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Force GitHub README to respect dark mode\n(function() {\n var style = document.createElement('style');\n style.textContent = '\n .markdown-body {\n color-scheme: dark light;\n }\n .markdown-body pre { background: #161b22 !important; }\n .markdown-body code { background: rgba(110, 118, 129, 0.4) !important; }\n .markdown-body table th, .markdown-body table td { border-color: #30363d !important; }\n .markdown-body img { background: #0d1117; }\n .markdown-body blockquote { border-left-color: #8b949e; }\n .markdown-body hr { border-color: #30363d; }\n ';\n document.head.appendChild(style);\n})();", "GitHub Dark Mode README Fix"); } } catch(__e) { console.warn('[Userscript:GitHub Dark Mode README Fix]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Remove Polyfill NuGet package dependency - #7597

Closed
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
remove-polyfill-dependency
Closed

Remove Polyfill NuGet package dependency#7597
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
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
CopilotAI review requested due to automatic review settings March 24, 2026 10:32

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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

Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs Outdated
Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.cs Outdated
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs Outdated
CopilotAI review requested due to automatic review settings March 26, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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).
Comment threadDirectory.Build.props Outdated
Comment threadeng/Polyfills.cs Outdated
Comment threadeng/Polyfills.cs
CopilotAI review requested due to automatic review settings April 9, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Removes the external Polyfill NuGet dependency across the repo and replaces it with an in-repo shared polyfill source file (eng/Polyfills.cs) plus a few project-scoped polyfill extension files, updating call sites to avoid newer BCL APIs on older TFMs.

Changes:

  • Removed PolyfillPackageReferences (and related Poly* configuration / Using Include="Polyfills" items) from projects and central package management.
  • Added eng/Polyfills.cs and several project-scoped polyfill extension files to replace previously generated APIs and avoid IVT ambiguity.
  • Updated code paths to use older-compatible APIs (e.g., enum parsing, file operations, hashing, async XML APIs, TextWriter.FlushAsync(CancellationToken)).
Show a summary per file
FileDescription
test/Utilities/TestFramework.ForTestingMSTest/TestFramework.ForTestingMSTest.csprojRemoves Polyfill package reference from test utility project.
test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csprojRemoves Polyfill package and Using Polyfills item.
test/Utilities/Automation.CLI/Automation.CLI.csprojRemoves Polyfill package reference.
test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csprojRemoves Polyfill package reference from unit tests.
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.csReplaces string split call with older-compatible overload usage.
test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/ObjectModel/UnitTestElementTests.csReplaces generic Enum API usage with non-generic alternative.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.MockedMethodInfoWithExtraAttributes.csRemoves conditional using Polyfills;.
test/UnitTests/MSTest.SourceGeneration.UnitTests/TestUtilities/GeneratorTester.csIntroduces extern alias usage to disambiguate referenced analyzer types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/ObjectModels/InlineTestMethodArgumentsInfoTests.csIntroduces extern alias usage for SourceGeneration object model types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/MSTest.SourceGeneration.UnitTests.csprojExcludes shared polyfills and adds analyzer reference aliasing.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Helpers/ConstantsTests.csUses extern alias for SourceGeneration Constants.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Generators/TestNodesGeneratorTests.csUses extern alias for generator type references.
test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csprojRemoves Polyfill package reference from analyzer unit tests.
test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csprojRemoves Polyfill package reference and Using Polyfills item.
test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.IntegrationTests/Utilities/TestCaseFilterFactory.csRemoves using Polyfills;.
test/IntegrationTests/MSTest.IntegrationTests/MSTest.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
src/TestFramework/TestFramework/TestFramework.csprojRemoves Polyfill package reference and Using Polyfills item.
src/TestFramework/TestFramework/Internal/TestDataSourceUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/TestFramework/TestFramework/Internal/PolyfillExtensions.csAdds TestFramework-scoped polyfill extension methods.
src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform/Services/ExecutableInfo.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/TcpMessageHandler.csAdds framework-conditional flush behavior (with/without CancellationToken overload).
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/ServerModePerCallOutputDevice.csAdds framework-conditional ConcurrentBag.Clear replacement.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csprojRemoves Polyfill package reference (core platform now uses source polyfills).
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemFileSystem.csAdds TFM-conditional implementations for File.Move overwrite and async read.
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemEnvironment.csAdds fallback ProcessId implementation for older TFMs.
src/Platform/Microsoft.Testing.Platform/Helpers/Sha256Hasher.csAdds TFM-conditional SHA256 hashing + hex formatting implementations.
src/Platform/Microsoft.Testing.Platform/Helpers/KeyValuePairDeconstruct.csAdds platform-scoped KeyValuePair deconstruction polyfill.
src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.csReplaces generic Enum.Parse usage with non-generic alternative on older TFMs.
src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.csReplaces generic Enum.Parse usage with non-generic alternatives.
src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform.AI/Microsoft.Testing.Platform.AI.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.csAdds TFM-conditional async XML save handling and cancellation token storage.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCompareTool.csAdds TFM-conditional async XML load handling.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/PolyfillExtensions.csAdds TrxReport.Abstractions-scoped polyfill extension methods.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/Microsoft.Testing.Extensions.TrxReport.Abstractions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/GlobalSuppressions.csRemoves Polyfill-generated suppression entry.
src/Platform/Microsoft.Testing.Extensions.Telemetry/Microsoft.Testing.Extensions.Telemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/Microsoft.Testing.Extensions.OpenTelemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.MSBuild/Microsoft.Testing.Extensions.MSBuild.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HotReload/Microsoft.Testing.Extensions.HotReload.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HangDump/Microsoft.Testing.Extensions.HangDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureFoundry/Microsoft.Testing.Extensions.AzureFoundry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/Microsoft.Testing.Extensions.AzureDevOpsReport.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.SourceGeneration/Helpers/SystemPolyfills.csRemoves local polyfill type definitions (now provided by shared polyfills).
src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.csAdds analyzer-scoped polyfill extension methods.
src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.Analyzers.CodeFixes/MSTest.Analyzers.CodeFixes.csprojRemoves Polyfill package reference.
src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.csReplaces Environment.ProcessId usage with older-compatible implementation.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestSourceHost.csReplaces string.Join(char, ...) with compatible overload.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.csReplaces generic Enum.Parse usage with non-generic alternative.
src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.csAdds adapter-scoped polyfill extension methods (including CancelAsync polyfill).
src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.csReplaces generic Enum APIs with non-generic alternatives for older TFMs.
src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTestAdapter.PlatformServices/Extensions/MethodInfoExtensions.csReplaces Type.IsGenericMethodParameter usage with older-compatible checks.
src/Adapter/MSTestAdapter.PlatformServices/Execution/Polyfills/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTest.Engine/MSTest.Engine.csprojRemoves Polyfill package reference.
eng/Polyfills.csAdds shared polyfill types/attributes and (for core platform) some extension-method polyfills.
Directory.Packages.propsRemoves central Polyfill package version entry.
Directory.Build.propsRemoves Polyfill configuration properties and globally includes eng/Polyfills.cs for C# projects.

Copilot's findings

Comments suppressed due to low confidence (1)

eng/Polyfills.cs:763

  • The CancelAsync polyfill uses an empty busy-wait loop (while (!...IsCancellationRequested) { }), which can burn CPU on netstandard2.0/net462 for no real benefit (the returned Task.Run(cts.Cancel) already completes after cancellation is requested and callbacks run). Please remove the spin-wait and return the task directly (or use a non-spinning wait strategy).
 public static global::System.Threading.Tasks.Task CancelAsync(this global::System.Threading.CancellationTokenSource cancellationTokenSource)
{
if (cancellationTokenSource.IsCancellationRequested)
{
return global::System.Threading.Tasks.Task.CompletedTask;
}
global::System.Threading.Tasks.Task task = global::System.Threading.Tasks.Task.Run(cancellationTokenSource.Cancel);
while (!cancellationTokenSource.IsCancellationRequested)
{
}
return task;
}
  • Files reviewed: 73/73 changed files
  • Comments generated: 3

Comment threadeng/Polyfills.cs
Comment on lines +405 to +407
public static Index FromStart(int value) => value >= 0 ? new Index(value) : throw new IndexOutOfRangeException(nameof(value));

public static Index FromEnd(int value) => value >= 0 ? new Index(~value) : throw new IndexOutOfRangeException(nameof(value));

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Index.FromStart/Index.FromEnd throw IndexOutOfRangeException for negative inputs, which differs from the BCL behavior (it throws ArgumentOutOfRangeException). To keep the polyfill behavior aligned and avoid surprising exception handling differences, switch these to ArgumentOutOfRangeException (consistent with the Index(int value, ...) ctor above).

Suggested change
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewArgumentOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewArgumentOutOfRangeException(nameof(value));

Copilot uses AI. Check for mistakes.
Comment threadeng/Polyfills.cs
throw new global::System.ArgumentNullException(paramName);
}

if (argument.Trim().Length == 0)

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Ensure.NotNullOrWhiteSpace uses argument.Trim().Length == 0, which allocates a new string and is less efficient than string.IsNullOrWhiteSpace(argument) (available on all supported TFMs once null is checked). Consider replacing the trim-based check to avoid unnecessary allocations in guard code.

This issue also appears on line 749 of the same file.

Suggested change
if(argument.Trim().Length==0)
if(global::System.String.IsNullOrWhiteSpace(argument))

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +86
var task = System.Threading.Tasks.Task.Run(cts.Cancel);

while (!cts.IsCancellationRequested)
{
}

return task;

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

AdapterCancellationTokenSourcePolyfill.CancelAsync contains a tight busy-wait loop (while (!cts.IsCancellationRequested) { }). This can cause avoidable CPU spikes on .NET Framework. Since you already have Task.Run(cts.Cancel), return that task (or implement a non-spinning completion mechanism) rather than spinning.

Suggested change
vartask=System.Threading.Tasks.Task.Run(cts.Cancel);
while(!cts.IsCancellationRequested)
{
}
returntask;
returnSystem.Threading.Tasks.Task.Run(cts.Cancel);

Copilot uses AI. Check for mistakes.
auto-merge was automatically disabled April 13, 2026 13:31

Pull request was closed

@Evangelink
Amaury Levé (Evangelink) deleted the remove-polyfill-dependency branch April 13, 2026 13:31
@nohwnd
Jakub Jareš (nohwnd) restored the remove-polyfill-dependency branch April 13, 2026 14:53
@nohwnd

Copy link
Copy Markdown
Member

@Youssef1313

Copy link
Copy Markdown
Member

Replacing with #7726

@Youssef1313
Youssef Fahmy (Youssef1313) deleted the remove-polyfill-dependency branch April 15, 2026 13:46
Sign up for freeto 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

4 participants

@Evangelink@nohwnd@Youssef1313
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Highlight search terms from Google/DuckDuckGo/Bing referrer\n(function() {\n var ref = document.referrer;\n var terms = [];\n \n if (ref.includes('google.com') || ref.includes('duckduckgo.com') || ref.includes('bing.com')) {\n var url = new URL(ref);\n var q = url.searchParams.get('q') || url.searchParams.get('p');\n if (q) {\n terms = q.split(/\\s+/).filter(function(t) { return t.length > 2; });\n }\n }\n \n if (terms.length === 0) return;\n \n var style = document.createElement('style');\n style.textContent = '.userscript-highlight { background: #fbbf24; color: #1a1a2e; padding: 1px 3px; border-radius: 2px; }';\n document.head.appendChild(style);\n \n function highlight(node) {\n if (node.nodeType === 3) { // text node\n var text = node.textContent;\n var found = false;\n terms.forEach(function(term) {\n var regex = new RegExp('(' + term.replace(/[.*+?^${}()|[\\]\\\\]/g, '\\\\') + ')', 'gi');\n if (regex.test(text)) {\n found = true;\n var frag = document.createDocumentFragment();\n var parts = text.split(regex);\n parts.forEach(function(part, i) {\n if (i % 2 === 0) {\n frag.appendChild(document.createTextNode(part));\n } else {\n var span = document.createElement('span');\n span.className = 'userscript-highlight';\n span.textContent = part;\n frag.appendChild(span);\n }\n });\n node.parentNode.replaceChild(frag, node);\n }\n });\n } else if (node.nodeType === 1 && node.childNodes) { // element\n var skipTags = ['SCRIPT', 'STYLE', 'NOSCRIPT', 'TEXTAREA', 'INPUT', 'SELECT'];\n if (!skipTags.includes(node.tagName)) {\n Array.from(node.childNodes).forEach(highlight);\n }\n }\n }\n \n highlight(document.body);\n \n // Re-highlight on dynamic content\n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1 || node.nodeType === 3) highlight(node);\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Highlight Search Terms"); } } catch(__e) { console.warn('[Userscript:Highlight Search Terms]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Remove Polyfill NuGet package dependency - #7597

Closed
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
remove-polyfill-dependency
Closed

Remove Polyfill NuGet package dependency#7597
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
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
CopilotAI review requested due to automatic review settings March 24, 2026 10:32

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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

Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs Outdated
Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.cs Outdated
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs Outdated
CopilotAI review requested due to automatic review settings March 26, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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).
Comment threadDirectory.Build.props Outdated
Comment threadeng/Polyfills.cs Outdated
Comment threadeng/Polyfills.cs
CopilotAI review requested due to automatic review settings April 9, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Removes the external Polyfill NuGet dependency across the repo and replaces it with an in-repo shared polyfill source file (eng/Polyfills.cs) plus a few project-scoped polyfill extension files, updating call sites to avoid newer BCL APIs on older TFMs.

Changes:

  • Removed PolyfillPackageReferences (and related Poly* configuration / Using Include="Polyfills" items) from projects and central package management.
  • Added eng/Polyfills.cs and several project-scoped polyfill extension files to replace previously generated APIs and avoid IVT ambiguity.
  • Updated code paths to use older-compatible APIs (e.g., enum parsing, file operations, hashing, async XML APIs, TextWriter.FlushAsync(CancellationToken)).
Show a summary per file
FileDescription
test/Utilities/TestFramework.ForTestingMSTest/TestFramework.ForTestingMSTest.csprojRemoves Polyfill package reference from test utility project.
test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csprojRemoves Polyfill package and Using Polyfills item.
test/Utilities/Automation.CLI/Automation.CLI.csprojRemoves Polyfill package reference.
test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csprojRemoves Polyfill package reference from unit tests.
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.csReplaces string split call with older-compatible overload usage.
test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/ObjectModel/UnitTestElementTests.csReplaces generic Enum API usage with non-generic alternative.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.MockedMethodInfoWithExtraAttributes.csRemoves conditional using Polyfills;.
test/UnitTests/MSTest.SourceGeneration.UnitTests/TestUtilities/GeneratorTester.csIntroduces extern alias usage to disambiguate referenced analyzer types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/ObjectModels/InlineTestMethodArgumentsInfoTests.csIntroduces extern alias usage for SourceGeneration object model types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/MSTest.SourceGeneration.UnitTests.csprojExcludes shared polyfills and adds analyzer reference aliasing.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Helpers/ConstantsTests.csUses extern alias for SourceGeneration Constants.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Generators/TestNodesGeneratorTests.csUses extern alias for generator type references.
test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csprojRemoves Polyfill package reference from analyzer unit tests.
test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csprojRemoves Polyfill package reference and Using Polyfills item.
test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.IntegrationTests/Utilities/TestCaseFilterFactory.csRemoves using Polyfills;.
test/IntegrationTests/MSTest.IntegrationTests/MSTest.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
src/TestFramework/TestFramework/TestFramework.csprojRemoves Polyfill package reference and Using Polyfills item.
src/TestFramework/TestFramework/Internal/TestDataSourceUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/TestFramework/TestFramework/Internal/PolyfillExtensions.csAdds TestFramework-scoped polyfill extension methods.
src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform/Services/ExecutableInfo.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/TcpMessageHandler.csAdds framework-conditional flush behavior (with/without CancellationToken overload).
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/ServerModePerCallOutputDevice.csAdds framework-conditional ConcurrentBag.Clear replacement.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csprojRemoves Polyfill package reference (core platform now uses source polyfills).
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemFileSystem.csAdds TFM-conditional implementations for File.Move overwrite and async read.
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemEnvironment.csAdds fallback ProcessId implementation for older TFMs.
src/Platform/Microsoft.Testing.Platform/Helpers/Sha256Hasher.csAdds TFM-conditional SHA256 hashing + hex formatting implementations.
src/Platform/Microsoft.Testing.Platform/Helpers/KeyValuePairDeconstruct.csAdds platform-scoped KeyValuePair deconstruction polyfill.
src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.csReplaces generic Enum.Parse usage with non-generic alternative on older TFMs.
src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.csReplaces generic Enum.Parse usage with non-generic alternatives.
src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform.AI/Microsoft.Testing.Platform.AI.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.csAdds TFM-conditional async XML save handling and cancellation token storage.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCompareTool.csAdds TFM-conditional async XML load handling.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/PolyfillExtensions.csAdds TrxReport.Abstractions-scoped polyfill extension methods.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/Microsoft.Testing.Extensions.TrxReport.Abstractions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/GlobalSuppressions.csRemoves Polyfill-generated suppression entry.
src/Platform/Microsoft.Testing.Extensions.Telemetry/Microsoft.Testing.Extensions.Telemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/Microsoft.Testing.Extensions.OpenTelemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.MSBuild/Microsoft.Testing.Extensions.MSBuild.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HotReload/Microsoft.Testing.Extensions.HotReload.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HangDump/Microsoft.Testing.Extensions.HangDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureFoundry/Microsoft.Testing.Extensions.AzureFoundry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/Microsoft.Testing.Extensions.AzureDevOpsReport.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.SourceGeneration/Helpers/SystemPolyfills.csRemoves local polyfill type definitions (now provided by shared polyfills).
src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.csAdds analyzer-scoped polyfill extension methods.
src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.Analyzers.CodeFixes/MSTest.Analyzers.CodeFixes.csprojRemoves Polyfill package reference.
src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.csReplaces Environment.ProcessId usage with older-compatible implementation.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestSourceHost.csReplaces string.Join(char, ...) with compatible overload.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.csReplaces generic Enum.Parse usage with non-generic alternative.
src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.csAdds adapter-scoped polyfill extension methods (including CancelAsync polyfill).
src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.csReplaces generic Enum APIs with non-generic alternatives for older TFMs.
src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTestAdapter.PlatformServices/Extensions/MethodInfoExtensions.csReplaces Type.IsGenericMethodParameter usage with older-compatible checks.
src/Adapter/MSTestAdapter.PlatformServices/Execution/Polyfills/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTest.Engine/MSTest.Engine.csprojRemoves Polyfill package reference.
eng/Polyfills.csAdds shared polyfill types/attributes and (for core platform) some extension-method polyfills.
Directory.Packages.propsRemoves central Polyfill package version entry.
Directory.Build.propsRemoves Polyfill configuration properties and globally includes eng/Polyfills.cs for C# projects.

Copilot's findings

Comments suppressed due to low confidence (1)

eng/Polyfills.cs:763

  • The CancelAsync polyfill uses an empty busy-wait loop (while (!...IsCancellationRequested) { }), which can burn CPU on netstandard2.0/net462 for no real benefit (the returned Task.Run(cts.Cancel) already completes after cancellation is requested and callbacks run). Please remove the spin-wait and return the task directly (or use a non-spinning wait strategy).
 public static global::System.Threading.Tasks.Task CancelAsync(this global::System.Threading.CancellationTokenSource cancellationTokenSource)
{
if (cancellationTokenSource.IsCancellationRequested)
{
return global::System.Threading.Tasks.Task.CompletedTask;
}
global::System.Threading.Tasks.Task task = global::System.Threading.Tasks.Task.Run(cancellationTokenSource.Cancel);
while (!cancellationTokenSource.IsCancellationRequested)
{
}
return task;
}
  • Files reviewed: 73/73 changed files
  • Comments generated: 3

Comment threadeng/Polyfills.cs
Comment on lines +405 to +407
public static Index FromStart(int value) => value >= 0 ? new Index(value) : throw new IndexOutOfRangeException(nameof(value));

public static Index FromEnd(int value) => value >= 0 ? new Index(~value) : throw new IndexOutOfRangeException(nameof(value));

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Index.FromStart/Index.FromEnd throw IndexOutOfRangeException for negative inputs, which differs from the BCL behavior (it throws ArgumentOutOfRangeException). To keep the polyfill behavior aligned and avoid surprising exception handling differences, switch these to ArgumentOutOfRangeException (consistent with the Index(int value, ...) ctor above).

Suggested change
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewArgumentOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewArgumentOutOfRangeException(nameof(value));

Copilot uses AI. Check for mistakes.
Comment threadeng/Polyfills.cs
throw new global::System.ArgumentNullException(paramName);
}

if (argument.Trim().Length == 0)

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Ensure.NotNullOrWhiteSpace uses argument.Trim().Length == 0, which allocates a new string and is less efficient than string.IsNullOrWhiteSpace(argument) (available on all supported TFMs once null is checked). Consider replacing the trim-based check to avoid unnecessary allocations in guard code.

This issue also appears on line 749 of the same file.

Suggested change
if(argument.Trim().Length==0)
if(global::System.String.IsNullOrWhiteSpace(argument))

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +86
var task = System.Threading.Tasks.Task.Run(cts.Cancel);

while (!cts.IsCancellationRequested)
{
}

return task;

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

AdapterCancellationTokenSourcePolyfill.CancelAsync contains a tight busy-wait loop (while (!cts.IsCancellationRequested) { }). This can cause avoidable CPU spikes on .NET Framework. Since you already have Task.Run(cts.Cancel), return that task (or implement a non-spinning completion mechanism) rather than spinning.

Suggested change
vartask=System.Threading.Tasks.Task.Run(cts.Cancel);
while(!cts.IsCancellationRequested)
{
}
returntask;
returnSystem.Threading.Tasks.Task.Run(cts.Cancel);

Copilot uses AI. Check for mistakes.
auto-merge was automatically disabled April 13, 2026 13:31

Pull request was closed

@Evangelink
Amaury Levé (Evangelink) deleted the remove-polyfill-dependency branch April 13, 2026 13:31
@nohwnd
Jakub Jareš (nohwnd) restored the remove-polyfill-dependency branch April 13, 2026 14:53
@nohwnd

Copy link
Copy Markdown
Member

@Youssef1313

Copy link
Copy Markdown
Member

Replacing with #7726

@Youssef1313
Youssef Fahmy (Youssef1313) deleted the remove-polyfill-dependency branch April 15, 2026 13:46
Sign up for freeto 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

4 participants

@Evangelink@nohwnd@Youssef1313
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Strip utm_, fbclid, gclid, etc. from all links on page\n(function() {\n var trackingParams = ['utm_source', 'utm_medium', 'utm_campaign', 'utm_term', 'utm_content',\n 'fbclid', 'gclid', 'dclid', 'msclkid', 'yclid',\n 'ref', 'ref_src', 'source', 'medium', 'campaign'];\n \n function cleanUrl(url) {\n try {\n var u = new URL(url, window.location.origin);\n var changed = false;\n trackingParams.forEach(function(p) {\n if (u.searchParams.has(p)) {\n u.searchParams.delete(p);\n changed = true;\n }\n });\n return changed ? u.toString() : url;\n } catch (e) {\n return url;\n }\n }\n \n function cleanLinks() {\n document.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n \n cleanLinks();\n \n var observer = new MutationObserver(function(mutations) {\n mutations.forEach(function(m) {\n m.addedNodes.forEach(function(node) {\n if (node.nodeType === 1) {\n if (node.tagName === 'A') cleanLinks();\n node.querySelectorAll('a[href]').forEach(function(a) {\n var clean = cleanUrl(a.href);\n if (clean !== a.href) a.href = clean;\n });\n }\n });\n });\n });\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "Remove Tracking Parameters from Links"); } } catch(__e) { console.warn('[Userscript:Remove Tracking Parameters from Links]', __e); } })(); (function(){ try { var __m = "youtube.com"; var __re = new RegExp('^' + "youtube\\.com" + '
Skip to content

Remove Polyfill NuGet package dependency - #7597

Closed
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
remove-polyfill-dependency
Closed

Remove Polyfill NuGet package dependency#7597
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
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
CopilotAI review requested due to automatic review settings March 24, 2026 10:32

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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

Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs Outdated
Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.cs Outdated
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs Outdated
CopilotAI review requested due to automatic review settings March 26, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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).
Comment threadDirectory.Build.props Outdated
Comment threadeng/Polyfills.cs Outdated
Comment threadeng/Polyfills.cs
CopilotAI review requested due to automatic review settings April 9, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Removes the external Polyfill NuGet dependency across the repo and replaces it with an in-repo shared polyfill source file (eng/Polyfills.cs) plus a few project-scoped polyfill extension files, updating call sites to avoid newer BCL APIs on older TFMs.

Changes:

  • Removed PolyfillPackageReferences (and related Poly* configuration / Using Include="Polyfills" items) from projects and central package management.
  • Added eng/Polyfills.cs and several project-scoped polyfill extension files to replace previously generated APIs and avoid IVT ambiguity.
  • Updated code paths to use older-compatible APIs (e.g., enum parsing, file operations, hashing, async XML APIs, TextWriter.FlushAsync(CancellationToken)).
Show a summary per file
FileDescription
test/Utilities/TestFramework.ForTestingMSTest/TestFramework.ForTestingMSTest.csprojRemoves Polyfill package reference from test utility project.
test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csprojRemoves Polyfill package and Using Polyfills item.
test/Utilities/Automation.CLI/Automation.CLI.csprojRemoves Polyfill package reference.
test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csprojRemoves Polyfill package reference from unit tests.
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.csReplaces string split call with older-compatible overload usage.
test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/ObjectModel/UnitTestElementTests.csReplaces generic Enum API usage with non-generic alternative.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.MockedMethodInfoWithExtraAttributes.csRemoves conditional using Polyfills;.
test/UnitTests/MSTest.SourceGeneration.UnitTests/TestUtilities/GeneratorTester.csIntroduces extern alias usage to disambiguate referenced analyzer types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/ObjectModels/InlineTestMethodArgumentsInfoTests.csIntroduces extern alias usage for SourceGeneration object model types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/MSTest.SourceGeneration.UnitTests.csprojExcludes shared polyfills and adds analyzer reference aliasing.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Helpers/ConstantsTests.csUses extern alias for SourceGeneration Constants.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Generators/TestNodesGeneratorTests.csUses extern alias for generator type references.
test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csprojRemoves Polyfill package reference from analyzer unit tests.
test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csprojRemoves Polyfill package reference and Using Polyfills item.
test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.IntegrationTests/Utilities/TestCaseFilterFactory.csRemoves using Polyfills;.
test/IntegrationTests/MSTest.IntegrationTests/MSTest.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
src/TestFramework/TestFramework/TestFramework.csprojRemoves Polyfill package reference and Using Polyfills item.
src/TestFramework/TestFramework/Internal/TestDataSourceUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/TestFramework/TestFramework/Internal/PolyfillExtensions.csAdds TestFramework-scoped polyfill extension methods.
src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform/Services/ExecutableInfo.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/TcpMessageHandler.csAdds framework-conditional flush behavior (with/without CancellationToken overload).
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/ServerModePerCallOutputDevice.csAdds framework-conditional ConcurrentBag.Clear replacement.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csprojRemoves Polyfill package reference (core platform now uses source polyfills).
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemFileSystem.csAdds TFM-conditional implementations for File.Move overwrite and async read.
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemEnvironment.csAdds fallback ProcessId implementation for older TFMs.
src/Platform/Microsoft.Testing.Platform/Helpers/Sha256Hasher.csAdds TFM-conditional SHA256 hashing + hex formatting implementations.
src/Platform/Microsoft.Testing.Platform/Helpers/KeyValuePairDeconstruct.csAdds platform-scoped KeyValuePair deconstruction polyfill.
src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.csReplaces generic Enum.Parse usage with non-generic alternative on older TFMs.
src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.csReplaces generic Enum.Parse usage with non-generic alternatives.
src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform.AI/Microsoft.Testing.Platform.AI.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.csAdds TFM-conditional async XML save handling and cancellation token storage.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCompareTool.csAdds TFM-conditional async XML load handling.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/PolyfillExtensions.csAdds TrxReport.Abstractions-scoped polyfill extension methods.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/Microsoft.Testing.Extensions.TrxReport.Abstractions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/GlobalSuppressions.csRemoves Polyfill-generated suppression entry.
src/Platform/Microsoft.Testing.Extensions.Telemetry/Microsoft.Testing.Extensions.Telemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/Microsoft.Testing.Extensions.OpenTelemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.MSBuild/Microsoft.Testing.Extensions.MSBuild.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HotReload/Microsoft.Testing.Extensions.HotReload.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HangDump/Microsoft.Testing.Extensions.HangDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureFoundry/Microsoft.Testing.Extensions.AzureFoundry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/Microsoft.Testing.Extensions.AzureDevOpsReport.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.SourceGeneration/Helpers/SystemPolyfills.csRemoves local polyfill type definitions (now provided by shared polyfills).
src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.csAdds analyzer-scoped polyfill extension methods.
src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.Analyzers.CodeFixes/MSTest.Analyzers.CodeFixes.csprojRemoves Polyfill package reference.
src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.csReplaces Environment.ProcessId usage with older-compatible implementation.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestSourceHost.csReplaces string.Join(char, ...) with compatible overload.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.csReplaces generic Enum.Parse usage with non-generic alternative.
src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.csAdds adapter-scoped polyfill extension methods (including CancelAsync polyfill).
src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.csReplaces generic Enum APIs with non-generic alternatives for older TFMs.
src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTestAdapter.PlatformServices/Extensions/MethodInfoExtensions.csReplaces Type.IsGenericMethodParameter usage with older-compatible checks.
src/Adapter/MSTestAdapter.PlatformServices/Execution/Polyfills/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTest.Engine/MSTest.Engine.csprojRemoves Polyfill package reference.
eng/Polyfills.csAdds shared polyfill types/attributes and (for core platform) some extension-method polyfills.
Directory.Packages.propsRemoves central Polyfill package version entry.
Directory.Build.propsRemoves Polyfill configuration properties and globally includes eng/Polyfills.cs for C# projects.

Copilot's findings

Comments suppressed due to low confidence (1)

eng/Polyfills.cs:763

  • The CancelAsync polyfill uses an empty busy-wait loop (while (!...IsCancellationRequested) { }), which can burn CPU on netstandard2.0/net462 for no real benefit (the returned Task.Run(cts.Cancel) already completes after cancellation is requested and callbacks run). Please remove the spin-wait and return the task directly (or use a non-spinning wait strategy).
 public static global::System.Threading.Tasks.Task CancelAsync(this global::System.Threading.CancellationTokenSource cancellationTokenSource)
{
if (cancellationTokenSource.IsCancellationRequested)
{
return global::System.Threading.Tasks.Task.CompletedTask;
}
global::System.Threading.Tasks.Task task = global::System.Threading.Tasks.Task.Run(cancellationTokenSource.Cancel);
while (!cancellationTokenSource.IsCancellationRequested)
{
}
return task;
}
  • Files reviewed: 73/73 changed files
  • Comments generated: 3

Comment threadeng/Polyfills.cs
Comment on lines +405 to +407
public static Index FromStart(int value) => value >= 0 ? new Index(value) : throw new IndexOutOfRangeException(nameof(value));

public static Index FromEnd(int value) => value >= 0 ? new Index(~value) : throw new IndexOutOfRangeException(nameof(value));

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Index.FromStart/Index.FromEnd throw IndexOutOfRangeException for negative inputs, which differs from the BCL behavior (it throws ArgumentOutOfRangeException). To keep the polyfill behavior aligned and avoid surprising exception handling differences, switch these to ArgumentOutOfRangeException (consistent with the Index(int value, ...) ctor above).

Suggested change
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewArgumentOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewArgumentOutOfRangeException(nameof(value));

Copilot uses AI. Check for mistakes.
Comment threadeng/Polyfills.cs
throw new global::System.ArgumentNullException(paramName);
}

if (argument.Trim().Length == 0)

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Ensure.NotNullOrWhiteSpace uses argument.Trim().Length == 0, which allocates a new string and is less efficient than string.IsNullOrWhiteSpace(argument) (available on all supported TFMs once null is checked). Consider replacing the trim-based check to avoid unnecessary allocations in guard code.

This issue also appears on line 749 of the same file.

Suggested change
if(argument.Trim().Length==0)
if(global::System.String.IsNullOrWhiteSpace(argument))

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +86
var task = System.Threading.Tasks.Task.Run(cts.Cancel);

while (!cts.IsCancellationRequested)
{
}

return task;

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

AdapterCancellationTokenSourcePolyfill.CancelAsync contains a tight busy-wait loop (while (!cts.IsCancellationRequested) { }). This can cause avoidable CPU spikes on .NET Framework. Since you already have Task.Run(cts.Cancel), return that task (or implement a non-spinning completion mechanism) rather than spinning.

Suggested change
vartask=System.Threading.Tasks.Task.Run(cts.Cancel);
while(!cts.IsCancellationRequested)
{
}
returntask;
returnSystem.Threading.Tasks.Task.Run(cts.Cancel);

Copilot uses AI. Check for mistakes.
auto-merge was automatically disabled April 13, 2026 13:31

Pull request was closed

@Evangelink
Amaury Levé (Evangelink) deleted the remove-polyfill-dependency branch April 13, 2026 13:31
@nohwnd
Jakub Jareš (nohwnd) restored the remove-polyfill-dependency branch April 13, 2026 14:53
@nohwnd

Copy link
Copy Markdown
Member

@Youssef1313

Copy link
Copy Markdown
Member

Replacing with #7726

@Youssef1313
Youssef Fahmy (Youssef1313) deleted the remove-polyfill-dependency branch April 15, 2026 13:46
Sign up for freeto 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

4 participants

@Evangelink@nohwnd@Youssef1313
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Auto-enable theater mode on YouTube\n(function() {\n function tryTheater() {\n var btn = document.querySelector('button[aria-label=\"Theater mode\"], ytd-player #player button[title=\"Theater mode\"]');\n if (btn && !btn.classList.contains('activated')) {\n btn.click();\n }\n }\n \n // Try immediately\n tryTheater();\n \n // Try after navigation (SPA)\n var lastUrl = location.href;\n setInterval(function() {\n if (location.href !== lastUrl) {\n lastUrl = location.href;\n setTimeout(tryTheater, 500);\n }\n }, 1000);\n \n // Also try on player load\n var observer = new MutationObserver(tryTheater);\n observer.observe(document.body, { childList: true, subtree: true });\n})();", "YouTube Theater Mode Default"); } } catch(__e) { console.warn('[Userscript:YouTube Theater Mode Default]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Remove Polyfill NuGet package dependency - #7597

Closed
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
remove-polyfill-dependency
Closed

Remove Polyfill NuGet package dependency#7597
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
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
CopilotAI review requested due to automatic review settings March 24, 2026 10:32

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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

Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs Outdated
Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.cs Outdated
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs Outdated
CopilotAI review requested due to automatic review settings March 26, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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).
Comment threadDirectory.Build.props Outdated
Comment threadeng/Polyfills.cs Outdated
Comment threadeng/Polyfills.cs
CopilotAI review requested due to automatic review settings April 9, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Removes the external Polyfill NuGet dependency across the repo and replaces it with an in-repo shared polyfill source file (eng/Polyfills.cs) plus a few project-scoped polyfill extension files, updating call sites to avoid newer BCL APIs on older TFMs.

Changes:

  • Removed PolyfillPackageReferences (and related Poly* configuration / Using Include="Polyfills" items) from projects and central package management.
  • Added eng/Polyfills.cs and several project-scoped polyfill extension files to replace previously generated APIs and avoid IVT ambiguity.
  • Updated code paths to use older-compatible APIs (e.g., enum parsing, file operations, hashing, async XML APIs, TextWriter.FlushAsync(CancellationToken)).
Show a summary per file
FileDescription
test/Utilities/TestFramework.ForTestingMSTest/TestFramework.ForTestingMSTest.csprojRemoves Polyfill package reference from test utility project.
test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csprojRemoves Polyfill package and Using Polyfills item.
test/Utilities/Automation.CLI/Automation.CLI.csprojRemoves Polyfill package reference.
test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csprojRemoves Polyfill package reference from unit tests.
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.csReplaces string split call with older-compatible overload usage.
test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/ObjectModel/UnitTestElementTests.csReplaces generic Enum API usage with non-generic alternative.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.MockedMethodInfoWithExtraAttributes.csRemoves conditional using Polyfills;.
test/UnitTests/MSTest.SourceGeneration.UnitTests/TestUtilities/GeneratorTester.csIntroduces extern alias usage to disambiguate referenced analyzer types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/ObjectModels/InlineTestMethodArgumentsInfoTests.csIntroduces extern alias usage for SourceGeneration object model types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/MSTest.SourceGeneration.UnitTests.csprojExcludes shared polyfills and adds analyzer reference aliasing.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Helpers/ConstantsTests.csUses extern alias for SourceGeneration Constants.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Generators/TestNodesGeneratorTests.csUses extern alias for generator type references.
test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csprojRemoves Polyfill package reference from analyzer unit tests.
test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csprojRemoves Polyfill package reference and Using Polyfills item.
test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.IntegrationTests/Utilities/TestCaseFilterFactory.csRemoves using Polyfills;.
test/IntegrationTests/MSTest.IntegrationTests/MSTest.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
src/TestFramework/TestFramework/TestFramework.csprojRemoves Polyfill package reference and Using Polyfills item.
src/TestFramework/TestFramework/Internal/TestDataSourceUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/TestFramework/TestFramework/Internal/PolyfillExtensions.csAdds TestFramework-scoped polyfill extension methods.
src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform/Services/ExecutableInfo.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/TcpMessageHandler.csAdds framework-conditional flush behavior (with/without CancellationToken overload).
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/ServerModePerCallOutputDevice.csAdds framework-conditional ConcurrentBag.Clear replacement.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csprojRemoves Polyfill package reference (core platform now uses source polyfills).
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemFileSystem.csAdds TFM-conditional implementations for File.Move overwrite and async read.
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemEnvironment.csAdds fallback ProcessId implementation for older TFMs.
src/Platform/Microsoft.Testing.Platform/Helpers/Sha256Hasher.csAdds TFM-conditional SHA256 hashing + hex formatting implementations.
src/Platform/Microsoft.Testing.Platform/Helpers/KeyValuePairDeconstruct.csAdds platform-scoped KeyValuePair deconstruction polyfill.
src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.csReplaces generic Enum.Parse usage with non-generic alternative on older TFMs.
src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.csReplaces generic Enum.Parse usage with non-generic alternatives.
src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform.AI/Microsoft.Testing.Platform.AI.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.csAdds TFM-conditional async XML save handling and cancellation token storage.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCompareTool.csAdds TFM-conditional async XML load handling.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/PolyfillExtensions.csAdds TrxReport.Abstractions-scoped polyfill extension methods.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/Microsoft.Testing.Extensions.TrxReport.Abstractions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/GlobalSuppressions.csRemoves Polyfill-generated suppression entry.
src/Platform/Microsoft.Testing.Extensions.Telemetry/Microsoft.Testing.Extensions.Telemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/Microsoft.Testing.Extensions.OpenTelemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.MSBuild/Microsoft.Testing.Extensions.MSBuild.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HotReload/Microsoft.Testing.Extensions.HotReload.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HangDump/Microsoft.Testing.Extensions.HangDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureFoundry/Microsoft.Testing.Extensions.AzureFoundry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/Microsoft.Testing.Extensions.AzureDevOpsReport.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.SourceGeneration/Helpers/SystemPolyfills.csRemoves local polyfill type definitions (now provided by shared polyfills).
src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.csAdds analyzer-scoped polyfill extension methods.
src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.Analyzers.CodeFixes/MSTest.Analyzers.CodeFixes.csprojRemoves Polyfill package reference.
src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.csReplaces Environment.ProcessId usage with older-compatible implementation.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestSourceHost.csReplaces string.Join(char, ...) with compatible overload.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.csReplaces generic Enum.Parse usage with non-generic alternative.
src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.csAdds adapter-scoped polyfill extension methods (including CancelAsync polyfill).
src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.csReplaces generic Enum APIs with non-generic alternatives for older TFMs.
src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTestAdapter.PlatformServices/Extensions/MethodInfoExtensions.csReplaces Type.IsGenericMethodParameter usage with older-compatible checks.
src/Adapter/MSTestAdapter.PlatformServices/Execution/Polyfills/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTest.Engine/MSTest.Engine.csprojRemoves Polyfill package reference.
eng/Polyfills.csAdds shared polyfill types/attributes and (for core platform) some extension-method polyfills.
Directory.Packages.propsRemoves central Polyfill package version entry.
Directory.Build.propsRemoves Polyfill configuration properties and globally includes eng/Polyfills.cs for C# projects.

Copilot's findings

Comments suppressed due to low confidence (1)

eng/Polyfills.cs:763

  • The CancelAsync polyfill uses an empty busy-wait loop (while (!...IsCancellationRequested) { }), which can burn CPU on netstandard2.0/net462 for no real benefit (the returned Task.Run(cts.Cancel) already completes after cancellation is requested and callbacks run). Please remove the spin-wait and return the task directly (or use a non-spinning wait strategy).
 public static global::System.Threading.Tasks.Task CancelAsync(this global::System.Threading.CancellationTokenSource cancellationTokenSource)
{
if (cancellationTokenSource.IsCancellationRequested)
{
return global::System.Threading.Tasks.Task.CompletedTask;
}
global::System.Threading.Tasks.Task task = global::System.Threading.Tasks.Task.Run(cancellationTokenSource.Cancel);
while (!cancellationTokenSource.IsCancellationRequested)
{
}
return task;
}
  • Files reviewed: 73/73 changed files
  • Comments generated: 3

Comment threadeng/Polyfills.cs
Comment on lines +405 to +407
public static Index FromStart(int value) => value >= 0 ? new Index(value) : throw new IndexOutOfRangeException(nameof(value));

public static Index FromEnd(int value) => value >= 0 ? new Index(~value) : throw new IndexOutOfRangeException(nameof(value));

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Index.FromStart/Index.FromEnd throw IndexOutOfRangeException for negative inputs, which differs from the BCL behavior (it throws ArgumentOutOfRangeException). To keep the polyfill behavior aligned and avoid surprising exception handling differences, switch these to ArgumentOutOfRangeException (consistent with the Index(int value, ...) ctor above).

Suggested change
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewArgumentOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewArgumentOutOfRangeException(nameof(value));

Copilot uses AI. Check for mistakes.
Comment threadeng/Polyfills.cs
throw new global::System.ArgumentNullException(paramName);
}

if (argument.Trim().Length == 0)

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Ensure.NotNullOrWhiteSpace uses argument.Trim().Length == 0, which allocates a new string and is less efficient than string.IsNullOrWhiteSpace(argument) (available on all supported TFMs once null is checked). Consider replacing the trim-based check to avoid unnecessary allocations in guard code.

This issue also appears on line 749 of the same file.

Suggested change
if(argument.Trim().Length==0)
if(global::System.String.IsNullOrWhiteSpace(argument))

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +86
var task = System.Threading.Tasks.Task.Run(cts.Cancel);

while (!cts.IsCancellationRequested)
{
}

return task;

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

AdapterCancellationTokenSourcePolyfill.CancelAsync contains a tight busy-wait loop (while (!cts.IsCancellationRequested) { }). This can cause avoidable CPU spikes on .NET Framework. Since you already have Task.Run(cts.Cancel), return that task (or implement a non-spinning completion mechanism) rather than spinning.

Suggested change
vartask=System.Threading.Tasks.Task.Run(cts.Cancel);
while(!cts.IsCancellationRequested)
{
}
returntask;
returnSystem.Threading.Tasks.Task.Run(cts.Cancel);

Copilot uses AI. Check for mistakes.
auto-merge was automatically disabled April 13, 2026 13:31

Pull request was closed

@Evangelink
Amaury Levé (Evangelink) deleted the remove-polyfill-dependency branch April 13, 2026 13:31
@nohwnd
Jakub Jareš (nohwnd) restored the remove-polyfill-dependency branch April 13, 2026 14:53
@nohwnd

Copy link
Copy Markdown
Member

@Youssef1313

Copy link
Copy Markdown
Member

Replacing with #7726

@Youssef1313
Youssef Fahmy (Youssef1313) deleted the remove-polyfill-dependency branch April 15, 2026 13:46
Sign up for freeto 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

4 participants

@Evangelink@nohwnd@Youssef1313
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Remove or un-stick sticky/fixed headers that block content\n(function() {\n function unstick() {\n document.querySelectorAll('header, nav, [role=\"banner\"], .header, .navbar, .sticky, .fixed-top, [style*=\"position: fixed\"], [style*=\"position:sticky\"]').forEach(function(el) {\n if (el.style.position === 'fixed' || el.style.position === 'sticky' || \n getComputedStyle(el).position === 'fixed' || getComputedStyle(el).position === 'sticky') {\n el.style.position = 'static';\n el.style.top = 'auto';\n el.style.zIndex = 'auto';\n }\n });\n }\n \n unstick();\n \n var observer = new MutationObserver(unstick);\n observer.observe(document.body, { childList: true, subtree: true, attributes: true, attributeFilter: ['style', 'class'] });\n})();", "Kill Sticky Headers"); } } catch(__e) { console.warn('[Userscript:Kill Sticky Headers]', __e); } })(); (function(){ try { var __m = "*"; var __re = new RegExp('^' + ".*" + '
Skip to content

Remove Polyfill NuGet package dependency - #7597

Closed
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
remove-polyfill-dependency
Closed

Remove Polyfill NuGet package dependency#7597
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
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
CopilotAI review requested due to automatic review settings March 24, 2026 10:32

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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

Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs Outdated
Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.cs Outdated
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs Outdated
CopilotAI review requested due to automatic review settings March 26, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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).
Comment threadDirectory.Build.props Outdated
Comment threadeng/Polyfills.cs Outdated
Comment threadeng/Polyfills.cs
CopilotAI review requested due to automatic review settings April 9, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Removes the external Polyfill NuGet dependency across the repo and replaces it with an in-repo shared polyfill source file (eng/Polyfills.cs) plus a few project-scoped polyfill extension files, updating call sites to avoid newer BCL APIs on older TFMs.

Changes:

  • Removed PolyfillPackageReferences (and related Poly* configuration / Using Include="Polyfills" items) from projects and central package management.
  • Added eng/Polyfills.cs and several project-scoped polyfill extension files to replace previously generated APIs and avoid IVT ambiguity.
  • Updated code paths to use older-compatible APIs (e.g., enum parsing, file operations, hashing, async XML APIs, TextWriter.FlushAsync(CancellationToken)).
Show a summary per file
FileDescription
test/Utilities/TestFramework.ForTestingMSTest/TestFramework.ForTestingMSTest.csprojRemoves Polyfill package reference from test utility project.
test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csprojRemoves Polyfill package and Using Polyfills item.
test/Utilities/Automation.CLI/Automation.CLI.csprojRemoves Polyfill package reference.
test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csprojRemoves Polyfill package reference from unit tests.
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.csReplaces string split call with older-compatible overload usage.
test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/ObjectModel/UnitTestElementTests.csReplaces generic Enum API usage with non-generic alternative.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.MockedMethodInfoWithExtraAttributes.csRemoves conditional using Polyfills;.
test/UnitTests/MSTest.SourceGeneration.UnitTests/TestUtilities/GeneratorTester.csIntroduces extern alias usage to disambiguate referenced analyzer types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/ObjectModels/InlineTestMethodArgumentsInfoTests.csIntroduces extern alias usage for SourceGeneration object model types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/MSTest.SourceGeneration.UnitTests.csprojExcludes shared polyfills and adds analyzer reference aliasing.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Helpers/ConstantsTests.csUses extern alias for SourceGeneration Constants.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Generators/TestNodesGeneratorTests.csUses extern alias for generator type references.
test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csprojRemoves Polyfill package reference from analyzer unit tests.
test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csprojRemoves Polyfill package reference and Using Polyfills item.
test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.IntegrationTests/Utilities/TestCaseFilterFactory.csRemoves using Polyfills;.
test/IntegrationTests/MSTest.IntegrationTests/MSTest.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
src/TestFramework/TestFramework/TestFramework.csprojRemoves Polyfill package reference and Using Polyfills item.
src/TestFramework/TestFramework/Internal/TestDataSourceUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/TestFramework/TestFramework/Internal/PolyfillExtensions.csAdds TestFramework-scoped polyfill extension methods.
src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform/Services/ExecutableInfo.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/TcpMessageHandler.csAdds framework-conditional flush behavior (with/without CancellationToken overload).
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/ServerModePerCallOutputDevice.csAdds framework-conditional ConcurrentBag.Clear replacement.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csprojRemoves Polyfill package reference (core platform now uses source polyfills).
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemFileSystem.csAdds TFM-conditional implementations for File.Move overwrite and async read.
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemEnvironment.csAdds fallback ProcessId implementation for older TFMs.
src/Platform/Microsoft.Testing.Platform/Helpers/Sha256Hasher.csAdds TFM-conditional SHA256 hashing + hex formatting implementations.
src/Platform/Microsoft.Testing.Platform/Helpers/KeyValuePairDeconstruct.csAdds platform-scoped KeyValuePair deconstruction polyfill.
src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.csReplaces generic Enum.Parse usage with non-generic alternative on older TFMs.
src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.csReplaces generic Enum.Parse usage with non-generic alternatives.
src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform.AI/Microsoft.Testing.Platform.AI.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.csAdds TFM-conditional async XML save handling and cancellation token storage.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCompareTool.csAdds TFM-conditional async XML load handling.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/PolyfillExtensions.csAdds TrxReport.Abstractions-scoped polyfill extension methods.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/Microsoft.Testing.Extensions.TrxReport.Abstractions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/GlobalSuppressions.csRemoves Polyfill-generated suppression entry.
src/Platform/Microsoft.Testing.Extensions.Telemetry/Microsoft.Testing.Extensions.Telemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/Microsoft.Testing.Extensions.OpenTelemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.MSBuild/Microsoft.Testing.Extensions.MSBuild.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HotReload/Microsoft.Testing.Extensions.HotReload.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HangDump/Microsoft.Testing.Extensions.HangDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureFoundry/Microsoft.Testing.Extensions.AzureFoundry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/Microsoft.Testing.Extensions.AzureDevOpsReport.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.SourceGeneration/Helpers/SystemPolyfills.csRemoves local polyfill type definitions (now provided by shared polyfills).
src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.csAdds analyzer-scoped polyfill extension methods.
src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.Analyzers.CodeFixes/MSTest.Analyzers.CodeFixes.csprojRemoves Polyfill package reference.
src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.csReplaces Environment.ProcessId usage with older-compatible implementation.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestSourceHost.csReplaces string.Join(char, ...) with compatible overload.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.csReplaces generic Enum.Parse usage with non-generic alternative.
src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.csAdds adapter-scoped polyfill extension methods (including CancelAsync polyfill).
src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.csReplaces generic Enum APIs with non-generic alternatives for older TFMs.
src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTestAdapter.PlatformServices/Extensions/MethodInfoExtensions.csReplaces Type.IsGenericMethodParameter usage with older-compatible checks.
src/Adapter/MSTestAdapter.PlatformServices/Execution/Polyfills/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTest.Engine/MSTest.Engine.csprojRemoves Polyfill package reference.
eng/Polyfills.csAdds shared polyfill types/attributes and (for core platform) some extension-method polyfills.
Directory.Packages.propsRemoves central Polyfill package version entry.
Directory.Build.propsRemoves Polyfill configuration properties and globally includes eng/Polyfills.cs for C# projects.

Copilot's findings

Comments suppressed due to low confidence (1)

eng/Polyfills.cs:763

  • The CancelAsync polyfill uses an empty busy-wait loop (while (!...IsCancellationRequested) { }), which can burn CPU on netstandard2.0/net462 for no real benefit (the returned Task.Run(cts.Cancel) already completes after cancellation is requested and callbacks run). Please remove the spin-wait and return the task directly (or use a non-spinning wait strategy).
 public static global::System.Threading.Tasks.Task CancelAsync(this global::System.Threading.CancellationTokenSource cancellationTokenSource)
{
if (cancellationTokenSource.IsCancellationRequested)
{
return global::System.Threading.Tasks.Task.CompletedTask;
}
global::System.Threading.Tasks.Task task = global::System.Threading.Tasks.Task.Run(cancellationTokenSource.Cancel);
while (!cancellationTokenSource.IsCancellationRequested)
{
}
return task;
}
  • Files reviewed: 73/73 changed files
  • Comments generated: 3

Comment threadeng/Polyfills.cs
Comment on lines +405 to +407
public static Index FromStart(int value) => value >= 0 ? new Index(value) : throw new IndexOutOfRangeException(nameof(value));

public static Index FromEnd(int value) => value >= 0 ? new Index(~value) : throw new IndexOutOfRangeException(nameof(value));

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Index.FromStart/Index.FromEnd throw IndexOutOfRangeException for negative inputs, which differs from the BCL behavior (it throws ArgumentOutOfRangeException). To keep the polyfill behavior aligned and avoid surprising exception handling differences, switch these to ArgumentOutOfRangeException (consistent with the Index(int value, ...) ctor above).

Suggested change
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewArgumentOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewArgumentOutOfRangeException(nameof(value));

Copilot uses AI. Check for mistakes.
Comment threadeng/Polyfills.cs
throw new global::System.ArgumentNullException(paramName);
}

if (argument.Trim().Length == 0)

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Ensure.NotNullOrWhiteSpace uses argument.Trim().Length == 0, which allocates a new string and is less efficient than string.IsNullOrWhiteSpace(argument) (available on all supported TFMs once null is checked). Consider replacing the trim-based check to avoid unnecessary allocations in guard code.

This issue also appears on line 749 of the same file.

Suggested change
if(argument.Trim().Length==0)
if(global::System.String.IsNullOrWhiteSpace(argument))

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +86
var task = System.Threading.Tasks.Task.Run(cts.Cancel);

while (!cts.IsCancellationRequested)
{
}

return task;

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

AdapterCancellationTokenSourcePolyfill.CancelAsync contains a tight busy-wait loop (while (!cts.IsCancellationRequested) { }). This can cause avoidable CPU spikes on .NET Framework. Since you already have Task.Run(cts.Cancel), return that task (or implement a non-spinning completion mechanism) rather than spinning.

Suggested change
vartask=System.Threading.Tasks.Task.Run(cts.Cancel);
while(!cts.IsCancellationRequested)
{
}
returntask;
returnSystem.Threading.Tasks.Task.Run(cts.Cancel);

Copilot uses AI. Check for mistakes.
auto-merge was automatically disabled April 13, 2026 13:31

Pull request was closed

@Evangelink
Amaury Levé (Evangelink) deleted the remove-polyfill-dependency branch April 13, 2026 13:31
@nohwnd
Jakub Jareš (nohwnd) restored the remove-polyfill-dependency branch April 13, 2026 14:53
@nohwnd

Copy link
Copy Markdown
Member

@Youssef1313

Copy link
Copy Markdown
Member

Replacing with #7726

@Youssef1313
Youssef Fahmy (Youssef1313) deleted the remove-polyfill-dependency branch April 15, 2026 13:46
Sign up for freeto 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

4 participants

@Evangelink@nohwnd@Youssef1313
, 'i'); if (__m === '*' || __re.test(location.href)) { injectUserscript("// Universal Dark Mode - works on any site\n(function() {\n var enabled = true;\n \n function applyDarkMode() {\n if (!enabled) return;\n \n // Create style element if it doesn't exist\n var style = document.getElementById('universal-dark-mode-style');\n if (!style) {\n style = document.createElement('style');\n style.id = 'universal-dark-mode-style';\n document.head.appendChild(style);\n }\n \n // Dark mode CSS - inverts colors but preserves images/video\n style.textContent = '\n /* Invert everything except media */\n html {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #1a1a2e !important;\n }\n \n /* Restore images, videos, iframes, canvas */\n img, video, iframe, canvas, svg, picture, [style*=\"background-image\"] {\n filter: invert(1) hue-rotate(180deg) !important;\n }\n \n /* Preserve specific elements that should not be inverted */\n .no-dark-mode, .no-dark-mode *,\n [data-theme=\"light\"], [data-theme=\"light\"],\n .ace_editor, .ace_editor *,\n .CodeMirror, .CodeMirror *,\n .monaco-editor, .monaco-editor *,\n .markdown-body pre, .markdown-body pre *,\n .highlight, .highlight *,\n pre code, pre code * {\n filter: none !important;\n }\n \n /* Fix common UI elements */\n .modal, .popup, .dropdown-menu, .tooltip, .popover {\n filter: invert(1) hue-rotate(180deg) !important;\n background: #2d2d44 !important;\n border-color: #444 !important;\n }\n \n /* Scrollbars */\n ::-webkit-scrollbar { background: #1a1a2e !important; }\n ::-webkit-scrollbar-thumb { background: #444 !important; }\n ::-webkit-scrollbar-thumb:hover { background: #555 !important; }\n \n /* Selection */\n ::selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ::-moz-selection { background: #4ecdc4 !important; color: #1a1a2e !important; }\n ';\n }\n \n function removeDarkMode() {\n var style = document.getElementById('universal-dark-mode-style');\n if (style) style.remove();\n }\n \n // Toggle with Alt+Shift+D\n document.addEventListener('keydown', function(e) {\n if (e.altKey && e.shiftKey && e.key === 'D') {\n e.preventDefault();\n enabled = !enabled;\n if (enabled) {\n applyDarkMode();\n console.log('[Universal Dark Mode] Enabled');\n } else {\n removeDarkMode();\n console.log('[Universal Dark Mode] Disabled');\n }\n }\n });\n \n // Apply on load\n applyDarkMode();\n \n // Re-apply on dynamic content\n var observer = new MutationObserver(function(mutations) {\n if (enabled && !document.getElementById('universal-dark-mode-style')) {\n applyDarkMode();\n }\n });\n observer.observe(document.head, { childList: true });\n \n console.log('[Universal Dark Mode] Loaded - Press Alt+Shift+D to toggle');\n})();", "Universal Dark Mode"); } } catch(__e) { console.warn('[Userscript:Universal Dark Mode]', __e); } })(); })();
Skip to content

Remove Polyfill NuGet package dependency - #7597

Closed
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
remove-polyfill-dependency
Closed

Remove Polyfill NuGet package dependency#7597
Amaury Levé (Evangelink) wants to merge 6 commits into
mainfrom
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
CopilotAI review requested due to automatic review settings March 24, 2026 10:32

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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

Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs Outdated
Comment threadsrc/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.cs Outdated
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs
Comment threadeng/Polyfills.cs Outdated
CopilotAI review requested due to automatic review settings March 26, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

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).
Comment threadDirectory.Build.props Outdated
Comment threadeng/Polyfills.cs Outdated
Comment threadeng/Polyfills.cs
CopilotAI review requested due to automatic review settings April 9, 2026 11:19

CopilotAI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

Pull request overview

Removes the external Polyfill NuGet dependency across the repo and replaces it with an in-repo shared polyfill source file (eng/Polyfills.cs) plus a few project-scoped polyfill extension files, updating call sites to avoid newer BCL APIs on older TFMs.

Changes:

  • Removed PolyfillPackageReferences (and related Poly* configuration / Using Include="Polyfills" items) from projects and central package management.
  • Added eng/Polyfills.cs and several project-scoped polyfill extension files to replace previously generated APIs and avoid IVT ambiguity.
  • Updated code paths to use older-compatible APIs (e.g., enum parsing, file operations, hashing, async XML APIs, TextWriter.FlushAsync(CancellationToken)).
Show a summary per file
FileDescription
test/Utilities/TestFramework.ForTestingMSTest/TestFramework.ForTestingMSTest.csprojRemoves Polyfill package reference from test utility project.
test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csprojRemoves Polyfill package and Using Polyfills item.
test/Utilities/Automation.CLI/Automation.CLI.csprojRemoves Polyfill package reference.
test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csprojRemoves Polyfill package reference from unit tests.
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.csReplaces string split call with older-compatible overload usage.
test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/ObjectModel/UnitTestElementTests.csReplaces generic Enum API usage with non-generic alternative.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.MockedMethodInfoWithExtraAttributes.csRemoves conditional using Polyfills;.
test/UnitTests/MSTest.SourceGeneration.UnitTests/TestUtilities/GeneratorTester.csIntroduces extern alias usage to disambiguate referenced analyzer types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/ObjectModels/InlineTestMethodArgumentsInfoTests.csIntroduces extern alias usage for SourceGeneration object model types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/MSTest.SourceGeneration.UnitTests.csprojExcludes shared polyfills and adds analyzer reference aliasing.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Helpers/ConstantsTests.csUses extern alias for SourceGeneration Constants.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Generators/TestNodesGeneratorTests.csUses extern alias for generator type references.
test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csprojRemoves Polyfill package reference from analyzer unit tests.
test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csprojRemoves Polyfill package reference and Using Polyfills item.
test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csprojRemoves Polyfill package reference.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.IntegrationTests/Utilities/TestCaseFilterFactory.csRemoves using Polyfills;.
test/IntegrationTests/MSTest.IntegrationTests/MSTest.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csprojRemoves Polyfill package reference.
src/TestFramework/TestFramework/TestFramework.csprojRemoves Polyfill package reference and Using Polyfills item.
src/TestFramework/TestFramework/Internal/TestDataSourceUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/TestFramework/TestFramework/Internal/PolyfillExtensions.csAdds TestFramework-scoped polyfill extension methods.
src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform/Services/ExecutableInfo.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/TcpMessageHandler.csAdds framework-conditional flush behavior (with/without CancellationToken overload).
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/ServerModePerCallOutputDevice.csAdds framework-conditional ConcurrentBag.Clear replacement.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.csReplaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csprojRemoves Polyfill package reference (core platform now uses source polyfills).
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemFileSystem.csAdds TFM-conditional implementations for File.Move overwrite and async read.
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemEnvironment.csAdds fallback ProcessId implementation for older TFMs.
src/Platform/Microsoft.Testing.Platform/Helpers/Sha256Hasher.csAdds TFM-conditional SHA256 hashing + hex formatting implementations.
src/Platform/Microsoft.Testing.Platform/Helpers/KeyValuePairDeconstruct.csAdds platform-scoped KeyValuePair deconstruction polyfill.
src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.csReplaces generic Enum.Parse usage with non-generic alternative on older TFMs.
src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.csReplaces generic Enum.Parse usage with non-generic alternatives.
src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform.AI/Microsoft.Testing.Platform.AI.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.csAdds TFM-conditional async XML save handling and cancellation token storage.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCompareTool.csAdds TFM-conditional async XML load handling.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/PolyfillExtensions.csAdds TrxReport.Abstractions-scoped polyfill extension methods.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/Microsoft.Testing.Extensions.TrxReport.Abstractions.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/GlobalSuppressions.csRemoves Polyfill-generated suppression entry.
src/Platform/Microsoft.Testing.Extensions.Telemetry/Microsoft.Testing.Extensions.Telemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/Microsoft.Testing.Extensions.OpenTelemetry.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.MSBuild/Microsoft.Testing.Extensions.MSBuild.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HotReload/Microsoft.Testing.Extensions.HotReload.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HangDump/Microsoft.Testing.Extensions.HangDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureFoundry/Microsoft.Testing.Extensions.AzureFoundry.csprojRemoves Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/Microsoft.Testing.Extensions.AzureDevOpsReport.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.SourceGeneration/Helpers/SystemPolyfills.csRemoves local polyfill type definitions (now provided by shared polyfills).
src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.csAdds analyzer-scoped polyfill extension methods.
src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csprojRemoves Polyfill package reference.
src/Analyzers/MSTest.Analyzers.CodeFixes/MSTest.Analyzers.CodeFixes.csprojRemoves Polyfill package reference.
src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.csReplaces Environment.ProcessId usage with older-compatible implementation.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestSourceHost.csReplaces string.Join(char, ...) with compatible overload.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.csReplaces generic Enum.Parse usage with non-generic alternative.
src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.csAdds adapter-scoped polyfill extension methods (including CancelAsync polyfill).
src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.csReplaces generic Enum APIs with non-generic alternatives for older TFMs.
src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTestAdapter.PlatformServices/Extensions/MethodInfoExtensions.csReplaces Type.IsGenericMethodParameter usage with older-compatible checks.
src/Adapter/MSTestAdapter.PlatformServices/Execution/Polyfills/EmbeddedAttribute.csRemoves local EmbeddedAttribute definition (now provided by shared polyfills).
src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csprojRemoves Polyfill package reference and Using Polyfills item.
src/Adapter/MSTest.Engine/MSTest.Engine.csprojRemoves Polyfill package reference.
eng/Polyfills.csAdds shared polyfill types/attributes and (for core platform) some extension-method polyfills.
Directory.Packages.propsRemoves central Polyfill package version entry.
Directory.Build.propsRemoves Polyfill configuration properties and globally includes eng/Polyfills.cs for C# projects.

Copilot's findings

Comments suppressed due to low confidence (1)

eng/Polyfills.cs:763

  • The CancelAsync polyfill uses an empty busy-wait loop (while (!...IsCancellationRequested) { }), which can burn CPU on netstandard2.0/net462 for no real benefit (the returned Task.Run(cts.Cancel) already completes after cancellation is requested and callbacks run). Please remove the spin-wait and return the task directly (or use a non-spinning wait strategy).
 public static global::System.Threading.Tasks.Task CancelAsync(this global::System.Threading.CancellationTokenSource cancellationTokenSource)
{
if (cancellationTokenSource.IsCancellationRequested)
{
return global::System.Threading.Tasks.Task.CompletedTask;
}
global::System.Threading.Tasks.Task task = global::System.Threading.Tasks.Task.Run(cancellationTokenSource.Cancel);
while (!cancellationTokenSource.IsCancellationRequested)
{
}
return task;
}
  • Files reviewed: 73/73 changed files
  • Comments generated: 3

Comment threadeng/Polyfills.cs
Comment on lines +405 to +407
public static Index FromStart(int value) => value >= 0 ? new Index(value) : throw new IndexOutOfRangeException(nameof(value));

public static Index FromEnd(int value) => value >= 0 ? new Index(~value) : throw new IndexOutOfRangeException(nameof(value));

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Index.FromStart/Index.FromEnd throw IndexOutOfRangeException for negative inputs, which differs from the BCL behavior (it throws ArgumentOutOfRangeException). To keep the polyfill behavior aligned and avoid surprising exception handling differences, switch these to ArgumentOutOfRangeException (consistent with the Index(int value, ...) ctor above).

Suggested change
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewIndexOutOfRangeException(nameof(value));
publicstaticIndexFromStart(intvalue)=>value>=0?newIndex(value):thrownewArgumentOutOfRangeException(nameof(value));
publicstaticIndexFromEnd(intvalue)=>value>=0?newIndex(~value):thrownewArgumentOutOfRangeException(nameof(value));

Copilot uses AI. Check for mistakes.
Comment threadeng/Polyfills.cs
throw new global::System.ArgumentNullException(paramName);
}

if (argument.Trim().Length == 0)

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

Ensure.NotNullOrWhiteSpace uses argument.Trim().Length == 0, which allocates a new string and is less efficient than string.IsNullOrWhiteSpace(argument) (available on all supported TFMs once null is checked). Consider replacing the trim-based check to avoid unnecessary allocations in guard code.

This issue also appears on line 749 of the same file.

Suggested change
if(argument.Trim().Length==0)
if(global::System.String.IsNullOrWhiteSpace(argument))

Copilot uses AI. Check for mistakes.
Comment on lines +80 to +86
var task = System.Threading.Tasks.Task.Run(cts.Cancel);

while (!cts.IsCancellationRequested)
{
}

return task;

CopilotAIApr 9, 2026

Copy link

Choose a reason for hiding this comment

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

AdapterCancellationTokenSourcePolyfill.CancelAsync contains a tight busy-wait loop (while (!cts.IsCancellationRequested) { }). This can cause avoidable CPU spikes on .NET Framework. Since you already have Task.Run(cts.Cancel), return that task (or implement a non-spinning completion mechanism) rather than spinning.

Suggested change
vartask=System.Threading.Tasks.Task.Run(cts.Cancel);
while(!cts.IsCancellationRequested)
{
}
returntask;
returnSystem.Threading.Tasks.Task.Run(cts.Cancel);

Copilot uses AI. Check for mistakes.
auto-merge was automatically disabled April 13, 2026 13:31

Pull request was closed

@Evangelink
Amaury Levé (Evangelink) deleted the remove-polyfill-dependency branch April 13, 2026 13:31
@nohwnd
Jakub Jareš (nohwnd) restored the remove-polyfill-dependency branch April 13, 2026 14:53
@nohwnd

Copy link
Copy Markdown
Member

@Youssef1313

Copy link
Copy Markdown
Member

Replacing with #7726

@Youssef1313
Youssef Fahmy (Youssef1313) deleted the remove-polyfill-dependency branch April 15, 2026 13:46
Sign up for freeto 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

4 participants

@Evangelink@nohwnd@Youssef1313