.NET MAUI › Native Interop & Libraries
How do you conditionally reference a package only for specific platforms?
AdvancedAnswer
Use an MSBuild condition on the PackageReference keyed off the TargetFramework moniker, so a platform-only dependency is restored just for that head. This avoids pulling Android-only or iOS-only libraries into targets that cannot use them.
<ItemGroup Condition="$(TargetFramework.Contains('-android'))">
<PackageReference Include="Xamarin.AndroidX.Biometric" Version="1.1.0.19" />
</ItemGroup>Real-world example An Android biometric package is referenced only for the net-android target, keeping the iOS and Windows builds lean.