Skip to content

Commit ea5741d

Browse files
committed
Fix the Android/iOS/Mac Catalyst/macOS workloads detection logic
1 parent 996ffee commit ea5741d

File tree

1 file changed

+28
-30
lines changed

1 file changed

+28
-30
lines changed

Directory.Build.props

Lines changed: 28 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -33,52 +33,50 @@
3333
<PublicKeyToken>35a561290d20de2f</PublicKeyToken>
3434
</PropertyGroup>
3535

36+
<PropertyGroup Condition=" '$(DotNetRoot)' == '' ">
37+
<DotNetRoot Condition=" '$(DOTNET_HOST_PATH)' != '' ">$([System.IO.Path]::GetDirectoryName($(DOTNET_HOST_PATH)))</DotNetRoot>
38+
<DotNetRoot Condition=" '$(MSBuildRuntimeType)' != 'Core' ">$(ProgramFiles)\dotnet</DotNetRoot>
39+
</PropertyGroup>
40+
41+
<ItemGroup Condition=" '$(DotNetRoot)' != '' ">
42+
<AndroidPackFolders Include="$(DotNetRoot)\packs\Microsoft.Android.Ref*" />
43+
<IOSPackFolders Include="$(DotNetRoot)\packs\Microsoft.iOS.Ref*" />
44+
<MacCatalystPackFolders Include="$(DotNetRoot)\packs\Microsoft.MacCatalyst.Ref*" />
45+
<MacOSPackFolders Include="$(DotNetRoot)\packs\Microsoft.macOS.Ref*" />
46+
</ItemGroup>
47+
48+
<PropertyGroup>
49+
<AndroidPackPaths>@(AndroidPackFolders->'%(FullPath)')</AndroidPackPaths>
50+
<IOSPackPaths>@(IOSPackFolders->'%(FullPath)')</IOSPackPaths>
51+
<MacCatalystPackPaths>@(MacCatalystPackFolders->'%(FullPath)')</MacCatalystPackPaths>
52+
<MacOSPackPaths>@(MacOSPackFolders->'%(FullPath)')</MacOSPackPaths>
53+
</PropertyGroup>
54+
3655
<PropertyGroup>
3756
<!--
38-
Note: targeting Android requires installing the .NET Android workload. To ensure the solution can
39-
be built on machines that don't have the Android workload installed, a directory check is used to
40-
ensure the Android reference assemblies pack is present on the machine before targeting Android.
57+
Note: targeting Android, iOS, Mac Catalyst or macOS requires installing the corresponding .NET workload.
58+
To ensure the solution can be built on machines that don't have the appropriate workloads installed,
59+
the platform-specific target framework monikers are only used if the corresponding .NET pack is present.
4160
-->
4261
<SupportsAndroidTargeting
4362
Condition=" '$(SupportsAndroidTargeting)' == '' And
4463
($([System.OperatingSystem]::IsMacOS()) Or $([System.OperatingSystem]::IsWindows())) And
45-
('$(GITHUB_ACTIONS)' == 'true' Or ('$(DotNetRoot)' != '' And Exists('$(DotNetRoot)packs\Microsoft.Android.Ref.34')) Or
46-
('$(DOTNET_HOST_PATH)' != '' And Exists('$([System.IO.Path]::GetDirectoryName($(DOTNET_HOST_PATH)))\packs\Microsoft.Android.Ref.34')) Or
47-
('$(MSBuildRuntimeType)' != 'Core' And Exists('$(ProgramFiles)\dotnet\packs\Microsoft.Android.Ref.34'))) ">true</SupportsAndroidTargeting>
64+
('$(GITHUB_ACTIONS)' == 'true' Or '$(AndroidPackPaths)' != '') ">true</SupportsAndroidTargeting>
4865

49-
<!--
50-
Note: targeting iOS requires installing the .NET iOS workload. To ensure the solution can be
51-
built on machines that don't have the iOS workload installed, a directory check is used to
52-
ensure the iOS reference assemblies pack is present on the machine before targeting iOS.
53-
-->
5466
<SupportsIOSTargeting
5567
Condition=" '$(SupportsIOSTargeting)' == '' And
5668
($([System.OperatingSystem]::IsMacOS()) Or $([System.OperatingSystem]::IsWindows())) And
57-
('$(GITHUB_ACTIONS)' == 'true' Or ('$(DotNetRoot)' != '' And Exists('$(DotNetRoot)packs\Microsoft.iOS.Ref')) Or
58-
('$(DOTNET_HOST_PATH)' != '' And Exists('$([System.IO.Path]::GetDirectoryName($(DOTNET_HOST_PATH)))\packs\Microsoft.iOS.Ref')) Or
59-
('$(MSBuildRuntimeType)' != 'Core' And Exists('$(ProgramFiles)\dotnet\packs\Microsoft.iOS.Ref'))) ">true</SupportsIOSTargeting>
60-
<!--
61-
Note: targeting Mac Catalyst requires installing the .NET Mac Catalyst workload. To ensure the solution
62-
can be built on machines that don't have the Mac Catalyst workload installed, a directory check is used to
63-
ensure the Mac Catalyst reference assemblies pack is present on the machine before targeting Mac Catalyst.
64-
-->
69+
('$(GITHUB_ACTIONS)' == 'true' Or '$(IOSPackPaths)' != '') ">true</SupportsIOSTargeting>
70+
6571
<SupportsMacCatalystTargeting
6672
Condition=" '$(SupportsMacCatalystTargeting)' == '' And
6773
($([System.OperatingSystem]::IsMacOS()) Or $([System.OperatingSystem]::IsWindows())) And
68-
('$(GITHUB_ACTIONS)' == 'true' Or ('$(DotNetRoot)' != '' And Exists('$(DotNetRoot)packs\Microsoft.MacCatalyst.Ref')) Or
69-
('$(DOTNET_HOST_PATH)' != '' And Exists('$([System.IO.Path]::GetDirectoryName($(DOTNET_HOST_PATH)))\packs\Microsoft.MacCatalyst.Ref')) Or
70-
('$(MSBuildRuntimeType)' != 'Core' And Exists('$(ProgramFiles)\dotnet\packs\Microsoft.MacCatalyst.Ref'))) ">true</SupportsMacCatalystTargeting>
71-
<!--
72-
Note: targeting macOS requires installing the .NET macOS workload. To ensure the solution can be
73-
built on machines that don't have the macOS workload installed, a directory check is used to
74-
ensure the macOS reference assemblies pack is present on the machine before targeting macOS.
75-
-->
74+
('$(GITHUB_ACTIONS)' == 'true' Or '$(MacCatalystPackPaths)' != '') ">true</SupportsMacCatalystTargeting>
75+
7676
<SupportsMacOSTargeting
7777
Condition=" '$(SupportsMacOSTargeting)' == '' And
7878
($([System.OperatingSystem]::IsMacOS()) Or $([System.OperatingSystem]::IsWindows())) And
79-
('$(GITHUB_ACTIONS)' == 'true' Or ('$(DotNetRoot)' != '' And Exists('$(DotNetRoot)packs\Microsoft.macOS.Ref')) Or
80-
('$(DOTNET_HOST_PATH)' != '' And Exists('$([System.IO.Path]::GetDirectoryName($(DOTNET_HOST_PATH)))\packs\Microsoft.macOS.Ref')) Or
81-
('$(MSBuildRuntimeType)' != 'Core' And Exists('$(ProgramFiles)\dotnet\packs\Microsoft.macOS.Ref'))) ">true</SupportsMacOSTargeting>
79+
('$(GITHUB_ACTIONS)' == 'true' Or '$(MacOSPackPaths)' != '') ">true</SupportsMacOSTargeting>
8280

8381
<!--
8482
Note: while <EnableWindowsTargeting>true</EnableWindowsTargeting> can be used to force targeting

0 commit comments

Comments
 (0)