Skip to content

Commit e68114a

Browse files
JanProvaznikCopilot
andcommitted
Scope MSBuild.exe.config realign to test projects via opt-in
Previously the realign target ran for any net472 project without DeployRuntimeServicingAssemblies, which also matched non-test projects that bundle MSBuild.exe for shipping (e.g. the VS.ExternalAPIs.MSBuild / DevDivPackage insertion package). It was harmless today only because that nuspec does not ship MSBuild.exe.config. Make it an explicit opt-in ($(RealignBundledMSBuildExeConfig)) defaulted on only for $(IsTestProject) == 'true', so the copied config is realigned exclusively in test bins and shipping/insertion projects are never touched. Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 5e4d30c commit e68114a

1 file changed

Lines changed: 23 additions & 13 deletions

File tree

src/Directory.Build.targets

Lines changed: 23 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -299,19 +299,29 @@
299299
<!--
300300
The net472 servicing redistribution above swaps DLLs and updates the binding redirects only in
301301
the projects that opt in ($(DeployRuntimeServicingAssemblies) == 'true': MSBuild.exe and the
302-
bootstrap). Other net472 projects that re-bundle MSBuild.exe (the test projects that spawn it
303-
out-of-proc, e.g. via ProjectReference to MSBuild.csproj) copy MSBuild.exe.config (which now
304-
carries the servicing redirects) but resolve their own copy-local runtime assemblies at the
305-
compiled-against versions. That leaves MSBuild.exe.config pointing at servicing versions
306-
(e.g. System.Memory 4.0.5.0) while the assembly on disk is the compiled-against one
307-
(4.0.2.0), so the copied MSBuild.exe fails to start with a FileLoadException, breaking every
308-
out-of-proc test (and hanging tests that wait on a spawned node/server).
309-
310-
These bins are not a VS redistribution surface, so the fix is to keep them self-consistent at
311-
the compiled-against versions: realign the copied MSBuild.exe.config binding redirects to the
312-
runtime assemblies actually next to it. Deploy surfaces are excluded; their DLLs already are
313-
the servicing build, so realigning would be a no-op there anyway.
302+
bootstrap). Test projects that re-bundle MSBuild.exe (they spawn it out-of-proc, e.g. via
303+
ProjectReference to MSBuild.csproj) copy MSBuild.exe.config (which now carries the servicing
304+
redirects) but resolve their own copy-local runtime assemblies at the compiled-against
305+
versions. That leaves MSBuild.exe.config pointing at servicing versions (e.g. System.Memory
306+
4.0.5.0) while the assembly on disk is the compiled-against one (4.0.2.0), so the copied
307+
MSBuild.exe fails to start with a FileLoadException, breaking every out-of-proc test (and
308+
hanging tests that wait on a spawned node/server).
309+
310+
These test bins are not a VS redistribution surface, so the fix is to keep them self-consistent
311+
at the compiled-against versions: realign the copied MSBuild.exe.config binding redirects to the
312+
runtime assemblies actually next to it.
313+
314+
This is scoped to test projects only ($(RealignBundledMSBuildExeConfig), defaulted on for
315+
$(IsTestProject) == 'true') and deliberately NOT keyed on the absence of
316+
$(DeployRuntimeServicingAssemblies): non-test projects that bundle MSBuild.exe for shipping
317+
(e.g. the VS.ExternalAPIs.MSBuild insertion package) must never have their copied config
318+
rewritten to the compiled-against versions, even though they happen not to ship MSBuild.exe.config
319+
today.
314320
-->
321+
<PropertyGroup>
322+
<RealignBundledMSBuildExeConfig Condition="'$(RealignBundledMSBuildExeConfig)' == '' and '$(IsTestProject)' == 'true'">true</RealignBundledMSBuildExeConfig>
323+
</PropertyGroup>
324+
315325
<UsingTask TaskName="AlignBindingRedirectsToOutputAssemblies"
316326
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll"
317327
TaskFactory="RoslynCodeTaskFactory">
@@ -388,7 +398,7 @@
388398

389399
<Target Name="AlignCopiedMSBuildExeConfigBindingRedirects"
390400
AfterTargets="Build"
391-
Condition="'$(TargetFramework)' == 'net472' and '$(DeployRuntimeServicingAssemblies)' != 'true'">
401+
Condition="'$(TargetFramework)' == 'net472' and '$(RealignBundledMSBuildExeConfig)' == 'true'">
392402
<ItemGroup>
393403
<_CopiedMSBuildExeConfig Include="$(TargetDir)**\MSBuild.exe.config" />
394404
</ItemGroup>

0 commit comments

Comments
 (0)