[dotnet] Rework KnownFrameworkReference so that 'net6.0-*' TargetFrameworks work when building with .NET 7. Fixes #15375.

The KnownFrameworkReference now references the exact versions of the ref and runtime
packs we're shipping with the sdk pack, instead of telling the build to use whatever
version is defined in the workload.

Then in the workload we specify the latest released version of the .NET 6 for the
ref and runtime packs.

Finally we add an aliased sdk pack, which points to the .NET 6 sdk pack, and
when we're building a .NET 6 TargetFramework we load this aliased sdk pack
instead of the one we're shipping with this workload.

Putting this together means that:

* When we're building a .NET 7 TargetFramework, we load the sdk pack shipped
  with the workload, which adds a KnownFrameworkReference which references the
  ref and runtime packs with the same version as the sdk pack.
* When we're building a .NET 6 TargetFramework, we load the (aliased) sdk pack
  which points to the latest stable .NET 6 sdk pack. That sdk pack will add a
  KnownFrameworkReference that tells the build to use the ref and runtime pack
  versions specified in the workload - which are now pointing to the .NET 6
  ref and runtime pack versions.

Thus we use the .NET 6 sdk, ref and runtime packs when building a .NET 6
TargetFramework, and we use the .NET 7 sdk, ref and runtime packs when
building a .NET 7 TargetFramework.

According to the workload design spec [1], this is supposed to be implemented
by using aliased ref and runtime packs, but that doesn't work due to
https://github.com/dotnet/sdk/issues/26384.

Fixes https://github.com/xamarin/xamarin-macios/issues/15375.

[1]: https://github.com/dotnet/designs/blob/main/accepted/2020/workloads/workload-manifest.md?rgh-link-date=2022-06-30T08%3A25%3A10Z#side-by-side-workload-pattern
This commit is contained in:
Rolf Bjarne Kvinge 2022-06-30 13:04:04 +02:00 коммит произвёл vs-mobiletools-engineering-service2
Родитель d53009c562
Коммит ba64775ba7
8 изменённых файлов: 47 добавлений и 31 удалений

Просмотреть файл

@ -85,3 +85,10 @@ DEFAULT_TARGET_PLATFORM_VERSION_TVOS=15.4
DEFAULT_TARGET_PLATFORM_VERSION_WATCHOS=8.5 DEFAULT_TARGET_PLATFORM_VERSION_WATCHOS=8.5
DEFAULT_TARGET_PLATFORM_VERSION_MACOS=12.3 DEFAULT_TARGET_PLATFORM_VERSION_MACOS=12.3
DEFAULT_TARGET_PLATFORM_VERSION_MACCATALYST=15.4 DEFAULT_TARGET_PLATFORM_VERSION_MACCATALYST=15.4
# These variables must be updated whenever we release a new stable version into .NET 6
NET6_IOS_NUGET_VERSION_NO_METADATA=15.4.447
NET6_TVOS_NUGET_VERSION_NO_METADATA=15.4.447
NET6_WATCHOS_NUGET_VERSION_NO_METADATA=8.5.447
NET6_MACOS_NUGET_VERSION_NO_METADATA=12.3.447
NET6_MACCATALYST_NUGET_VERSION_NO_METADATA=15.4.447

Просмотреть файл

@ -12,6 +12,7 @@ DOTNET_PLATFORMS_UPPERCASE:=$(shell echo $(DOTNET_PLATFORMS) | tr a-z A-Z)
# Create variables prefixed with the correctly cased platform name from the upper-cased platform name. This makes some of the next sections somewhat simpler. # Create variables prefixed with the correctly cased platform name from the upper-cased platform name. This makes some of the next sections somewhat simpler.
$(foreach platform,$(DOTNET_PLATFORMS),$(eval $(platform)_NUGET_VERSION_NO_METADATA:=$($(shell echo $(platform) | tr a-z A-Z)_NUGET_VERSION_NO_METADATA))) $(foreach platform,$(DOTNET_PLATFORMS),$(eval $(platform)_NUGET_VERSION_NO_METADATA:=$($(shell echo $(platform) | tr a-z A-Z)_NUGET_VERSION_NO_METADATA)))
$(foreach platform,$(DOTNET_PLATFORMS),$(eval NET6_$(platform)_NUGET_VERSION_NO_METADATA:=$(NET6_$(shell echo $(platform) | tr a-z A-Z)_NUGET_VERSION_NO_METADATA)))
DOTNET_iOS_GLOBAL_USINGS=CoreGraphics Foundation UIKit DOTNET_iOS_GLOBAL_USINGS=CoreGraphics Foundation UIKit
DOTNET_tvOS_GLOBAL_USINGS=CoreGraphics Foundation UIKit DOTNET_tvOS_GLOBAL_USINGS=CoreGraphics Foundation UIKit
@ -104,13 +105,15 @@ targets/Microsoft.$(1).Sdk.Versions.props: targets/Microsoft.Sdk.Versions.templa
-e "s/@CURRENT_BRANCH@/$$(CURRENT_BRANCH_SED_ESCAPED)/g" \ -e "s/@CURRENT_BRANCH@/$$(CURRENT_BRANCH_SED_ESCAPED)/g" \
-e "s/@CURRENT_HASH_LONG@/$$(CURRENT_HASH_LONG)/g" \ -e "s/@CURRENT_HASH_LONG@/$$(CURRENT_HASH_LONG)/g" \
-e 's*@VALID_RUNTIME_IDENTIFIERS@*$(foreach rid,$(3),\n\t\t<_XamarinValidRuntimeIdentifier Include="$(rid)" Platform="$(1)" />)*' \ -e 's*@VALID_RUNTIME_IDENTIFIERS@*$(foreach rid,$(3),\n\t\t<_XamarinValidRuntimeIdentifier Include="$(rid)" Platform="$(1)" />)*' \
-e 's/@DOTNET_TFM@/$(DOTNET_TFM)/g' \
-e 's/@RUNTIME_PACK_RUNTIME_IDENTIFIERS@/$(4)/g' \
$$< > $$@.tmp $$< > $$@.tmp
$$(Q) mv $$@.tmp $$@ $$(Q) mv $$@.tmp $$@
Microsoft.$1.Sdk/targets/Microsoft.$1.Sdk.Versions.props: targets/Microsoft.$1.Sdk.Versions.props Microsoft.$1.Sdk/targets/Microsoft.$1.Sdk.Versions.props: targets/Microsoft.$1.Sdk.Versions.props
$$(Q) $$(CP) $$< $$@ $$(Q) $$(CP) $$< $$@
endef endef
$(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call VersionsTemplate,$(platform),$(shell echo $(platform) | tr a-z A-Z),$(DOTNET_$(shell echo $(platform) | tr a-z A-Z)_RUNTIME_IDENTIFIERS)))) $(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call VersionsTemplate,$(platform),$(shell echo $(platform) | tr a-z A-Z),$(DOTNET_$(shell echo $(platform) | tr a-z A-Z)_RUNTIME_IDENTIFIERS),$(shell echo $(DOTNET_$(shell echo $(platform) | tr a-z A-Z)_RUNTIME_IDENTIFIERS) | tr ' ' ';'))))
define AutoImports define AutoImports
Microsoft.$(1).Sdk/Sdk/AutoImport.props: targets/AutoImport.template.props Makefile Microsoft.$(1).Sdk/Sdk/AutoImport.props: targets/AutoImport.template.props Makefile
@ -154,6 +157,7 @@ Workloads/Microsoft.NET.Sdk.$(1)/WorkloadManifest.json: targets/WorkloadManifest
$$(Q) rm -f $$@.tmp $$(Q) rm -f $$@.tmp
$$(Q_GEN) sed \ $$(Q_GEN) sed \
-e "s/@VERSION@/$3/g" \ -e "s/@VERSION@/$3/g" \
-e "s/@NET6_VERSION@/$(4)/g" \
-e "s/@BUNDLED_NETCORE_PLATFORMS_PACKAGE_VERSION@/$(BUNDLED_NETCORE_PLATFORMS_PACKAGE_VERSION)/g" \ -e "s/@BUNDLED_NETCORE_PLATFORMS_PACKAGE_VERSION@/$(BUNDLED_NETCORE_PLATFORMS_PACKAGE_VERSION)/g" \
-e "s/@PLATFORM_LOWERCASE@/$2/g" \ -e "s/@PLATFORM_LOWERCASE@/$2/g" \
-e "s/@PLATFORM@/$1/g" \ -e "s/@PLATFORM@/$1/g" \
@ -169,7 +173,7 @@ WORKLOAD_TARGETS += Workloads/Microsoft.NET.Sdk.$(1)/LICENSE
LOCAL_WORKLOAD_TARGETS += Workloads/Microsoft.NET.Sdk.$(1)/WorkloadManifest.json LOCAL_WORKLOAD_TARGETS += Workloads/Microsoft.NET.Sdk.$(1)/WorkloadManifest.json
LOCAL_WORKLOAD_TARGETS += Workloads/Microsoft.NET.Sdk.$(1)/LICENSE LOCAL_WORKLOAD_TARGETS += Workloads/Microsoft.NET.Sdk.$(1)/LICENSE
endef endef
$(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call WorkloadTargets,$(platform),$(shell echo $(platform) | tr A-Z a-z),$($(platform)_NUGET_VERSION_NO_METADATA)))) $(foreach platform,$(DOTNET_PLATFORMS),$(eval $(call WorkloadTargets,$(platform),$(shell echo $(platform) | tr A-Z a-z),$($(platform)_NUGET_VERSION_NO_METADATA),$(NET6_$(platform)_NUGET_VERSION_NO_METADATA))))
$(DOTNET_NUPKG_DIR)/vs-workload.props: Workloads/vs-workload.template.props $(DOTNET_NUPKG_DIR)/vs-workload.props: Workloads/vs-workload.template.props
$(Q) rm -f $@.tmp $(Q) rm -f $@.tmp

Просмотреть файл

@ -1,5 +1,8 @@
<Project> <Project>
<Import Project="Sdk.props" Sdk="Microsoft.MacCatalyst.Sdk" Condition="'$(TargetPlatformIdentifier)' == 'MacCatalyst'" /> <ImportGroup Condition=" '$(TargetPlatformIdentifier)' == 'MacCatalyst' ">
<Import Project="Sdk.props" Sdk="Microsoft.$(TargetPlatformIdentifier).Sdk.net7" Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '7.0')) " />
<Import Project="Sdk.props" Sdk="Microsoft.$(TargetPlatformIdentifier).Sdk.net6" Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '6.0')) " />
</ImportGroup>
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0')) "> <ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0')) ">
<SdkSupportedTargetPlatformIdentifier Include="maccatalyst" DisplayName="Mac Catalyst" /> <SdkSupportedTargetPlatformIdentifier Include="maccatalyst" DisplayName="Mac Catalyst" />

Просмотреть файл

@ -1,6 +1,10 @@
<Project> <Project>
<Import Project="Sdk.props" Sdk="Microsoft.iOS.Sdk" Condition="'$(TargetPlatformIdentifier)' == 'iOS'" /> <ImportGroup Condition=" '$(TargetPlatformIdentifier)' == 'iOS' ">
<Import Project="Sdk.props" Sdk="Microsoft.iOS.Windows.Sdk.Aliased" Condition=" '$(TargetPlatformIdentifier)' == 'iOS' and $([MSBuild]::IsOSPlatform('windows'))" /> <Import Project="Sdk.props" Sdk="Microsoft.$(TargetPlatformIdentifier).Sdk.net7" Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '7.0')) " />
<Import Project="Sdk.props" Sdk="Microsoft.$(TargetPlatformIdentifier).Sdk.net6" Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '6.0')) " />
<Import Project="Sdk.props" Sdk="Microsoft.$(TargetPlatformIdentifier).Windows.Sdk.Aliased.net7" Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '7.0')) And $([MSBuild]::IsOSPlatform('windows'))" />
<Import Project="Sdk.props" Sdk="Microsoft.$(TargetPlatformIdentifier).Windows.Sdk.Aliased.net6" Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '6.0')) And $([MSBuild]::IsOSPlatform('windows'))" />
</ImportGroup>
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0')) "> <ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0')) ">
<SdkSupportedTargetPlatformIdentifier Include="ios" DisplayName="iOS" /> <SdkSupportedTargetPlatformIdentifier Include="ios" DisplayName="iOS" />

Просмотреть файл

@ -1,5 +1,8 @@
<Project> <Project>
<Import Project="Sdk.props" Sdk="Microsoft.macOS.Sdk" Condition="'$(TargetPlatformIdentifier)' == 'macOS'" /> <ImportGroup Condition=" '$(TargetPlatformIdentifier)' == 'macOS' ">
<Import Project="Sdk.props" Sdk="Microsoft.$(TargetPlatformIdentifier).Sdk.net7" Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '7.0')) " />
<Import Project="Sdk.props" Sdk="Microsoft.$(TargetPlatformIdentifier).Sdk.net6" Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '6.0')) " />
</ImportGroup>
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0')) "> <ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0')) ">
<SdkSupportedTargetPlatformIdentifier Include="macos" DisplayName="macOS" /> <SdkSupportedTargetPlatformIdentifier Include="macos" DisplayName="macOS" />

Просмотреть файл

@ -1,5 +1,8 @@
<Project> <Project>
<Import Project="Sdk.props" Sdk="Microsoft.tvOS.Sdk" Condition="'$(TargetPlatformIdentifier)' == 'tvOS'" /> <ImportGroup Condition=" '$(TargetPlatformIdentifier)' == 'tvOS' ">
<Import Project="Sdk.props" Sdk="Microsoft.$(TargetPlatformIdentifier).Sdk.net7" Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '7.0')) " />
<Import Project="Sdk.props" Sdk="Microsoft.$(TargetPlatformIdentifier).Sdk.net6" Condition=" $([MSBuild]::VersionEquals($(TargetFrameworkVersion), '6.0')) " />
</ImportGroup>
<ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0')) "> <ItemGroup Condition=" '$(TargetFrameworkIdentifier)' == '.NETCoreApp' and $([MSBuild]::VersionGreaterThanOrEquals($(TargetFrameworkVersion), '6.0')) ">
<SdkSupportedTargetPlatformIdentifier Include="tvos" DisplayName="tvOS" /> <SdkSupportedTargetPlatformIdentifier Include="tvos" DisplayName="tvOS" />

Просмотреть файл

@ -11,4 +11,20 @@
<ItemGroup>@VALID_RUNTIME_IDENTIFIERS@ <ItemGroup>@VALID_RUNTIME_IDENTIFIERS@
</ItemGroup> </ItemGroup>
<!-- Declare the XI/XM framework bundled with this version of the SDK. See Microsoft.NETCoreSdk.BundledVersions.props -->
<ItemGroup>
<KnownFrameworkReference
Include="Microsoft.@PLATFORM@"
TargetFramework="@DOTNET_TFM@"
RuntimeFrameworkName="Microsoft.@PLATFORM@"
DefaultRuntimeFrameworkVersion="@NUGET_VERSION_NO_METADATA@"
LatestRuntimeFrameworkVersion="@NUGET_VERSION_NO_METADATA@"
TargetingPackName="Microsoft.@PLATFORM@.Ref"
TargetingPackVersion="@NUGET_VERSION_NO_METADATA@"
RuntimePackNamePatterns="Microsoft.@PLATFORM@.Runtime.**RID**"
RuntimePackRuntimeIdentifiers="@RUNTIME_PACK_RUNTIME_IDENTIFIERS@"
Profile="@PLATFORM@"
/>
</ItemGroup>
</Project> </Project>

Просмотреть файл

@ -76,35 +76,11 @@
<ComputedPlatform Condition="'$(ComputedPlatform)' == ''">iPhone</ComputedPlatform> <ComputedPlatform Condition="'$(ComputedPlatform)' == ''">iPhone</ComputedPlatform>
</PropertyGroup> </PropertyGroup>
<!-- Declare the XI/XM framework bundled with this version of the SDK. See Microsoft.NETCoreSdk.BundledVersions.props -->
<PropertyGroup>
<!-- Runtime pack identifiers -->
<_RuntimePackRuntimeIdentifiers Condition=" '$(_PlatformName)' == 'iOS' ">iossimulator-x64;ios-arm64;ios-arm;iossimulator-x86;iossimulator-arm64</_RuntimePackRuntimeIdentifiers>
<_RuntimePackRuntimeIdentifiers Condition=" '$(_PlatformName)' == 'tvOS' ">tvossimulator-x64;tvos-arm64;tvossimulator-arm64</_RuntimePackRuntimeIdentifiers>
<_RuntimePackRuntimeIdentifiers Condition=" '$(_PlatformName)' == 'watchOS' ">watchos-x86;watchos-x64;watchos-arm</_RuntimePackRuntimeIdentifiers>
<_RuntimePackRuntimeIdentifiers Condition=" '$(_PlatformName)' == 'macOS' ">osx-x64;osx-arm64</_RuntimePackRuntimeIdentifiers>
<_RuntimePackRuntimeIdentifiers Condition=" '$(_PlatformName)' == 'MacCatalyst' ">maccatalyst-x64;maccatalyst-arm64</_RuntimePackRuntimeIdentifiers>
</PropertyGroup>
<PropertyGroup> <PropertyGroup>
<_RuntimeFrameworkVersion>$(BundledNETCorePlatformsPackageVersion)</_RuntimeFrameworkVersion> <_RuntimeFrameworkVersion>$(BundledNETCorePlatformsPackageVersion)</_RuntimeFrameworkVersion>
<_RuntimeFrameworkVersion Condition="'$(CUSTOM_DOTNET_VERSION)' != ''">$(CUSTOM_DOTNET_VERSION)</_RuntimeFrameworkVersion> <_RuntimeFrameworkVersion Condition="'$(CUSTOM_DOTNET_VERSION)' != ''">$(CUSTOM_DOTNET_VERSION)</_RuntimeFrameworkVersion>
</PropertyGroup> </PropertyGroup>
<ItemGroup>
<KnownFrameworkReference Include="Microsoft.$(_PlatformName)"
TargetFramework="net7.0"
RuntimeFrameworkName="Microsoft.$(_PlatformName)"
DefaultRuntimeFrameworkVersion="**FromWorkload**"
LatestRuntimeFrameworkVersion="**FromWorkload**"
TargetingPackName="Microsoft.$(_PlatformName).Ref"
TargetingPackVersion="**FromWorkload**"
RuntimePackNamePatterns="Microsoft.$(_PlatformName).Runtime.**RID**"
RuntimePackRuntimeIdentifiers="$(_RuntimePackRuntimeIdentifiers)"
Profile="$(_PlatformName)"
/>
</ItemGroup>
<ItemGroup Condition="'$(DisableImplicitFrameworkReferences)' != 'true'"> <ItemGroup Condition="'$(DisableImplicitFrameworkReferences)' != 'true'">
<FrameworkReference Include="Microsoft.$(_PlatformName)" IsImplicitlyDefined="true" Pack="false" PrivateAssets="All" /> <FrameworkReference Include="Microsoft.$(_PlatformName)" IsImplicitlyDefined="true" Pack="false" PrivateAssets="All" />
</ItemGroup> </ItemGroup>