Skip to content
This repository has been archived by the owner on May 1, 2024. It is now read-only.

[Bug] Unit Test projects now reference Xamarin.Forms.Platform.WPF #985

Open
cabal95 opened this issue Feb 9, 2021 · 26 comments
Open

[Bug] Unit Test projects now reference Xamarin.Forms.Platform.WPF #985

cabal95 opened this issue Feb 9, 2021 · 26 comments
Labels
❗ Breaking Change This issue/PR described a breaking change! Proceed with caution and never merge to current stable!

Comments

@cabal95
Copy link

cabal95 commented Feb 9, 2021

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

  1. Create a shared library and install Xamarin Forms 5.0.0 and Community Toolkit 1.0.2 via NuGet.
  2. Create a unit test library that has a project reference to the first project.
  3. 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

image

Reproduction Link

Let me know if I need to add one, since the unit tests in XCF exhibit the same behavior.

@jfversluis
Copy link
Member

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!

@HeikkiDev
Copy link

HeikkiDev commented Feb 18, 2021

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:
rotorgames/Rg.Plugins.Popup#568 (comment)

@akamud
Copy link

akamud commented Feb 22, 2021

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:
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.

@pictos
Copy link
Contributor

pictos commented Feb 22, 2021

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?

@akamud
Copy link

akamud commented Feb 22, 2021

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?

Yes, the build fails on my unit test projects and my Xamarin.Forms project referencing XCT.
I'm using 1.0.2.

@brminnick
Copy link
Contributor

brminnick commented Feb 22, 2021

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

@brminnick

This comment has been minimized.

@jfversluis

This comment has been minimized.

@jsuarezruiz jsuarezruiz transferred this issue from xamarin/XamarinCommunityToolkit Feb 23, 2021
@cabal95
Copy link
Author

cabal95 commented Feb 23, 2021

@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.

@brminnick
Copy link
Contributor

brminnick commented Feb 23, 2021

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 👍

@brminnick

This comment has been minimized.

@StephaneDelcroix

This comment has been minimized.

@jsuarezruiz jsuarezruiz reopened this Feb 25, 2021
@jsuarezruiz jsuarezruiz transferred this issue from xamarin/Xamarin.Forms Feb 25, 2021
@omghb
Copy link

omghb commented Mar 1, 2021

Please fix this. I run into the same issue. Workaround <GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks> helped.

@Countryen
Copy link
Contributor

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).

@mgramley
Copy link

Has there been an update to this? The workaround everyone has mentioned doesn't work for me.

@brminnick
Copy link
Contributor

@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.

@brminnick brminnick added the ❗ Breaking Change This issue/PR described a breaking change! Proceed with caution and never merge to current stable! label Nov 19, 2021
@mgramley
Copy link

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.

@pasteusernamehere
Copy link

pasteusernamehere commented Mar 17, 2022

@brminnick <GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks> and test project targeting .NET Core 3.1 does not work.

@vppetrov
Copy link

vppetrov commented Apr 7, 2022

This seems to be the root cause for #1167 and #1482.

@Axemasta
Copy link
Contributor

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 😅

@thomasgalliker
Copy link

@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.

nicolasbriere1 added a commit to ZeroGachis/Smartway.UiComponent that referenced this issue Sep 21, 2022
@haavamoa
Copy link

haavamoa commented Feb 10, 2023

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.

@follesoe
Copy link

We're in the same situation as @haavamoa 😫

@tNRevan
Copy link

tNRevan commented Apr 13, 2023

Had to remove the community toolkit due to this issue :'(

@gtbuchanan
Copy link

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.

@softlion
Copy link

Ty @gtbuchanan finally a workaround that fixes it. It was really a pain !

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
❗ Breaking Change This issue/PR described a breaking change! Proceed with caution and never merge to current stable!
Projects
None yet
Development

No branches or pull requests