Rg.Plugins.Popup icon indicating copy to clipboard operation
Rg.Plugins.Popup copied to clipboard

Unit Tests Projects won't build on Mac

Open NPadrutt opened this issue 4 years ago • 11 comments

🐛 Bug Report

I have Xamarin Forms Application with an .net core Test library for my shared project. When I add Rg.Plugins.Popup I'm no longer able to build my test project on MacOS because it tries to load a WPF component which fails on MacOS.

Expected behavior

Unit Test Projects are buildable and Tests can be executed.

Reproduction steps

Start attached reproduction project and try to build / run unit test.

test.zip

Configuration

Version: 2.0.0.2

Platform:

  • [x] :iphone: iOS
  • [ ] :robot: Android
  • [ ] :checkered_flag: WPF
  • [ ] :earth_americas: UWP
  • [x] :apple: MacOS
  • [ ] :tv: tvOS
  • [x] :monkey: Xamarin.Forms

NPadrutt avatar Jul 29 '20 21:07 NPadrutt

Having this problem too. WPF dependencies won't build on mac systems, which makes this package not buildable for Xamarin Forms. The build chugs along, but this is the task and error that fails:

Target ResolveTargetingPackAssets:
    /usr/local/share/dotnet/sdk/3.1.302/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(283,5): error NETSDK1073: The FrameworkReference 'Microsoft.WindowsDesktop.App.WPF' was not recognized

SittenSpynne avatar Jul 31 '20 15:07 SittenSpynne

I have stumbled upon the same issue. My test project works fine on Windows, but throws "Error NETSDK1073: The FrameworkReference 'Microsoft.WindowsDesktop.App.WPF' was not recognized (NETSDK1073)" when trying from MAC.

Is there any workaround for this issue?

AndreasErikCoder avatar Aug 14 '20 10:08 AndreasErikCoder

OK it is a problem with the Rg.Plugins.Pop NuGet package. In its .nuspec it always includes WPF:

<frameworkReferences>
    <group targetFramework=".NETCoreApp3.1">
    <frameworkReference name="Microsoft.WindowsDesktop.App.WPF" />
    </group>
</frameworkReferences>

Since your NUnit test project targets .NET Core app 3.1 it adds that Framework Reference which is not supported on the Mac. source

spottedmahn avatar Aug 17 '20 18:08 spottedmahn

<PackageReference Include="Rg.Plugins.Popup" Version="2.0.0.3">
    <PrivateAssets>all</PrivateAssets>
</PackageReference>

https://stackoverflow.com/a/62341670/1155650

rohitvipin avatar Aug 28 '20 16:08 rohitvipin

I tried @rohitvipin 's solution in all of the project files that reference Rg.Plugins.Popup.

It did seem to make my projects build but now my test runner in VS is completely mucked up. It won't load even previous versions of the test project. I'm going to try a reboot and hope that works.

SittenSpynne avatar Aug 31 '20 19:08 SittenSpynne

@rohitvipin When I tried giving PrivateAssets "all" to the csproj files which reference the plugin, I'm getting compiler error in my test class files which has "using Rg.Plugins.Popup".

AndreasErikCoder avatar Sep 01 '20 05:09 AndreasErikCoder

The PrivateAssets tag didn't do anything for me either.

davidaramantSEP avatar Sep 21 '20 14:09 davidaramantSEP

I think I've found the solution for this! The PrivateAssets tag by itself was not enough in our case. We have a shared .NET Standard library and a .NET Core unit test project, and even with that tag in both projects we couldn't compile the unit tests.

The answer for us seems to be adding the following additional tag to the unit tests: <GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>

I just put this in the first PropertyGroup in the unit test csproj (the one that has things like TargetFramework)

davidaramant avatar Oct 12 '20 13:10 davidaramant

We just updated our unit test project to 3.1 and encountered the same problem with the Microsoft.WindowsDesktop.App.WPF framework reference that @spottedmahn identified. Thanks to @davidaramant for providing an effective workaround.

  <PropertyGroup>
    <TargetFramework>netcoreapp3.1</TargetFramework>
    <GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>
...

shaynemarriage avatar Oct 29 '20 19:10 shaynemarriage

The workaround works for 3.1, but not for 5.0 and 6.0-Preview

IngweLand avatar Oct 15 '21 12:10 IngweLand

To workaround the issue, add this target at the end of the csproj

<Target BeforeTargets="_CheckForTransitiveWindowsDesktopDependencies" Name="RemoveWpf">
    <ItemGroup>
        <TransitiveFrameworkReference Remove="Microsoft.WindowsDesktop.App.WPF" />
    </ItemGroup>
</Target>

kvpt avatar Sep 08 '22 14:09 kvpt