XamarinCommunityToolkit: [Bug] Unit Test projects now reference Xamarin.Forms.Platform.WPF
Description
I’m not sure if this is a bug per-se, but I couldn’t find any previous discussion of it so thought I would mention it as it doesn’t “feel right”. For our Xamarin Forms project, we have some unit tests that verify some of the business logic works and doesn’t break between various upgrades. These are not UI tests. Just a standard netcoreapp3.1 project type for unit testing.
Today I installed Xamarin Community Toolkit and noticed the following warnings appeared:
warning NU1701: Package 'OpenTK 3.0.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
warning NU1701: Package 'OpenTK.GLControl 3.0.1' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
My tests still execute and work fine, but it doesn’t seem right that my unit tests project would now be forced to reference a platform lib. I downloaded the latest code from here and verified that the unit test project here does the same.
Is this actually a bug or something we have to live with due to no other way to differentiate WPF from a “generic non-platform” project?
Steps to Reproduce
- Create a shared library and install Xamarin Forms 5.0.0 and Community Toolkit 1.0.2 via NuGet.
- Create a unit test library that has a project reference to the first project.
- Compile, see warnings when NuGet packages are restored.
Expected Behavior
No reference to a platform I’m not using and is not valid for unit testing.
Actual Behavior
Xamarin.Forms.Platform.WPF gets added as a dependency of my Unit Tests project, which chains to the OpenTK package as well.
Basic Information
- Version with issue: 1.0.2
- Last known good version: n/a
- IDE: Visual Studio 2019 16.8.4 Windows 10
- Platform Target Frameworks:
- iOS:
- Android:
- UWP:
- Android Support Library Version:
- Nuget Packages: Xamarin Forms 5.0.0
- Affected Devices:
Workaround
None so far.
Reproduction imagery

Reproduction Link
Let me know if I need to add one, since the unit tests in XCF exhibit the same behavior.
About this issue
- Original URL
- State: open
- Created 3 years ago
- Reactions: 9
- Comments: 26 (10 by maintainers)
Commits related to this issue
- 🚀 Update csproj for ignore error missing dependencies Following issue : xamarin/XamarinCommunityToolkit#985 — committed to ZeroGachis/xamarin-ui by nicolasbriere1 2 years ago
- 🚀 Update csproj for ignore error missing dependencies Following issue : xamarin/XamarinCommunityToolkit#985 — committed to ZeroGachis/xamarin-ui by nicolasbriere1 2 years ago
I was running into this issue with my
net6.0-androidsdk-style app project rather than a unit test project. TheGenerateErrorForMissingTargetingPacksworkaround did not work for me either but I found this one that does:It’s obviously not ideal if you actually develop for these platforms but that wasn’t a problem in my case.
I originally tried something like this to force the use of a different target framework without the WPF dependency but it appears the aforementioned target still runs regardless of the
PackageReference.ExcludeAssetsattribute.~This is a bug caused by the Xamarin.Forms NuGet Package.~ Edit: This statement is incorrect. See correction, below
Workaround
The current workaround is to add the following line to the Unit Test CSPROJ file:
Here an example of I implement this workaround in my app GitTrends: https://github.com/brminnick/GitTrends/blob/efe0f6e06c1e22c444b2fa35646797c64e82f235/GitTrends.UnitTests/GitTrends.UnitTests.csproj#L9
Its nice we have a workaround but this doesn’t work for .net5.0 projects and thinking about .net6.0 compatibility when we eventually migrate XF projects to MAUI I’d rather be using a newer .net version than
netcoreapp3.1😅Apologies, @cabal95 - you are absolutely correct!
This is caused by
Xamarin.CommunityToolkit’s dependency onXamarin.Forms.Platform.WPFfor.NETCoreApp 3.1:I was 100% mistaken.
It turns out
Xamarin.Forms.PancakeViewhas the same problem (it also referencesXamarin.Forms.Platform.WPFon.NETCoreApp 3.1), and when I was digging into the root cause of this bug, I mistookXamarin.Forms.PancakeViewforXamarin.Forms.I’ll hide my earlier comment to avoid any confusion 👍
Ty @gtbuchanan finally a workaround that fixes it. It was really a pain !
The workaround with
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>doesn’t work for my .NET 5 test projects. Also I don’t want to disable all (unknown) errors. You can, however, disable them more specifically, if you include the packages yourself, like this:Project.Tests.csproj:
But you should check the status of this issue and remove the workaround as soon as possible (or update the package manually, whenever XCT does).
@jsuarezruiz When you get a chance, could you move this back to Xamarin.CommunityToolkit? (Explaination, above)
I’m so sorry for the mistake! 🤦♂️
Hey @cabal95 that is definitely not behavior I would want to force upon anyone.
We need to check our dependencies here. Thanks for letting us know!