1+ <Project >
2+
3+ <PropertyGroup >
4+
5+ <!-- Verification of the Windows SDK package version is enabled by default-->
6+ <MvvmToolkitEnableWindowsSdkPackageVersionValidation Condition =" '$(MvvmToolkitEnableWindowsSdkPackageVersionValidation)' == ''" >true</MvvmToolkitEnableWindowsSdkPackageVersionValidation >
7+
8+ <!--
9+ Wired up the Windows SDK package version verification target, if enabled.
10+ This only applies to TFMs targeting Windows 10 or later.
11+ -->
12+ <ResolveReferencesDependsOn Condition =" '$(MSBuildProjectExtension)' == '.csproj' AND
13+ '$(MvvmToolkitVerifyWindowsSdkPackageVersion)' != 'false' AND
14+ '$(MvvmToolkitEnableWindowsSdkPackageVersionValidation)' != 'false' AND
15+ $([MSBuild]::IsTargetFrameworkCompatible('$(TargetFramework)', 'net8.0-windows10.0.17763.0'))" >
16+ $(ResolveReferencesDependsOn);MvvmToolkitVerifyWindowsSdkPackageVersion
17+ </ResolveReferencesDependsOn >
18+ </PropertyGroup >
19+
20+ <!-- Custom target to verify the Windows SDK package version -->
21+ <Target Name =" MvvmToolkitVerifyWindowsSdkPackageVersion" DependsOnTargets =" ResolveAssemblyReferences" >
22+ <PropertyGroup >
23+
24+ <!-- The minimum build version for the Windows SDK package -->
25+ <_MvvmToolkitWindowsSdkPackageMinBuild >41</_MvvmToolkitWindowsSdkPackageMinBuild >
26+ </PropertyGroup >
27+ <ItemGroup >
28+
29+ <!-- If 'WindowsSdkPackageVersion' is explicitly set, validate against that -->
30+ <_MvvmToolkitWindowsSdkPackage Include =" $(WindowsSdkPackageVersion)" Condition =" '$(WindowsSdkPackageVersion)' != ''" >
31+ <Referenced >$(WindowsSdkPackageVersion)</Referenced >
32+ <Required >10.0.$([System.Version]::Parse("$(WindowsSdkPackageVersion.Split('-')[0])").Build).$(_MvvmToolkitWindowsSdkPackageMinBuild)</Required >
33+ </_MvvmToolkitWindowsSdkPackage >
34+
35+ <!-- Otherwise, validate against the framework reference package -->
36+ <_MvvmToolkitWindowsSdkPackage
37+ Include =" @(ResolvedFrameworkReference)"
38+ Condition =" '$(WindowsSdkPackageVersion)' == '' AND '@(ResolvedFrameworkReference)' != '' AND '%(Identity)' == 'Microsoft.Windows.SDK.NET.Ref'" >
39+ <Referenced >%(ResolvedFrameworkReference.TargetingPackVersion)</Referenced >
40+ <Required >10.0.$([System.Version]::Parse("%(ResolvedFrameworkReference.TargetingPackVersion)").Build).$(_MvvmToolkitWindowsSdkPackageMinBuild)</Required >
41+ </_MvvmToolkitWindowsSdkPackage >
42+
43+ <!-- Check whether the referenced Windows SDK package is compatible -->
44+ <_MvvmToolkitCompatibleWindowsSdkPackages
45+ Include =" @(_MvvmToolkitWindowsSdkPackage)"
46+ Condition =" '@(_MvvmToolkitWindowsSdkPackage)' != '' AND $([MSBuild]::VersionGreaterThanOrEquals(%(Referenced), %(Required)))" />
47+ </ItemGroup >
48+ <PropertyGroup >
49+
50+ <!-- Extract the required Windows SDK package version (to show if the one in use is not compatible) -->
51+ <_MvvmToolkitWindowsSdkPackageRequired >@(_MvvmToolkitWindowsSdkPackage->'%(Required)')</_MvvmToolkitWindowsSdkPackageRequired >
52+ </PropertyGroup >
53+
54+ <!-- Emit an error if the Windows SDK package version isn't valid -->
55+ <Error
56+ Condition =" '@(_MvvmToolkitCompatibleWindowsSdkPackages)' == ''"
57+ Code =" MVVMTKCFG0003"
58+ HelpLink =" https://aka.ms/mvvmtoolkit/errors/mvvmtkcfg0003"
59+ Text =" This version of the MVVM Toolkit requires 'Microsoft.Windows.SDK.NET.Ref' version '$(_MvvmToolkitWindowsSdkPackageRequired)' or later. Please update to .NET SDK 8.0.109, 8.0.305 or 8.0.402 (or later). Alternatively, use a temporary 'Microsoft.Windows.SDK.NET.Ref' reference, which can be done by setting the 'WindowsSdkPackageVersion' property in your .csproj file to '$(_MvvmToolkitWindowsSdkPackageRequired)'." />
60+ </Target >
61+
62+ </Project >
0 commit comments