Follow these steps to resolve NuGet dependency conflicts and library version mismatches in a Xamarin project using <PackageReference>:
- Identify the exact error codes and packages
- Look in the build output and Package Manager Console for errors like
NU1106,NU1107,NU1102, orNU1202. - Note which packages and versions are in conflict (for example, two different versions of the same Play plugin or its dependencies).
- Look in the build output and Package Manager Console for errors like
- Fix version conflicts between packages (NU1107 / diamond dependencies)
- When two packages require different versions of the same dependency (classic “diamond dependency”), NuGet must pick one version.
- If the error resembles
NU1107(version conflict detected forPackageX):- Edit the main Xamarin project’s
.csproj. - Add a direct
<PackageReference>for the conflicting package with the version to use, typically the higher version:<ItemGroup> <PackageReference Include="PackageX" Version="4.0.0" /> </ItemGroup> - Restore packages and rebuild.
- Edit the main Xamarin project’s
- This explicitly tells NuGet which version to unify on and resolves the conflict.
- Avoid overly strict or conflicting version ranges (NU1106)
- If the error is like
NU1106(unable to satisfy conflicting requests):- Open the
.csprojand look for<PackageReference>entries with exact or upper-bounded versions, for example:<PackageReference Include="ExamplePackage" Version="[1.0]" /> <PackageReference Include="ExamplePackage" Version="[1.0,2.0)" /> - Replace exact or tight ranges with a minimum version only, which is more “open-ended” and easier for NuGet to resolve:
<!-- Prefer this style --> <PackageReference Include="ExamplePackage" Version="1.0.0" /> - Re-run restore and build.
- Open the
- If the error is like
- Ensure requested versions actually exist (NU1102)
- If the error is like
NU1102(unable to find package with version >= X):- Open the
.csprojand verify theVersionattribute for the failing package. - Change it to a version that actually exists on your configured sources.
- Check
NuGet.Configin the corporate environment to ensure the correct feeds are configured and not blocking the needed source. - Restore packages and rebuild.
- Open the
- If the error is like
- Fix target framework incompatibilities (NU1202 / “not compatible” errors)
- If the error says a package “is not compatible with” the project’s target framework (for example,
NU1202):- Check the Xamarin project’s
<TargetFramework>(or<TargetFrameworks>) in the.csproj. - Compare with the frameworks listed in the error message as supported by the package.
- Use one of these options:
- Retarget the project to a framework supported by the Play plugin and its dependencies.
- Or choose a different version of the plugin that supports the current target framework.
- After changing the target framework or package version, restore and rebuild.
- Check the Xamarin project’s
- If the error says a package “is not compatible with” the project’s target framework (for example,
- Prefer minimum-only version declarations for your own libraries
- For internal corporate libraries referenced via NuGet:
- Use a minimum version only (no upper bound, no exact range) to reduce conflicts:
<PackageReference Include="Corporate.Library" Version="1.2.0" /> - Avoid exact versions (
[1.2.0]) or upper limits ([1.2.0,2.0.0)), as they increase the chance of conflicts when combined with third-party packages.
- Use a minimum version only (no upper bound, no exact range) to reduce conflicts:
- For internal corporate libraries referenced via NuGet:
- If using
packages.configin older projects- If any legacy Xamarin projects still use
packages.configinstead of<PackageReference>:- Be aware NuGet selects the lowest
major.minorversion that satisfies dependencies, which can differ from<PackageReference>behavior. - Mixed stable/prerelease graphs are not allowed with ranges like
[1.0.0, 2.0.0). - Consider migrating to
<PackageReference>for more predictable restore and easier conflict resolution.
- Be aware NuGet selects the lowest
- If any legacy Xamarin projects still use
- Use tooling help if available
- In Visual Studio, consider using the NuGetSolver extension (if permitted in the corporate environment) to automatically analyze and suggest fixes for dependency conflicts.
Applying these steps systematically—first unifying versions via direct references, then relaxing strict version ranges, verifying available versions, and aligning target frameworks—will resolve most NuGet dependency conflicts in a Xamarin corporate project.
References: