XamarinCommunityToolkit
                                
                                 XamarinCommunityToolkit copied to clipboard
                                
                                    XamarinCommunityToolkit copied to clipboard
                            
                            
                            
                        [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.
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!
Similar issue here. Build error in my Unit Tests project with TargetFramework netcoreapp3.1.
NETSDK1073: The FrameworkReference 'Microsoft.WindowsDesktop.App' was not recognized
This workaround worked for me: https://github.com/rotorgames/Rg.Plugins.Popup/issues/568#issuecomment-707134962
Similar issue here. Build error in my Unit Tests project with TargetFramework netcoreapp3.1.
NETSDK1073: The FrameworkReference 'Microsoft.WindowsDesktop.App' was not recognizedThis workaround worked for me: rotorgames/Rg.Plugins.Popup#568 (comment)
I have this same issue in any project referencing XCT on Mac. It just won't compile due to the Microsoft.WindowsDesktop.App reference.
I have this same issue in any project referencing XCT on Mac. It just won't compile due to the Microsoft.WindowsDesktop.App reference.
@akamud what version of XCT are you running? The any project includes xamarin.forms projects?
I have this same issue in any project referencing XCT on Mac. It just won't compile due to the Microsoft.WindowsDesktop.App reference.
@akamud what version of XCT are you running? The
any projectincludes xamarin.forms projects?
Yes, the build fails on my unit test projects and my Xamarin.Forms project referencing XCT. I'm using 1.0.2.
~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:
<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
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
I recommend closing this issue because it is not a problem in Xamarin.CommunityToolkit, rather it is caused by Xamarin.Forms and then inherited by Xamarin.CommunityToolkit.
Alternatively, @jfversluis or @jsuarezruiz may be able to transfer it to the Xamarin.Forms repo.
 
                                    
                                    
                                    
                                
I lost my rights to the Forms repo so @jsuarezruiz is now our only hope!
@brminnick Just to be clear, the original issue I posted about ONLY happens if Xamarin Community Toolkit is linked in. If I remove XCT but leave Xam5 in then the warning goes away.
Apologies, @cabal95 - you are absolutely correct!
This is  caused by Xamarin.CommunityToolkit's dependency on Xamarin.Forms.Platform.WPF for .NETCoreApp 3.1:

I was 100% mistaken.
It turns out Xamarin.Forms.PancakeView has the same problem (it also references Xamarin.Forms.Platform.WPF on .NETCoreApp 3.1), and when I was digging into the root cause of this bug, I mistook Xamarin.Forms.PancakeView for Xamarin.Forms.
I'll hide my earlier comment to avoid any confusion 👍
@jsuarezruiz When you get a chance, could you move this back to Xamarin.CommunityToolkit? (Explaination, above)
I'm so sorry for the mistake! 🤦♂️
I can't transfer the issue. closing it
Please fix this. I run into the same issue. Workaround <GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks> helped.
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:
<ItemGroup>
    <PackageReference Include="OpenTK" Version="3.0.1">
	<NoWarn>NU1701</NoWarn>
    </PackageReference>
    <PackageReference Include="OpenTK.GLControl" Version="3.0.1">
	<NoWarn>NU1701</NoWarn>
    </PackageReference>
</ItemGroup>
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).
Has there been an update to this? The workaround everyone has mentioned doesn't work for me.
@mgramley Ensure your Unit Test project is targeting .NET Core 3.1 and that the Unit Test CSPROJ includes <GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>.
We do not have a known way to fix this without removing Xamarin Community Toolkit support for WPF.
We are open to pull requests.
I already had the GenerateErrorForMissingTargetingPacks flag in my project, it did not resolve the issue for me.
For now, since I only need a single view from the toolkit I will pul the latest source files into my project.
@brminnick  <GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks> and test project targeting .NET Core 3.1 does not work.
This seems to be the root cause for https://github.com/xamarin/XamarinCommunityToolkit/issues/1167 and https://github.com/xamarin/XamarinCommunityToolkit/issues/1482.
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 😅
@jfversluis did you check with the repository owners how they want to untangle the dependency to Xamarin.Forms.Platform.WPF? From my point of view, such a dependency should never have been added. As for now since we move our test projects to net6.0, we had to get rid of XamarinCommunityToolkit. Let me know if we can use it again.
Any update on this? Sad that we havev to run tests on netcoreapp 3.1. Especially now as net5.0-windows is officially removed from azure images, which forces us to run under netcoreapp 3.1 in Azure Devops.
We're in the same situation as @haavamoa 😫
Had to remove the community toolkit due to this issue :'(
I was running into this issue with my net6.0-android sdk-style app project rather than a unit test project. The GenerateErrorForMissingTargetingPacks workaround did not work for me either but I found this one that does:
  <Target BeforeTargets="_CheckForTransitiveWindowsDesktopDependencies" Name="_FixStupidSdkError_NETSDK1136">
    <ItemGroup>
      <TransitiveFrameworkReference Remove="Microsoft.WindowsDesktop.App" />
      <TransitiveFrameworkReference Remove="Microsoft.WindowsDesktop.App.WPF" />
      <TransitiveFrameworkReference Remove="Microsoft.WindowsDesktop.App.WindowsForms" />
    </ItemGroup>
  </Target>
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.ExcludeAssets attribute.
Ty @gtbuchanan finally a workaround that fixes it. It was really a pain !