Description
Description
In Xamarin workloads, we'd like to set a default RuntimeIdentifier for each platform we support.
The problem is that the Microsoft.NET.RuntimeIdentifierInference.targets
file is loaded before our WorkloadManifest.targets
file, and executes some logic depending on whether the RuntimeIdentifier is set or not, which means that it's too late if we try to set RuntimeIdentifer
in our WorkloadManifest.targets file.
And we can't set it earlier (AutoImports.props
), because that would be a global default, not a platform-specific default.
The workaround I've found is to replicate the behavior of Microsoft.NET.RuntimeIdentifierInference.targets
that we want in our WorkloadManifest.targets
, which comes down to something like this:
<!-- First set the default RuntimeIdentifier if not already specified. -->
<PropertyGroup Condition=" '$(RuntimeIdentifier)' == '' And '$(RuntimeIdentifiers)' == '' ">
<RuntimeIdentifier Condition="'$(_PlatformName)' == 'iOS'">iossimulator-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(_PlatformName)' == 'tvOS'">tvossimulator-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(_PlatformName)' == 'macOS'">osx-x64</RuntimeIdentifier>
<RuntimeIdentifier Condition="'$(_PlatformName)' == 'MacCatalyst'">maccatalyst-x64</RuntimeIdentifier>
<!-- Workaround/hack:
The Microsoft.NET.RuntimeIdentifierInference.targets file is loaded
before this file, and executes some logic depending on whether the
RuntimeIdentifier is set or not. Since RuntimeIdentifier isn't set at
that point (we're setting it here), we need to replicate the logic in
the Microsoft.NET.RuntimeIdentifierInference.targets file to make sure
things work as expected.
-->
<SelfContained>true</SelfContained>
<_RuntimeIdentifierUsesAppHost>false</_RuntimeIdentifierUsesAppHost>
<UseAppHost>false</UseAppHost>
<IntermediateOutputPath>$(IntermediateOutputPath)$(RuntimeIdentifier)\</IntermediateOutputPath>
<OutputPath>$(OutputPath)$(RuntimeIdentifier)\</OutputPath>
</PropertyGroup>
Something more appropriate would be nice...