Skip to content

Move more shared files to a single binary#13370

Open
DustinCampbell wants to merge 43 commits intomainfrom
dev/dustinca/further-shared-file-work
Open

Move more shared files to a single binary#13370
DustinCampbell wants to merge 43 commits intomainfrom
dev/dustinca/further-shared-file-work

Conversation

@DustinCampbell
Copy link
Member

@DustinCampbell DustinCampbell commented Mar 11, 2026

This pull request continues moving shared code to a single target binary. In most cases, that's going to be Microsoft.Build.Framework.

The commits are very granular: One commit per shared code file moved. Feel free to review the whole PR in one go or review commit-by-commit -- whichever works best for you!

I have intentionally not cleaned up the code that I've moved to keep the changes small. General clean-up will come later.

Base automatically changed from dev/dustinca/isolate-taskhost-followup to main March 12, 2026 15:41
- Move src/Shared/IElementLocation.cs to Microsoft.Build
- Move src/Shared/IKeyed.cs to Microsoft.Build
- Move src/Shared/ReadOnlyEmptyCollection.cs to Microsoft.Build.Framework
- Add "CollectionIsReadOnly" string resource to src/Framework/SR.resx (copied from "OM_NotSupportedReadOnlyCollection"). Take care to copy translated strings to the correct .xlf file.
- Move src/Shared/ReadOnlyCollection.cs to Microsoft.Build.Framework
- Move src/Shared/ReadOnlyEmptyDictionary.cs to Microsoft.Build.Framework
- Move src/Shared/BufferedReadStream.cs to Microsoft.Build.Framework
- Move src/Shared/CopyOnWriteDictionary.cs to Microsoft.Build.Framework
- Move src/Shared/ConversionUtilities.cs to Microsoft.Build.Framework
- Add "CannotConvertStringToBool" string resource to src/Framework/SR.resx (copied from "Shared.CannotConvertStringToBool"). Take care to copy translated strings to the correct .xlf file.
- Move src/Shared/TaskFactoryUtilities.cs to Microsoft.Build.Framework
- Move src/Shared/TranslatorHelpers.cs to Microsoft.Build.Framework
- Move src/Shared/InterningBinaryReader.cs to Microsoft.Build.Framework
Rather than compiling files directly into Microsoft.Build.Engine.OM.UnitTests.csproj, provide IVT from Microsoft.Build.
- Move src/Shared/EncodingStringWriter.cs to Microsoft.Build
- Move src/Shared/ProjectWriter.cs to Microsoft.Build
- Move src/Shared/VersionUtilities.cs to Microsoft.Build.Framework
- Move src/Shared/StringUtils.cs to Microsoft.Build.Framework
- Move src/Shared/MetadataConversionUtilities.cs to Microsoft.Build.Framework
- Add "InvalidAttributeMetadata" string resource to src/Framework/SR.resx (copied from "General.InvalidAttributeMetadata"). Take care to copy translated strings to the correct .xlf file.
- Move src/Shared/FileMatcher.cs to Microsoft.Build.Framework
- Add "GlobExpansionFailed" string resource to src/Framework/SR.resx (copied from "Shared.GlobExpansionFailed"). Take care to copy translated strings to the correct .xlf file.
- Move src/Shared/XmlUtilities.cs to Microsoft.Build
- Move src/Shared/FileDelegates.cs to Microsoft.Build.Framework
- Move src/Shared/CollectionHelpers.cs to Microsoft.Build.Framework
- Move src/Shared/ThreadPoolExtensions.cs to Microsoft.Build.Framework
src/Shared/XamlUtilities.cs isn't compiled into any binary.
- Move src/Shared/ProcessExtensions.cs to Microsoft.Build.Framework
- Move src/Shared/QuotingUtilities.cs to Microsoft.Build.Framework
- Move src/Shared/EventArgsFormatting.cs to Microsoft.Build.Framework
- Move src/Shared/SolutionConfiguration.cs to Microsoft.Build.Framework
- Move src/Shared/ToolsetElement.cs to Microsoft.Build. This was compiled into Microsoft.Build.Utilities, but unused.
- Move src/Shared/StrongNameHelpers.cs to Microsoft.Build.Tasks.
- Move src/Shared/AssemblyNameComparer.cs to Microsoft.Build.Framework
- Move src/Shared/AssemblyNameExtension.cs to Microsoft.Build.Framework

These types are related and must be moved together.
- Move src/Shared/AssemblyNameReverseVersionComparer.cs to Microsoft.Build.Framework
- Move src/Shared/AssemblyLoadInfo.cs to Microsoft.Build.Framework
- Move src/Shared/AwaitExtensions.cs to Microsoft.Build.
- Move src/Shared/BuildEnvironmentHelper.cs to Microsoft.Build.Framework
- Audit all usages of BuildEnvironmentHelper.ExecutingAssemblyPath to use a different method. Add TypeExtensions.GetAssemblyPath(Type) extension method to make this a bit easier.
- Move src/Shared/TypeUtilities.cs to Microsoft.Build.Framework
- Move src/Build/Instance/ReflectableTaskPropertyInfo.cs to Microsoft.Build.Framework.
Move src/Shared/LoadedType.cs to Microsoft.Build.Framework
Move src/Shared/MSBuildLoadContext.cs to Microsoft.Build.Framework.
Move src/Shared/CoreClrAssemblyLoader.cs to Microsoft.Build.Framework.
- Move src/Shared/FrameworkLocationHelper.cs to Microsoft.Build.Framework
- Add "CouldNotGenerateReferenceAssemblyDirectory" string resource to src/Framework/SR.resx (copied from "FrameworkLocationHelper.CouldNotGenerateReferenceAssemblyDirectory").
- Add "UnsupportedFrameworkVersion" string resource to src/Framework/SR.resx (copied from "FrameworkLocationHelper.UnsupportedFrameworkVersion").
- Add "UnsupportedFrameworkVersionForWindowsSdk" string resource to src/Framework/SR.resx (copied from "FrameworkLocationHelper.UnsupportedFrameworkVersionForWindowsSdk").
- Add "UnsupportedVisualStudioVersion" string resource to src/Framework/SR.resx (copied from "FrameworkLocationHelper.UnsupportedVisualStudioVersion").

For all string resources, take care to copy translated strings to the correct .xlf file.
- Move src/Shared/UnitTests/CopyOnWriteDictionary_Tests.cs to Microsoft.Build.Framework.UnitTests
- Move src/Shared/UnitTests/FileMatcher_Tests.cs to Microsoft.Build.Framework.UnitTests
- Move src/Shared/UnitTests/XmlUtilities_Tests.cs to Microsoft.Build.Engine.UnitTests
@DustinCampbell DustinCampbell force-pushed the dev/dustinca/further-shared-file-work branch from 6806280 to 89f0524 Compare March 12, 2026 16:17
Copilot AI review requested due to automatic review settings March 12, 2026 16:17
Copy link
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 continues the ongoing effort to reduce duplicated “Shared” source by moving additional shared utilities/types into a single target binary (primarily Microsoft.Build.Framework) and updating downstream projects to consume them from there.

Changes:

  • Removes many ..\Shared\*.cs compile includes from Utilities/Tasks/MSBuild/Build projects and replaces them with Framework/Build-local equivalents.
  • Replaces BuildEnvironmentHelper.ExecutingAssemblyPath usage with a new TypeExtensions.GetAssemblyPath() helper.
  • Introduces/relocates several utility and collection types into src/Framework/** (and adds related resources/translations and some new unit tests).

Reviewed changes

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

Show a summary per file
File Description
src/Utilities/Microsoft.Build.Utilities.csproj Drops several shared source inclusions so Utilities relies more on Framework-shared code.
src/Utilities.UnitTests/Microsoft.Build.Utilities.UnitTests.csproj Removes direct compilation of Shared ConversionUtilities.
src/Tasks/ResolveComReference.cs Updates architecture enum usage to avoid type ambiguity after moves.
src/Tasks/Microsoft.Build.Tasks.csproj Removes many Shared compile includes and adds a Tasks-local StrongNameHelpers include.
src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj Removes direct compilation of Shared QuotingUtilities.
src/Shared/XamlUtilities.cs Deletes the Shared XAML utility file (presumably no longer used).
src/Shared/Debugging/PrintLineDebuggerWriters.cs Switches assembly-path derivation to GetAssemblyPath().
src/Shared/Debugging/DebugUtils.cs Removes MICROSOFT_BUILD_ENGINE_OM_UNITTESTS conditional around crash telemetry recording.
src/MSBuild/XMake.cs Switches exe path discovery to GetAssemblyPath().
src/MSBuild/MSBuild.csproj Removes many Shared compile includes so MSBuild consumes moved Framework/Build code.
src/MSBuild/CommandLine/CommandLineParser.cs Uses GetAssemblyPath() for response-file probing and minor formatting change.
src/MSBuild.UnitTests/Microsoft.Build.CommandLine.UnitTests.csproj Removes Shared includes (ProcessExtensions/VersionUtilities) from this unit test project.
src/Framework/Utilities/VersionUtilities.cs Adds VersionUtilities under Framework utilities (moved from Shared).
src/Framework/Utilities/TypeUtilities.cs Adds attribute-probing helpers under Framework utilities.
src/Framework/Utilities/TypeExtensions.cs Adds Type.GetAssemblyPath() helper used across the repo.
src/Framework/Utilities/ThreadPoolExtensions.cs Adds ThreadPool culture helper under Framework utilities (moved from Shared).
src/Framework/Utilities/TaskFactoryUtilities.cs Adds centralized task-factory helper utilities under Framework utilities.
src/Framework/Utilities/StringUtils.cs Adds string utility helpers under Framework utilities (moved from Shared).
src/Framework/Utilities/QuotingUtilities.cs Adjusts error utility usage to FrameworkErrorUtilities after move.
src/Framework/Utilities/ProcessExtensions.cs Adjusts OS detection to NativeMethods and updates imports after move.
src/Framework/Utilities/MetadataConversionUtilities.cs Switches error formatting to SR-generated formatting helper.
src/Framework/Utilities/FrameworkLocationHelper.cs Replaces some ErrorUtilities.* throws with explicit exceptions using SR strings; updates NativeMethods usage.
src/Framework/Utilities/FileMatcher.cs Switches internal error utilities to FrameworkErrorUtilities and SR formatting helpers.
src/Framework/Utilities/FileDelegates.cs Minor cleanup after move.
src/Framework/Utilities/EventArgsFormatting.cs Replaces null checks with ArgumentNullException.ThrowIfNull.
src/Framework/Utilities/ConversionUtilities.cs Moves away from Shared aliasing and uses SR + FrameworkErrorUtilities.
src/Framework/Utilities/CollectionHelpers.cs Adds CollectionHelpers under Framework utilities (moved from Shared).
src/Framework/Utilities/AssemblyNameReverseVersionComparer.cs Adds comparer under Framework utilities (moved from Shared).
src/Framework/Utilities/AssemblyNameExtension.cs Updates attributes and internal error utility usage after move.
src/Framework/Utilities/AssemblyNameComparer.cs Adds comparer under Framework utilities (moved from Shared).
src/Framework/Utilities/AssemblyLoadInfo.cs Updates internal error utility usage after move.
src/Framework/StringBuilderCache.cs Removes MICROSOFT_BUILD_ENGINE_OM_UNITTESTS from DEBUG eventing compilation guard.
src/Framework/SolutionConfiguration.cs Adds SolutionConfiguration under Framework (moved from Shared).
src/Framework/Resources/xlf/SR.zh-Hant.xlf Adds translations for new SR entries.
src/Framework/Resources/xlf/SR.zh-Hans.xlf Adds translations for new SR entries.
src/Framework/Resources/xlf/SR.tr.xlf Adds translations for new SR entries.
src/Framework/Resources/xlf/SR.ru.xlf Adds translations for new SR entries.
src/Framework/Resources/xlf/SR.pt-BR.xlf Adds translations for new SR entries.
src/Framework/Resources/xlf/SR.pl.xlf Adds translations for new SR entries.
src/Framework/Resources/xlf/SR.ko.xlf Adds translations for new SR entries.
src/Framework/Resources/xlf/SR.ja.xlf Adds translations for new SR entries.
src/Framework/Resources/xlf/SR.it.xlf Adds translations for new SR entries.
src/Framework/Resources/xlf/SR.fr.xlf Adds translations for new SR entries.
src/Framework/Resources/xlf/SR.es.xlf Adds translations for new SR entries.
src/Framework/Resources/xlf/SR.de.xlf Adds translations for new SR entries.
src/Framework/Resources/xlf/SR.cs.xlf Adds translations for new SR entries.
src/Framework/Resources/SR.resx Adds new resource strings used by moved/updated Framework code.
src/Framework/ReflectableTaskPropertyInfo.cs Replaces Shared ErrorUtilities usage with Framework equivalents and modern null checks.
src/Framework/NativeMethods.cs Removes MICROSOFT_BUILD_ENGINE_OM_UNITTESTS conditional in last-write-time logic.
src/Framework/Loader/MSBuildLoadContext.cs Wraps file in #if NET && FEATURE_ASSEMBLYLOADCONTEXT guard.
src/Framework/Loader/LoadedType.cs Switches internal checks to FrameworkErrorUtilities.
src/Framework/Loader/CoreCLRAssemblyLoader.cs Wraps file in #if NET && FEATURE_ASSEMBLYLOADCONTEXT guard.
src/Framework/ErrorUtilities.cs Adds a ThrowInternalError(string) overload to FrameworkErrorUtilities.
src/Framework/Collections/ReadOnlyEmptyDictionary.cs Switches read-only mutation exceptions to SR CollectionIsReadOnly and modernizes IEnumerable implementation.
src/Framework/Collections/ReadOnlyEmptyCollection.cs Switches read-only mutation exceptions to SR CollectionIsReadOnly and modernizes IEnumerable implementation.
src/Framework/Collections/ReadOnlyCollection.cs Switches to Framework error utilities and SR CollectionIsReadOnly; modernizes null checks.
src/Framework/Collections/CopyOnWriteDictionary.cs Introduces CopyOnWriteDictionary in Framework (moved/rewritten around ImmutableDictionary).
src/Framework/BuildEnvironmentHelper.cs Removes ExecutingAssemblyPath property and uses GetAssemblyPath() internally; updates NativeMethods usage.
src/Framework/BackEnd/TranslatorHelpers.cs Adds TranslatorHelpers into Framework backend utilities.
src/Framework/BackEnd/InterningBinaryReader.cs Switches internal error utility calls to Framework equivalents.
src/Framework/BackEnd/BufferedReadStream.cs Removes conditional compilation around async ReadAsync override.
src/Framework.UnitTests/FileUtilities_Tests.cs Updates test to use GetAssemblyPath() for system-specific path.
src/Framework.UnitTests/CopyOnWriteDictionary_Tests.cs Adds tests for CopyOnWriteDictionary behavior.
src/Build/Utilities/XmlUtilities.cs Adds/moves XmlUtilities into Build project under Microsoft.Build.Shared namespace.
src/Build/Utilities/ProjectWriter.cs Adds/moves ProjectWriter into Build project under Microsoft.Build.Shared namespace.
src/Build/Utilities/EncodingStringWriter.cs Adds/moves EncodingStringWriter into Build project under Microsoft.Build.Shared namespace.
src/Build/Utilities/AwaitExtensions.cs Adds/moves AwaitExtensions into Build project under Microsoft.Build.Shared namespace.
src/Build/Microsoft.Build.csproj Removes many Shared includes and adds new Build-local utilities and moved types.
src/Build/IElementLocation.cs Simplifies interface file using file-scoped namespace.
src/Build/Evaluation/ToolsetElement.cs Moves toolset configuration types into Build project.
src/Build/Definition/ProjectCollection.cs Switches version discovery to GetAssemblyPath().
src/Build/Collections/IKeyed.cs Adds/moves IKeyed into Build collections.
src/Build/AssemblyInfo.cs Adds InternalsVisibleTo for Microsoft.Build.Engine.OM.UnitTests.
src/Build.UnitTests/XmlUtilities_Tests.cs Adds unit test coverage for XmlUtilities element-name validation.
src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj Removes Shared unit test sources that were moved (e.g., XmlUtilities/FileMatcher/COW dictionary tests).
src/Build.UnitTests/BuildEnvironmentHelper_Tests.cs Switches test to GetAssemblyPath().
src/Build.UnitTests/BackEnd/SdkResolverLoader_Tests.cs Changes fallback path logic to use executing test assembly location.
src/Build.OM.UnitTests/Microsoft.Build.Engine.OM.UnitTests.csproj Removes Shared sources/constants import and cleans minor formatting.

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.

2 participants