Skip to content

Remove Polyfill NuGet package dependency#7597

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

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

Conversation

@Evangelink
Copy link
Copy Markdown
Member

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

Changes

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

Replacements

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

Call-site fixes

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

Fixes #7596

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

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

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

Changes:

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

Reviewed changes

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

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

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

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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

…d param

- Add Polyfills.Guard, Polyfills.Ensure, and Polyfills.Polyfill backward-
  compatible types in eng/Polyfills.cs (guarded by IS_CORE_MTP) to prevent
  TypeLoadException/MissingMethodException when old extension packages
  reference these types from the platform assembly via InternalsVisibleTo.
- Fix unused cancellationToken parameter in TrxReportEngine constructor
  for netstandard2.0 builds (addresses PR review comment).
Copilot AI review requested due to automatic review settings April 9, 2026 11:19
Copy link
Copy Markdown
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

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

Pull request overview

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 Polyfill PackageReferences (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
File Description
test/Utilities/TestFramework.ForTestingMSTest/TestFramework.ForTestingMSTest.csproj Removes Polyfill package reference from test utility project.
test/Utilities/Microsoft.Testing.TestInfrastructure/Microsoft.Testing.TestInfrastructure.csproj Removes Polyfill package and Using Polyfills item.
test/Utilities/Automation.CLI/Automation.CLI.csproj Removes Polyfill package reference.
test/UnitTests/TestFramework.UnitTests/TestFramework.UnitTests.csproj Removes Polyfill package reference from unit tests.
test/UnitTests/TestFramework.UnitTests/Assertions/AssertTests.AreEqualTests.cs Replaces string split call with older-compatible overload usage.
test/UnitTests/MSTestAdapter.UnitTests/MSTestAdapter.UnitTests.csproj Removes Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/ObjectModel/UnitTestElementTests.cs Replaces generic Enum API usage with non-generic alternative.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/MSTestAdapter.PlatformServices.UnitTests.csproj Removes Polyfill package reference.
test/UnitTests/MSTestAdapter.PlatformServices.UnitTests/Discovery/TypeEnumeratorTests.MockedMethodInfoWithExtraAttributes.cs Removes conditional using Polyfills;.
test/UnitTests/MSTest.SourceGeneration.UnitTests/TestUtilities/GeneratorTester.cs Introduces extern alias usage to disambiguate referenced analyzer types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/ObjectModels/InlineTestMethodArgumentsInfoTests.cs Introduces extern alias usage for SourceGeneration object model types.
test/UnitTests/MSTest.SourceGeneration.UnitTests/MSTest.SourceGeneration.UnitTests.csproj Excludes shared polyfills and adds analyzer reference aliasing.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Helpers/ConstantsTests.cs Uses extern alias for SourceGeneration Constants.
test/UnitTests/MSTest.SourceGeneration.UnitTests/Generators/TestNodesGeneratorTests.cs Uses extern alias for generator type references.
test/UnitTests/MSTest.Analyzers.UnitTests/MSTest.Analyzers.UnitTests.csproj Removes Polyfill package reference from analyzer unit tests.
test/UnitTests/Microsoft.Testing.Platform.UnitTests/Microsoft.Testing.Platform.UnitTests.csproj Removes Polyfill package reference and Using Polyfills item.
test/UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests/Microsoft.Testing.Extensions.VSTestBridge.UnitTests.csproj Removes Polyfill package reference.
test/UnitTests/Microsoft.Testing.Extensions.UnitTests/Microsoft.Testing.Extensions.UnitTests.csproj Removes Polyfill package reference.
test/IntegrationTests/MSTest.IntegrationTests/Utilities/TestCaseFilterFactory.cs Removes using Polyfills;.
test/IntegrationTests/MSTest.IntegrationTests/MSTest.IntegrationTests.csproj Removes Polyfill package reference.
test/IntegrationTests/MSTest.Acceptance.IntegrationTests/MSTest.Acceptance.IntegrationTests.csproj Removes Polyfill package reference.
test/IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests/Microsoft.Testing.Platform.Acceptance.IntegrationTests.csproj Removes Polyfill package reference.
src/TestFramework/TestFramework/TestFramework.csproj Removes Polyfill package reference and Using Polyfills item.
src/TestFramework/TestFramework/Internal/TestDataSourceUtilities.cs Replaces string.Join(char, ...) with compatible overload.
src/TestFramework/TestFramework/Internal/PolyfillExtensions.cs Adds TestFramework-scoped polyfill extension methods.
src/TestFramework/TestFramework.Extensions/TestFramework.Extensions.csproj Removes Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform/Services/ExecutableInfo.cs Replaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/TcpMessageHandler.cs Adds framework-conditional flush behavior (with/without CancellationToken overload).
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/ServerModePerCallOutputDevice.cs Adds framework-conditional ConcurrentBag.Clear replacement.
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/SerializerUtilities.cs Replaces string.Join(char, ...) with compatible overload.
src/Platform/Microsoft.Testing.Platform/Microsoft.Testing.Platform.csproj Removes Polyfill package reference (core platform now uses source polyfills).
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemFileSystem.cs Adds TFM-conditional implementations for File.Move overwrite and async read.
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemEnvironment.cs Adds fallback ProcessId implementation for older TFMs.
src/Platform/Microsoft.Testing.Platform/Helpers/Sha256Hasher.cs Adds TFM-conditional SHA256 hashing + hex formatting implementations.
src/Platform/Microsoft.Testing.Platform/Helpers/KeyValuePairDeconstruct.cs Adds platform-scoped KeyValuePair deconstruction polyfill.
src/Platform/Microsoft.Testing.Platform/Builder/TestApplication.cs Replaces generic Enum.Parse usage with non-generic alternative on older TFMs.
src/Platform/Microsoft.Testing.Platform.MSBuild/Tasks/InvokeTestingPlatformTask.cs Replaces generic Enum.Parse usage with non-generic alternatives.
src/Platform/Microsoft.Testing.Platform.MSBuild/Microsoft.Testing.Platform.MSBuild.csproj Removes Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Platform.AI/Microsoft.Testing.Platform.AI.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.VSTestBridge/Microsoft.Testing.Extensions.VSTestBridge.csproj Removes Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxReportEngine.cs Adds TFM-conditional async XML save handling and cancellation token storage.
src/Platform/Microsoft.Testing.Extensions.TrxReport/TrxCompareTool.cs Adds TFM-conditional async XML load handling.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Microsoft.Testing.Extensions.TrxReport.csproj Removes Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport/Hashing/EmbeddedAttribute.cs Removes local EmbeddedAttribute definition (now provided by shared polyfills).
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/PolyfillExtensions.cs Adds TrxReport.Abstractions-scoped polyfill extension methods.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/Microsoft.Testing.Extensions.TrxReport.Abstractions.csproj Removes Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/GlobalSuppressions.cs Removes Polyfill-generated suppression entry.
src/Platform/Microsoft.Testing.Extensions.Telemetry/Microsoft.Testing.Extensions.Telemetry.csproj Removes Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.Retry/Microsoft.Testing.Extensions.Retry.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.OpenTelemetry/Microsoft.Testing.Extensions.OpenTelemetry.csproj Removes Polyfill package reference and Using Polyfills item.
src/Platform/Microsoft.Testing.Extensions.MSBuild/Microsoft.Testing.Extensions.MSBuild.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HotReload/Microsoft.Testing.Extensions.HotReload.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.HangDump/Microsoft.Testing.Extensions.HangDump.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.CrashDump/Microsoft.Testing.Extensions.CrashDump.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureFoundry/Microsoft.Testing.Extensions.AzureFoundry.csproj Removes Polyfill package reference.
src/Platform/Microsoft.Testing.Extensions.AzureDevOpsReport/Microsoft.Testing.Extensions.AzureDevOpsReport.csproj Removes Polyfill package reference.
src/Analyzers/MSTest.SourceGeneration/Helpers/SystemPolyfills.cs Removes local polyfill type definitions (now provided by shared polyfills).
src/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.cs Adds analyzer-scoped polyfill extension methods.
src/Analyzers/MSTest.Analyzers/MSTest.Analyzers.csproj Removes Polyfill package reference.
src/Analyzers/MSTest.Analyzers.CodeFixes/MSTest.Analyzers.CodeFixes.csproj Removes Polyfill package reference.
src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.cs Replaces Environment.ProcessId usage with older-compatible implementation.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestSourceHost.cs Replaces string.Join(char, ...) with compatible overload.
src/Adapter/MSTestAdapter.PlatformServices/Services/TestDataSource.cs Replaces generic Enum.Parse usage with non-generic alternative.
src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs Adds adapter-scoped polyfill extension methods (including CancelAsync polyfill).
src/Adapter/MSTestAdapter.PlatformServices/MSTestSettings.cs Replaces generic Enum APIs with non-generic alternatives for older TFMs.
src/Adapter/MSTestAdapter.PlatformServices/MSTestAdapter.PlatformServices.csproj Removes Polyfill package reference and Using Polyfills item.
src/Adapter/MSTestAdapter.PlatformServices/Extensions/MethodInfoExtensions.cs Replaces Type.IsGenericMethodParameter usage with older-compatible checks.
src/Adapter/MSTestAdapter.PlatformServices/Execution/Polyfills/EmbeddedAttribute.cs Removes local EmbeddedAttribute definition (now provided by shared polyfills).
src/Adapter/MSTest.TestAdapter/MSTest.TestAdapter.csproj Removes Polyfill package reference and Using Polyfills item.
src/Adapter/MSTest.Engine/MSTest.Engine.csproj Removes Polyfill package reference.
eng/Polyfills.cs Adds shared polyfill types/attributes and (for core platform) some extension-method polyfills.
Directory.Packages.props Removes central Polyfill package version entry.
Directory.Build.props Removes 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 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));
Copy link

Copilot AI Apr 9, 2026

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
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));
public static Index FromStart(int value) => value >= 0 ? new Index(value) : throw new ArgumentOutOfRangeException(nameof(value));
public static Index FromEnd(int value) => value >= 0 ? new Index(~value) : throw new ArgumentOutOfRangeException(nameof(value));

Copilot uses AI. Check for mistakes.
throw new global::System.ArgumentNullException(paramName);
}

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

Copilot AI Apr 9, 2026

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;
Copy link

Copilot AI Apr 9, 2026

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
var task = System.Threading.Tasks.Task.Run(cts.Cancel);
while (!cts.IsCancellationRequested)
{
}
return task;
return System.Threading.Tasks.Task.Run(cts.Cancel);

Copilot uses AI. Check for mistakes.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Consider removing Polyfill NuGet package dependency

3 participants