Broken dependency SkiaSharp

Hello,

We are updating GemBox.Document from 35.0.1300 to 35.0.1538.

Our project is in .Net Framework 4.8.

This version has a new transitive dependency to SkaSharp. When restoring Nuget package, there’s two broken references that appears under the project where GemBox is installed and every other project in the solution that references this project.

Steps to reproduce

  • In Visual Studio 2022, create a new .Net Framework Console App targetting .Net Framework 4.8
  • Build the solution
  • Install GemBox.Document version 35.0.1538 in the project, in PackageReference format (no package.config file)
  • Build the solution : usually here it’s fine
  • Clean solution
  • Close Visual Studio
  • Reopen Visual Studio and the solution
  • Restore packages
  • Build solution

If someone else clone this repo, they got the same problem if they

  • build
  • close Visual Studio
  • reopen Visual Studio

Note that you can reproduce this issue without using GemBox.Document.

In other words, remove the <PackageReference> for GemBox.Document and add one for SkiaSharp or HarfBuzzSharp. Do those same steps and you’ll notice that the same warning appears.
The issue is related to the package dependency that those libraries have, the native assets for macOS.

Anyway, I noticed that the issue occurs only when using an older format for the project (non-SDK version) and the newer format for the NuGet packaging (<PackageReference>). It seems that this combination doesn’t work well for those packages.

So the solution is to either use the older Nuget package installation (packages.config) or the newer project format (<Project Sdk="Microsoft.NET.Sdk">).

Regards,
Mario

:information_source: The currently still open GitHub issue regarding that behaviour: [BUG] VS build error when referencing SkiaSharp from an SDK style csproj targetting .NET framework 4.8 · Issue #2450 · mono/SkiaSharp · GitHub

What fixed the build for me was to add ExcludeAssets="buildTransitive" to my reference, as suggested as workaround in the linked issue:
<PackageReference Include="GemBox.Bundle" Version="47.0.1370" ExcludeAssets="buildTransitive" />

But I am not sure, if that has any unintended side effects, which I did not notice so far.

Best regards,
Sarah

In the future, that might cause issues.
So perhaps you could try using this instead:

<PackageReference Include="GemBox.Bundle" Version="47.0.1370" />
<PackageReference Include="SkiaSharp" Version="*" ExcludeAssets="buildTransitive" />
<PackageReference Include="SkiaSharp.NativeAssets.Win32" Version="*" />
<PackageReference Include="HarfBuzzSharp" Version="*" ExcludeAssets="buildTransitive" />
<PackageReference Include="HarfBuzzSharp.NativeAssets.Win32" Version="*" />

Hi Mario,

I still get the build error when including the packages individually as above.
The project I get the errors with uses the “Microsoft.NET.Sdk.Web” SDK and has the target framework .net472.
Do I have to handle it differently?

Best regards,
Sarah

Can you please send us a small Visual Studio project that reproduces this issue so that I can investigate it further?

Hi Mario,

I uploaded a minimal repro project here: GitHub - SarahAmagno/ReproGemBox
The issue should be reproducible by building the only project in the solution.
The build fails unless the package reference is changed to
<PackageReference Include="GemBox.Bundle" Version="47.0.1370" ExcludeAssets="buildTransitive" />

Best regards,
Sarah

The error message indicates another way this can be resolved, by disabling the <EnableDefaultContentItems>.
In other words, try this:

<PropertyGroup>
  <TargetFramework>net472</TargetFramework>
  <Nullable>enable</Nullable>
  <ImplicitUsings>enable</ImplicitUsings>
  <EnableDefaultContentItems>false</EnableDefaultContentItems>
</PropertyGroup>

Hi Mario,

this fixes the build but I am not sure about the possible side effects changing this setting has on the project’s publishing behaviour. However, I will use it as a workaround as long as I don’t notice any further problems.

Best regards,
Sarah