rotorgames / Rg.Plugins.Popup

Xamarin Forms popup plugin
MIT License
1.15k stars 337 forks source link

Unit Tests Projects won't build on Mac #568

Open NPadrutt opened 4 years ago

NPadrutt commented 4 years ago

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

SittenSpynne commented 4 years ago

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
AndreasErikCoder commented 4 years ago

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?

spottedmahn commented 4 years ago

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

rohitvipin commented 4 years ago
<PackageReference Include="Rg.Plugins.Popup" Version="2.0.0.3">
    <PrivateAssets>all</PrivateAssets>
</PackageReference>

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

SittenSpynne commented 4 years ago

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.

AndreasErikCoder commented 4 years ago

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

davidaramantSEP commented 4 years ago

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

davidaramant commented 3 years ago

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)

shaynemarriage commented 3 years ago

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>
...
IngweLand commented 2 years ago

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

kvpt commented 2 years ago

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>