Conversation
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
There was a problem hiding this comment.
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
PolyfillPackageReferenceentries (and related MSBuild config/global usings) across projects. - Added
eng/Polyfills.csand wired it into builds viaDirectory.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. |
src/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cs
Outdated
Show resolved
Hide resolved
src/Platform/Microsoft.Testing.Platform/Helpers/System/SystemEnvironment.cs
Show resolved
Hide resolved
src/Adapter/MSTestAdapter.PlatformServices/Utilities/DeploymentUtility.cs
Outdated
Show resolved
Hide resolved
src/Platform/Microsoft.Testing.Platform/ServerMode/JsonRpc/TcpMessageHandler.cs
Show resolved
Hide resolved
…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).
There was a problem hiding this comment.
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 relatedPoly*configuration /Using Include="Polyfills"items) from projects and central package management. - Added
eng/Polyfills.csand 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
CancelAsyncpolyfill uses an empty busy-wait loop (while (!...IsCancellationRequested) { }), which can burn CPU on netstandard2.0/net462 for no real benefit (the returnedTask.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
| 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)); |
There was a problem hiding this comment.
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).
| 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)); |
| throw new global::System.ArgumentNullException(paramName); | ||
| } | ||
|
|
||
| if (argument.Trim().Length == 0) |
There was a problem hiding this comment.
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.
| if (argument.Trim().Length == 0) | |
| if (global::System.String.IsNullOrWhiteSpace(argument)) |
| var task = System.Threading.Tasks.Task.Run(cts.Cancel); | ||
|
|
||
| while (!cts.IsCancellationRequested) | ||
| { | ||
| } | ||
|
|
||
| return task; |
There was a problem hiding this comment.
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.
| var task = System.Threading.Tasks.Task.Run(cts.Cancel); | |
| while (!cts.IsCancellationRequested) | |
| { | |
| } | |
| return task; | |
| return System.Threading.Tasks.Task.Run(cts.Cancel); |
Replace the Polyfill NuGet package with a self-contained
eng/Polyfills.csfile and project-specific polyfill extension methods.Changes
PolyfillPackageReference from all 35 csproj filesPolyEnsure,PolyGuard,PolyStringInterpolation,PolyUseEmbeddedAttribute) fromDirectory.Build.propsPackageVersionentry fromDirectory.Packages.props<Using Include="Polyfills" />directives from 12 csproj filesusing Polyfills;from source filesGlobalSuppressionsentryReplacements
eng/Polyfills.cs— Shared polyfill types and attributes for older TFMs (netstandard2.0,net462): nullable attributes, compiler attributes,ExperimentalAttribute,Index/Range,Lock,OperatingSystem,UnreachableException,Ensurehelper, etc.src/Platform/Microsoft.Testing.Platform/Helpers/KeyValuePairDeconstruct.cssrc/Platform/Microsoft.Testing.Extensions.TrxReport.Abstractions/PolyfillExtensions.cssrc/TestFramework/TestFramework/Internal/PolyfillExtensions.cssrc/Adapter/MSTestAdapter.PlatformServices/PolyfillExtensions.cssrc/Analyzers/MSTest.Analyzers/RoslynAnalyzerHelpers/AnalyzerPolyfillExtensions.csCall-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), andTextWriter.FlushAsync(CancellationToken).Fixes #7596