Pinned the .NET runtime to the version in metadata.txt (#1221)

This commit is contained in:
Thorsten Sommer authored and GitHub committed 2026-11-23 10:30:50 +01:00
1 parent 37e6161ccc
commit b6d614d96a
2 files changed
+32 -3

No files matched your search

@@ -54,6 +54,30 @@
<RequiresAspNetWebAssets>true</RequiresAspNetWebAssets>
</PropertyGroup>
<!--
The published app brings the .NET runtime which line 5 of metadata.txt names, whatever SDK builds it.
Without a fixed version, the SDK takes the runtime it knows itself, and a build with an older SDK would
ship an older runtime than our other builds. The Flatpak is such a build: its SDK extension on Flathub
may lag behind for months. The version fixes the runtime packs, the app hosts, the trimmer, and the
package with the script of Blazor alike. The restore downloads these packages, so the version has to be
known while MSBuild evaluates the project; the target ReadMetaData runs too late for that, and it only
checks the version.
-->
<PropertyGroup>
<MetaDotnetRuntimeVersion Condition="Exists('$(MSBuildThisFileDirectory)../../metadata.txt')">$([System.Text.RegularExpressions.Regex]::Split($([System.IO.File]::ReadAllText('$(MSBuildThisFileDirectory)../../metadata.txt')), '\r?\n')[4].Split(' ')[0])</MetaDotnetRuntimeVersion>
<RuntimeFrameworkVersion>$(MetaDotnetRuntimeVersion)</RuntimeFrameworkVersion>
</PropertyGroup>
<!--
The trimmer is a .NET program of its own, which runs on the runtime of the SDK and needs a runtime at
least as new as itself. An SDK older than the pinned runtime, such as the one of the Flatpak, could not
start the trimmer of the pinned version. Then the trimmer of that SDK does the work. It ships with
nothing, so the app still brings the pinned runtime.
-->
<ItemGroup Condition="'$(MetaDotnetRuntimeVersion)' != '' And $([MSBuild]::VersionLessThan('$(BundledNETCoreAppPackageVersion)', '$(MetaDotnetRuntimeVersion)'))">
<PackageReference Include="Microsoft.NET.ILLink.Tasks" Version="$(BundledNETCoreAppPackageVersion)" PrivateAssets="all" />
</ItemGroup>
<Import Project="..\Trimming.props" />
<ItemGroup>
@@ -125,7 +149,10 @@
<!-- Read the meta data file -->
<Target Name="ReadMetaData" BeforeTargets="BeforeBuild">
<Error Text="The ../../metadata.txt file was not found!" Condition="!Exists('../../metadata.txt')" />
<!-- Without this check, a broken line 5 would let the SDK pick the runtime by itself, without a word: -->
<Error Text="Line 5 of ../../metadata.txt names no .NET runtime, such as '10.0.15 (commit 8e0f8ed231)', but '$(MetaDotnetRuntimeVersion)'. The build ships the runtime which this line names, see RuntimeFrameworkVersion." Condition="!$([System.Text.RegularExpressions.Regex]::IsMatch('$(MetaDotnetRuntimeVersion)', '^\d+\.\d+\.\d+$'))" />
<ReadLinesFromFile File="../../metadata.txt">
<Output TaskParameter="Lines" PropertyName="Metadata" />
</ReadLinesFromFile>
@@ -133,8 +160,9 @@
<!--
metadata.txt names the .NET SDK which the pipeline pins, but a local build may use another
one. Hence, we take the SDK which builds right now. Its .version file starts with the commit
it was built from. The .NET runtime is not recorded at all: the app asks for it while it runs.
Neither is the Rust compiler, which the app learns from the runtime it built.
it was built from. The .NET runtime is not recorded here: the app asks for it while it runs, and
RuntimeFrameworkVersion above makes it the one in metadata.txt. Neither is the Rust compiler,
which the app learns from the runtime it built.
-->
<PropertyGroup>
<DotnetSdkVersionFile>$(NetCoreRoot)sdk/$(NETCoreSdkVersion)/.version</DotnetSdkVersionFile>