Generate a props file that can be used to detect MSBuild version mismatches.

We know the minimum and 'bundled' MSbuild versions, but users may build a project with newer SDKs than we expected (specifically when full-framework MSBuild is starting the build of an SDK-style project).
When this occurs, we'd like to automatically condition the use of PackageReferences meant to ensure compatibility of the Roslyn toolchain, so we need to know if we are in this mismatched situation.
A fast and simple way to do this is to 'stamp' the 'expected' version
of MSBuild during product construction and compare that to the
'current' version being used during the actual build.
This commit is contained in:
Chet Husk 2024-03-22 11:43:18 -05:00 committed by github-actions
parent 0597a03186
commit 79c1c4cc9a

View file

@ -2,7 +2,7 @@
<Target Name="GenerateBundledVersions"
Condition="'$(PgoInstrument)' != 'true'"
DependsOnTargets="GenerateBundledVersionsProps;GenerateBundledCliToolsProps" >
DependsOnTargets="GenerateBundledVersionsProps;GenerateBundledCliToolsProps;GenerateBundledMSBuildProps" >
<WriteLinesToFile
File="$(ArtifactsShippingPackagesDir)productVersion.txt"
@ -1205,6 +1205,52 @@ Copyright (c) .NET Foundation. All rights reserved.
Overwrite="true" />
</Target>
<Target Name="GenerateBundledMSBuildProps" DependsOnTargets="SetupBundledComponents">
<PropertyGroup>
<BundledMSBuildPropsFileName>Microsoft.NETCoreSdk.BundledMSBuildInformation.props</BundledMSBuildPropsFileName>
<MinimumMSBuildVersionFile Condition="$([System.Text.RegularExpressions.Regex]::Match(%(SDKInternalFiles.Identity),'.*minimumMSBuildVersion').Success) ">%(SDKInternalFiles.Identity)</MinimumMSBuildVersionFile>
<BundledMSBuildVersion>$(MSBuildVersion)</BundledMSBuildVersion>
</PropertyGroup>
<ReadLinesFromFile File="$(MinimumMSBuildVersionFile)">
<Output TaskParameter="Lines" PropertyName="MinimumMSBuildVersion"/>
</ReadLinesFromFile>
<PropertyGroup>
<_BundledMSBuildVersionMajorMinor>$([System.Version]::Parse('$(BundledMSBuildVersion)').ToString(2))</_BundledMSBuildVersionMajorMinor>
</PropertyGroup>
<PropertyGroup>
<BundledMSBuildPropsFileContent>
<![CDATA[
<!--
***********************************************************************************************
$(BundledMSBuildPropsFileName)
WARNING: DO NOT MODIFY this file unless you are knowledgeable about MSBuild and have
created a backup copy. Incorrect changes to this file will make it
impossible to load or build your projects from the command-line or the IDE.
Copyright (c) .NET Foundation. All rights reserved.
***********************************************************************************************
-->
<Project>
<PropertyGroup>
<MinimumMSBuildVersion>$(MinimumMSBuildVersion)</MinimumMSBuildVersion>
<BundledMSBuildVersion>$(BundledMSBuildVersion)</BundledMSBuildVersion>
<_MSBuildVersionMajorMinor>%24([System.Version]::Parse('%24(MSBuildVersion)').ToString(2))</_MSBuildVersionMajorMinor>
<_IsDisjointMSBuildVersion>%24([MSBuild]::VersionGreaterThan('%24(_MSBuildVersionMajorMinor)', '$(_BundledMSBuildVersionMajorMinor)'))</_IsDisjointMSBuildVersion>
</PropertyGroup>
</Project>
]]>
</BundledMSBuildPropsFileContent>
</PropertyGroup>
<WriteLinesToFile File="$(SdkOutputDirectory)$(BundledMSBuildPropsFileName)"
Lines="$(BundledMSBuildPropsFileContent)"
Overwrite="true" />
</Target>
<ItemGroup>
<PackageDownload Include="Microsoft.NETCore.Platforms" Version="[$(MicrosoftNETCorePlatformsPackageVersion)]" />
</ItemGroup>