Skip to content

Clean-up unnecessary compatibility polyfills and feature definitions.#12231

Open
teo-tsirpanis wants to merge 6 commits intodotnet:mainfrom
teo-tsirpanis:rm-compat-code
Open

Clean-up unnecessary compatibility polyfills and feature definitions.#12231
teo-tsirpanis wants to merge 6 commits intodotnet:mainfrom
teo-tsirpanis:rm-compat-code

Conversation

@teo-tsirpanis
Copy link
Copy Markdown
Contributor

@teo-tsirpanis teo-tsirpanis commented Jul 26, 2025

Context

MSBuild has been using some polyfills and compatibility code, owing to it targeting earlier .NET Core and .NET Standard versions in the past. It doesn't target these frameworks anymore, so these can be removed.

Changes Made

The following were removed as unnecessary:

  • Calls to Type.GetTypeInfo()
  • Polyfills for methods on the Assembly class, that are now available on all supported frameworks.
  • The FEATURE_CULTUREINFO_GETCULTURES symbol, and all code conditioned upon it not being defined.

Testing

Existing test coverage.

Notes

FEATURE_XML_SCHEMA_VALIDATION is always available too, but since enabling it has user-visible effects, it will be done in a separate PR.

@teo-tsirpanis teo-tsirpanis force-pushed the rm-compat-code branch 4 times, most recently from 3085937 to e030e20 Compare July 27, 2025 00:36
@teo-tsirpanis

This comment was marked as resolved.

@teo-tsirpanis teo-tsirpanis marked this pull request as ready for review July 27, 2025 18:53
Copilot AI review requested due to automatic review settings July 27, 2025 18:53
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 cleans up unnecessary compatibility polyfills and feature definitions that were previously required for earlier .NET Core and .NET Standard versions but are no longer needed since MSBuild now targets only modern .NET frameworks.

  • Removes calls to Type.GetTypeInfo() and replaces them with direct Type property access
  • Removes Assembly polyfills and the FEATURE_CULTUREINFO_GETCULTURES and FEATURE_GET_COMMANDLINE feature flags
  • Simplifies code by using native framework APIs directly instead of compatibility wrappers

Reviewed Changes

Copilot reviewed 61 out of 61 changed files in this pull request and generated no comments.

Show a summary per file
File Description
src/Utilities/AssemblyResources.cs Remove GetTypeInfo() calls for ResourceManager assembly access
src/Utilities.UnitTests/ToolLocationHelper_Tests.cs Remove GetTypeInfo() calls for Module.FullyQualifiedName access
src/Utilities.UnitTests/MockTask.cs Remove GetTypeInfo() call for ResourceManager assembly access
src/UnitTests.Shared/MockLogger.cs Remove GetTypeInfo() call for Assembly access in resource manager
src/Tasks/RoslynCodeTaskFactory/RoslynCodeTaskFactory.cs Remove GetTypeInfo() call for assembly directory path calculation
src/Tasks/CultureInfoCache.cs Remove FEATURE_CULTUREINFO_GETCULTURES feature flag and hardcoded culture names list
src/Tasks/AssemblyResources.cs Remove GetTypeInfo() calls for ResourceManager assembly access
src/Shared/UnitTests/TypeLoader_Tests.cs Remove FEATURE_ASSEMBLY_LOCATION feature flag and add assembly load context checks
src/Shared/Tracing.cs Remove GetTypeInfo() call for assembly name access
src/Shared/TaskParameterTypeVerifier.cs Remove GetTypeInfo() calls for type property checks
src/Shared/TaskParameter.cs Remove GetTypeInfo() calls for type assignability checks
src/Shared/TaskLoader.cs Remove GetTypeInfo() calls for task class validation
src/Shared/LoadedType.cs Remove GetTypeInfo() calls for attribute checks
src/Shared/FileUtilities.cs Remove GetTypeInfo() call for executing assembly path
src/Shared/CoreCLRAssemblyLoader.cs Add well-known assembly name check for load optimization
src/Shared/CommunicationsUtilities.cs Remove GetTypeInfo() call for CLR version check
src/Shared/BuildEnvironmentHelper.cs Simplify process path detection by removing Assembly utility wrapper
src/Samples/PortableTask/ShowItems.cs Remove GetTypeInfo() call for core assembly access
src/MSBuild/XMake.cs Remove FEATURE_GET_COMMANDLINE feature flag and command line parameter handling
src/MSBuild/OutOfProcTaskHostNode.cs Remove GetTypeInfo() call for serialization check
src/MSBuild/MSBuildClientApp.cs Remove FEATURE_GET_COMMANDLINE feature flag conditionals
src/MSBuild/AssemblyResources.cs Remove GetTypeInfo() calls for ResourceManager assembly access
src/MSBuild.UnitTests/XMake_Tests.cs Remove FEATURE_GET_COMMANDLINE conditionals in test methods
src/MSBuild.UnitTests/CommandLineSwitches_Tests.cs Remove FEATURE_GET_COMMANDLINE conditionals in test execution
src/Framework/TaskPropertyInfo.cs Remove GetTypeInfo() call for value type check
src/Framework/NativeMethods.cs Remove GetTypeInfo() call for framework path detection
src/Framework/AssemblyUtilities.cs Remove all polyfill methods and compatibility code
src/Framework.UnitTests/Attribute_Tests.cs Remove GetTypeInfo() call for custom attribute access
src/Directory.BeforeCommon.targets Remove FEATURE_ASSEMBLY_LOCATION, FEATURE_CULTUREINFO_GETCULTURES, and FEATURE_GET_COMMANDLINE defines
src/BuildCheck.UnitTests/EditorConfig_Tests.cs Remove GetTypeInfo() calls for type checks
src/Build/Resources/MSBuildAssemblyFileVersion.cs Remove GetTypeInfo() call for assembly attribute access
src/Build/Resources/AssemblyResources.cs Remove GetTypeInfo() calls for ResourceManager assembly access
src/Build/Logging/LoggerDescription.cs Remove GetTypeInfo() calls for logger class validation
src/Build/Instance/TaskRegistry.cs Remove GetTypeInfo() calls for task factory class validation
src/Build/Instance/TaskFactoryLoggingHost.cs Remove GetTypeInfo() call for serialization check
src/Build/Instance/TaskFactories/TaskHostTask.cs Remove GetTypeInfo() calls for assembly location access
src/Build/Evaluation/Expander.cs Remove GetTypeInfo() call for enum type check
src/Build/Definition/ProjectCollection.cs Remove GetTypeInfo() call for assembly version access
src/Build/BackEnd/TaskExecutionHost/TaskExecutionHost.cs Remove GetTypeInfo() calls for assembly access
src/Build/BackEnd/Node/ServerNodeBuildCommand.cs Remove FEATURE_GET_COMMANDLINE conditionals
src/Build/BackEnd/Node/OutOfProcServerNode.cs Remove FEATURE_GET_COMMANDLINE conditionals
src/Build/BackEnd/Components/SdkResolution/SdkResolverService.cs Remove GetTypeInfo() call for type name check
src/Build/BackEnd/Components/SdkResolution/SdkResolverLoader.cs Remove GetTypeInfo() calls for type filtering
src/Build/BackEnd/Components/RequestBuilder/TaskHost.cs Remove GetTypeInfo() call for serialization check
src/Build/BackEnd/Components/RequestBuilder/TaskBuilder.cs Remove GetTypeInfo() call for exception type check
src/Build/BackEnd/Components/RequestBuilder/IntrinsicTask.cs Remove GetTypeInfo() call for base type access
src/Build/BackEnd/Components/ProjectCache/ProjectCacheService.cs Remove GetTypeInfo() calls for type filtering
src/Build/BackEnd/Components/Logging/LoggingService.cs Remove GetTypeInfo() call for assembly access
src/Build/BackEnd/Client/MSBuildClient.cs Remove FEATURE_GET_COMMANDLINE conditionals
src/Build/BackEnd/BuildManager/BuildManager.cs Remove GetTypeInfo() calls for assembly name access
src/Build.UnitTests/Utilities_Tests.cs Remove FEATURE_GET_COMMANDLINE conditionals in test execution
src/Build.UnitTests/Evaluation/Expander_Tests.cs Remove FEATURE_CULTUREINFO_GETCULTURES conditionals
src/Build.UnitTests/EscapingInProjects_Tests.cs Remove FEATURE_ASSEMBLY_LOCATION conditionals and update assembly access
src/Build.UnitTests/Definition/ItemDefinitionGroup_Tests.cs Remove FEATURE_ASSEMBLY_LOCATION conditionals and update assembly access
src/Build.UnitTests/BackEnd/TranslationHelpers.cs Add assembly load context comparison for exception types
src/Build.UnitTests/BackEnd/TaskRegistry_Tests.cs Remove FEATURE_ASSEMBLY_LOCATION conditionals and update assembly location access
src/Build.UnitTests/BackEnd/TaskExecutionHost_Tests.cs Remove GetTypeInfo() calls for type checks
src/Build.UnitTests/BackEnd/SdkResolverLoader_Tests.cs Remove GetTypeInfo() calls for assembly access
src/Build.UnitTests/BackEnd/LoggingService_Tests.cs Remove FEATURE_ASSEMBLY_LOCATION conditionals and update assembly access
src/Build.UnitTests/BackEnd/AssemblyTaskFactory_Tests.cs Remove FEATURE_ASSEMBLY_LOCATION conditionals and update assembly load info
src/Build.OM.UnitTests/Definition/ProjectCollection_Tests.cs Remove GetTypeInfo() call for assembly version access
Comments suppressed due to low confidence (1)

Comment on lines +58 to +66
AssemblyName assemblyName = AssemblyLoadContext.GetAssemblyName(fullPath);
if (MSBuildLoadContext.WellKnownAssemblyNames.Contains(assemblyName.Name))
{
// If this is a well-known assembly, load it directly, ensuring that
// it is loaded only once. Some tests might pass a well-known assembly
// to this method.
return Assembly.Load(assemblyName);
}

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

This is the only non-trivial change in the PR.

@YuliiaKovalova
Copy link
Copy Markdown
Member

hi @teo-tsirpanis ,

Could you please update this PR if you want to have it in?

@teo-tsirpanis teo-tsirpanis force-pushed the rm-compat-code branch 2 times, most recently from a478eb2 to 5bf56e7 Compare October 29, 2025 22:45
Fixes at least one failing test. Type checking in tests was also enhanced to better catch these kinds of errors.
@teo-tsirpanis
Copy link
Copy Markdown
Contributor Author

@YuliiaKovalova conflicts resolved.

@YuliiaKovalova YuliiaKovalova self-assigned this Oct 30, 2025
@github-actions
Copy link
Copy Markdown
Contributor

This pull request has been automatically closed because it has been open for more than 180 days with no recent activity.

If you believe this work is still relevant, please feel free to reopen or create a new pull request. Thank you for your contribution!

Generated by Close Stale Pull Requests

@github-actions github-actions Bot closed this Mar 17, 2026
@teo-tsirpanis
Copy link
Copy Markdown
Contributor Author

@YuliiaKovalova could you reopen this?

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.

3 participants