LottieXamarin icon indicating copy to clipboard operation
LottieXamarin copied to clipboard

Compilation error in Unit Test project on Mac when using Lottie 4.0.x version

Open Sergiu-Cosmin opened this issue 4 years ago • 5 comments

🐛 Bug Report

We are currently developing an application in Xamarin Forms on MAC using Visual Studio for Mac and use the lottie animation in a .NET Standard 2.1 common project, to unit test this common project we have a separate project targeting .NET Core 3.1. Everything was ok until we updated from Lottie 3.1.0 to Lottie 4.0.4 and also tried 4.0.6. After the update we have build errors on the unit test project:

/usr/local/share/dotnet/sdk/3.1.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(5,5): Error NETSDK1073: The FrameworkReference 'Microsoft.WindowsDesktop.App.WPF' was not recognized (NETSDK1073) (CommonProject.Tests) /usr/local/share/dotnet/sdk/3.1.402/Sdks/Microsoft.NET.Sdk/targets/Microsoft.NET.Sdk.FrameworkReferenceResolution.targets(5,5): Error NETSDK1073: The FrameworkReference 'Microsoft.WindowsDesktop.App.WindowsForms' was not recognized (NETSDK1073) (CommonProject.Tests)

Expected behavior

No errors when building

Reproduction steps

Create a Xamarin.Forms Shell Project Add Lottie 4.0.6 to the .NET Standard 2.1 common project Create a NUnit test project with type .NET Core 3.1 Add .NET Standard 2.1 common project as reference to the NET Core 3.1 project Try to build the test project

Configuration

You can check the project below for a faster view of the configuration and problem TestLottie.zip

Version: 4.0.6

Platform:

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

Sergiu-Cosmin avatar Oct 28 '20 18:10 Sergiu-Cosmin

Not sure this is an issue. Since Lottie 4.x it targets WPF on .NET and .NET core as well. That's why it is imported.

martijn00 avatar Oct 31 '20 13:10 martijn00

@martijn00 so then is there a way to fix this ? did you test the TestLottie.zip on a mac ? we cannot run any unit tests locally anymore because of this issue, our CI/CD pipelines fail as well :(

Sergiu-Cosmin avatar Oct 31 '20 13:10 Sergiu-Cosmin

@Sergiu-Cosmin I take it your Unit Test Project is referencing the Main Project. If that is the case, then in the Main Project, open up the .csproj file and mark the Lottie NuGet package as a private asset. In that way it wont be imported when running the unit tests. That worked for us. IE.

<PackageReference Include="Com.Airbnb.Xamarin.Forms.Lottie" Version="4.0.6"> <PrivateAssets>all</PrivateAssets> </PackageReference>

mauro-dasilva avatar Oct 31 '20 13:10 mauro-dasilva

@mauro-dasilva thank you for the advice, that is what we did but that leads to other problems, if we make it a a private asset we cannot use it as a reference in other projects anymore

our app has a separate module where all our ui components are stored, which uses also lottie for animations this is constructed as a nuget package that we use in out main app, but our main app also needs to use lottie for other animations which are not in the UI Components, so we use the reference from the UI Components module so we don't have to keep them in sync (UI Components and main app Lottie nugets) what we actually use is a little bit more complex with more modules but the explanation above describes it pretty well, now the problem is that if we set it to PrivateAssets we lose the ability to take the reference from the UI Components nuget and we have to add the Lottie nuget everywhere we need it

Sergiu-Cosmin avatar Oct 31 '20 13:10 Sergiu-Cosmin

This can be resolved by adding the following to the PropertyGroup in the .csproj file:

<GenerateErrorForMissingTargetingPacks>false</GenerateErrorForMissingTargetingPacks>

ChristopherStephan avatar Nov 09 '20 10:11 ChristopherStephan