Skip to content

Commit b7b9e95

Browse files
Centralize runtime version selection in Directory.Build.targets
Co-authored-by: Copilot <223556219+Copilot@users.noreply.github.com>
1 parent 71bcd22 commit b7b9e95

6 files changed

Lines changed: 49 additions & 43 deletions

File tree

eng/Versions.props

Lines changed: 5 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -69,23 +69,14 @@
6969
See the ReplaceRuntimeAssembliesWithServicingVersions target in src/Directory.Build.targets.
7070
This mirrors the $(UseFrozenMaintenancePackageVersions) mechanism in reverse (there we
7171
compile against an older build than we ship; here we ship a newer build than we compile).
72+
73+
These two versions are the single source of truth. src/Directory.Build.targets selects between
74+
them per project and assigns the individual System.* runtime package versions from the result;
75+
the selection lives there because it depends on $(IsUnitTestProject) and $(TargetFramework),
76+
which are not yet set this early.
7277
-->
7378
<RuntimePackageVersion_CompileTime>9.0.0</RuntimePackageVersion_CompileTime>
7479
<RuntimePackageVersion_VSDeploy>10.0.8</RuntimePackageVersion_VSDeploy>
75-
<SystemCollectionsImmutableVersion>$(RuntimePackageVersion_CompileTime)</SystemCollectionsImmutableVersion>
76-
<SystemConfigurationConfigurationManagerVersion>$(RuntimePackageVersion_CompileTime)</SystemConfigurationConfigurationManagerVersion>
77-
<SystemDiagnosticsDiagnosticSourceVersion>$(RuntimePackageVersion_CompileTime)</SystemDiagnosticsDiagnosticSourceVersion>
78-
<SystemDiagnosticsEventLogVersion>$(RuntimePackageVersion_CompileTime)</SystemDiagnosticsEventLogVersion>
79-
<SystemFormatsAsn1Version>$(RuntimePackageVersion_CompileTime)</SystemFormatsAsn1Version>
80-
<SystemFormatsNrbfVersion>$(RuntimePackageVersion_CompileTime)</SystemFormatsNrbfVersion>
81-
<SystemReflectionMetadataVersion>$(RuntimePackageVersion_CompileTime)</SystemReflectionMetadataVersion>
82-
<SystemReflectionMetadataLoadContextVersion>$(RuntimePackageVersion_CompileTime)</SystemReflectionMetadataLoadContextVersion>
83-
<SystemResourcesExtensionsVersion>$(RuntimePackageVersion_CompileTime)</SystemResourcesExtensionsVersion>
84-
<SystemSecurityCryptographyProtectedDataVersion>$(RuntimePackageVersion_CompileTime)</SystemSecurityCryptographyProtectedDataVersion>
85-
<SystemTextEncodingCodePagesVersion>$(RuntimePackageVersion_CompileTime)</SystemTextEncodingCodePagesVersion>
86-
<SystemTextJsonVersion>$(RuntimePackageVersion_CompileTime)</SystemTextJsonVersion>
87-
<SystemThreadingChannelsVersion>$(RuntimePackageVersion_CompileTime)</SystemThreadingChannelsVersion>
88-
<SystemThreadingTasksDataflowVersion>$(RuntimePackageVersion_CompileTime)</SystemThreadingTasksDataflowVersion>
8980
</PropertyGroup>
9081
<PropertyGroup>
9182
<!-- maintained in eng/dependabot/Packages.props -->

src/Build.UnitTests/Microsoft.Build.Engine.UnitTests.csproj

Lines changed: 0 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,6 @@
44
<TargetFrameworks>$(RuntimeOutputTargetFrameworks)</TargetFrameworks>
55
<PlatformTarget>$(RuntimeOutputPlatformTarget)</PlatformTarget>
66
<IsPackable>false</IsPackable>
7-
8-
<!-- This project bundles MSBuild.exe (via the MSBuild.csproj reference) and spawns it
9-
out-of-proc, so it is a net472 servicing-assembly redistribution surface just like
10-
MSBuild.csproj: deploy the servicing assemblies so the bundled MSBuild.exe and its
11-
servicing app.config binding redirects agree. See the
12-
ReplaceRuntimeAssembliesWithServicingVersions target in src/Directory.Build.targets. -->
13-
<DeployRuntimeServicingAssemblies>true</DeployRuntimeServicingAssemblies>
14-
157
<AssemblyName>Microsoft.Build.Engine.UnitTests</AssemblyName>
168

179
<DefineConstants>$(DefineConstants);MICROSOFT_BUILD_ENGINE_UNITTESTS</DefineConstants>

src/Directory.Build.targets

Lines changed: 44 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -158,6 +158,50 @@
158158
<PackageDownload Include="System.Numerics.Vectors" Version="[$(FrozenSystemNumericsVectorsVersion)]" />
159159
</ItemGroup>
160160

161+
<!--
162+
Select the dotnet/runtime build each project references. This selection lives here rather than in
163+
eng/Versions.props because it depends on $(IsUnitTestProject) and $(TargetFramework), which are
164+
not yet set when that file is imported.
165+
166+
Most projects reference $(RuntimePackageVersion_CompileTime) - the build MSBuild compiles against
167+
and declares as its own package dependencies. net472 unit-test projects load Microsoft.Build
168+
in-proc and run the redistributed MSBuild.exe, so they instead reference the servicing build the
169+
application projects redistribute (see $(DeployRuntimeServicingAssemblies) below):
170+
$(RuntimePackageVersion_VSDeploy). Referencing it flows the servicing versions through restore,
171+
keeping each test output directory self-consistent - the deployed assemblies, the generated
172+
test-host binding redirects, and the bundled MSBuild.exe.config all agree. net9.0 keeps the
173+
compile-time versions (the shared framework supplies these there).
174+
175+
Pinning only the leaf test projects higher does not cause an NU1109 downgrade, because their
176+
transitive providers (Microsoft.Build etc.) stay at $(RuntimePackageVersion_CompileTime).
177+
-->
178+
<PropertyGroup>
179+
<RuntimePackageVersion Condition="'$(IsUnitTestProject)' == 'true' and '$(TargetFramework)' == 'net472'">$(RuntimePackageVersion_VSDeploy)</RuntimePackageVersion>
180+
<RuntimePackageVersion Condition="'$(RuntimePackageVersion)' == ''">$(RuntimePackageVersion_CompileTime)</RuntimePackageVersion>
181+
182+
<SystemCollectionsImmutableVersion>$(RuntimePackageVersion)</SystemCollectionsImmutableVersion>
183+
<SystemConfigurationConfigurationManagerVersion>$(RuntimePackageVersion)</SystemConfigurationConfigurationManagerVersion>
184+
<SystemDiagnosticsDiagnosticSourceVersion>$(RuntimePackageVersion)</SystemDiagnosticsDiagnosticSourceVersion>
185+
<SystemDiagnosticsEventLogVersion>$(RuntimePackageVersion)</SystemDiagnosticsEventLogVersion>
186+
<SystemFormatsAsn1Version>$(RuntimePackageVersion)</SystemFormatsAsn1Version>
187+
<SystemFormatsNrbfVersion>$(RuntimePackageVersion)</SystemFormatsNrbfVersion>
188+
<SystemReflectionMetadataVersion>$(RuntimePackageVersion)</SystemReflectionMetadataVersion>
189+
<SystemReflectionMetadataLoadContextVersion>$(RuntimePackageVersion)</SystemReflectionMetadataLoadContextVersion>
190+
<SystemResourcesExtensionsVersion>$(RuntimePackageVersion)</SystemResourcesExtensionsVersion>
191+
<SystemSecurityCryptographyProtectedDataVersion>$(RuntimePackageVersion)</SystemSecurityCryptographyProtectedDataVersion>
192+
<SystemTextEncodingCodePagesVersion>$(RuntimePackageVersion)</SystemTextEncodingCodePagesVersion>
193+
<SystemTextJsonVersion>$(RuntimePackageVersion)</SystemTextJsonVersion>
194+
<SystemThreadingChannelsVersion>$(RuntimePackageVersion)</SystemThreadingChannelsVersion>
195+
<SystemThreadingTasksDataflowVersion>$(RuntimePackageVersion)</SystemThreadingTasksDataflowVersion>
196+
</PropertyGroup>
197+
198+
<!-- The net472 servicing wave binds to newer maintenance packages than the compile-time defaults in eng/Versions.props. -->
199+
<PropertyGroup Condition="'$(IsUnitTestProject)' == 'true' and '$(TargetFramework)' == 'net472'">
200+
<SystemMemoryVersion>4.6.3</SystemMemoryVersion>
201+
<SystemThreadingTasksExtensionsVersion>4.6.3</SystemThreadingTasksExtensionsVersion>
202+
<SystemRuntimeCompilerServicesUnsafeVersion>6.1.2</SystemRuntimeCompilerServicesUnsafeVersion>
203+
</PropertyGroup>
204+
161205
<!-- Work around maintenance-packages updates breaking stuff -->
162206
<Target Name="ReplaceCompileReferencesWithOlderMaintenancePackagesVersions"
163207
BeforeTargets="ResolveAssemblyReferences"

src/MSBuild.UnitTests/Microsoft.Build.CommandLine.UnitTests.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,13 +4,6 @@
44
<TargetFrameworks>$(RuntimeOutputTargetFrameworks)</TargetFrameworks>
55
<PlatformTarget>$(RuntimeOutputPlatformTarget)</PlatformTarget>
66
<IsPackable>false</IsPackable>
7-
8-
<!-- This project bundles MSBuild.exe (via the MSBuild.csproj reference) and spawns it
9-
out-of-proc, so it is a net472 servicing-assembly redistribution surface just like
10-
MSBuild.csproj: deploy the servicing assemblies so the bundled MSBuild.exe and its
11-
servicing app.config binding redirects agree. See the
12-
ReplaceRuntimeAssembliesWithServicingVersions target in src/Directory.Build.targets. -->
13-
<DeployRuntimeServicingAssemblies>true</DeployRuntimeServicingAssemblies>
147
</PropertyGroup>
158

169
<ItemGroup>

src/Tasks.UnitTests/Microsoft.Build.Tasks.UnitTests.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
<IsPackable>false</IsPackable>
77
<GenerateAssemblyInfo>false</GenerateAssemblyInfo>
88

9-
<!-- This project bundles MSBuild.exe (via the MSBuild.csproj reference) and spawns it
10-
out-of-proc, so it is a net472 servicing-assembly redistribution surface just like
11-
MSBuild.csproj: deploy the servicing assemblies so the bundled MSBuild.exe and its
12-
servicing app.config binding redirects agree. See the
13-
ReplaceRuntimeAssembliesWithServicingVersions target in src/Directory.Build.targets. -->
14-
<DeployRuntimeServicingAssemblies>true</DeployRuntimeServicingAssemblies>
15-
169
<AssemblyName>Microsoft.Build.Tasks.UnitTests</AssemblyName>
1710
<IsTestProject>true</IsTestProject>
1811
<DefineConstants>$(DefineConstants);MICROSOFT_BUILD_TASKS_UNITTESTS</DefineConstants>

src/Utilities.UnitTests/Microsoft.Build.Utilities.UnitTests.csproj

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,6 @@
66
<AssemblyName>Microsoft.Build.Utilities.UnitTests</AssemblyName>
77
<IsTestProject>true</IsTestProject>
88
<RootNamespace>Microsoft.Build.Utilities.UnitTests</RootNamespace>
9-
10-
<!-- This project bundles MSBuild.exe (via the MSBuild.csproj reference) and spawns it
11-
out-of-proc, so it is a net472 servicing-assembly redistribution surface just like
12-
MSBuild.csproj: deploy the servicing assemblies so the bundled MSBuild.exe and its
13-
servicing app.config binding redirects agree. See the
14-
ReplaceRuntimeAssembliesWithServicingVersions target in src/Directory.Build.targets. -->
15-
<DeployRuntimeServicingAssemblies>true</DeployRuntimeServicingAssemblies>
169
</PropertyGroup>
1710

1811
<ItemGroup>

0 commit comments

Comments
 (0)