mono / SkiaSharp

SkiaSharp is a cross-platform 2D graphics API for .NET platforms based on Google's Skia Graphics Library. It provides a comprehensive 2D API that can be used across mobile, server and desktop models to render images.
MIT License
4.14k stars 522 forks source link

[BUG] Annoying warning on .NET Framework 4.8 project with SkiaSharp 2.88.6 or 2.88.7 #2824

Closed rozeboosje closed 5 days ago

rozeboosje commented 1 month ago

Description

Created a WPF project targeting .NET Framework 4.8 with no additional code, only nuget references to SkiaSharp 2.88.6 and also when upgrading this to 2.88.7

At first this builds without any errors but if you then save the project and reopen it later the following warning starts appearing in the Error List:

Severity Code Description Project File Line Suppression State Details Warning The referenced component 'C:\Users[*****]\packages\SkiaSharp.NativeAssets.macOS.2.88.7\build\net462....\runtimes\osx\native\libSkiaSharp.dylib' could not be found. Foo

Can something be done about this, please?

Additional information: Version 2.88.7 of SkiaSharp is presented as "Latest stable" in nuget. Also, we don't even use SkiaSharp ourselves; this is included in our project after installing a 3rd party nuget package which depends on SkiaSharp 2.88.6 ... However, even after removing the 3rd party software and leaving only SkiaSharp and its dependencies, the warning persists.

Code

The best way to share code for larger projects is a link to a GitHub repository: https://github.com/user/repo/tree/bug-123

But, you can also share a short block of code here:

// some C# code here

You can also share some XAML:

<!-- xaml code here -->

Expected Behavior

Project should simply build without any warnings.

Actual Behavior

Warning is shown.

Version of SkiaSharp

2.88.3 (Current)

Last Known Good Version of SkiaSharp

2.88.2 (Previous)

IDE / Editor

Visual Studio (Windows)

Platform / Operating System

Windows

Platform / Operating System Version

Windows

Devices

Laptop

Relevant Screenshots

image

Relevant Log Output

No response

Code of Conduct

lbras commented 1 month ago

I get this as well. It has been around for a while #2223. Using VS2019 16.11.35.

rozeboosje commented 1 month ago

It's, at the very least, annoying. But it also leaves me wondering what I need to distribute in order to ensure that the software works without issues.

Please address this.

rozeboosje commented 1 month ago

Any chance of a response from the Team? Even merely an acknowledgement that the issue has been noted and understood?

rozeboosje commented 1 month ago

Issue still persists in the nuget packages for skiasharp 2.88.8

mattleibow commented 3 weeks ago

This is the code that is importing the native reference:

https://github.com/mono/SkiaSharp/blob/release/2.x/binding/SkiaSharp/nuget/build/net462/SkiaSharp.targets#L11-L16

It has a condition that is not ever true on Windows, VS for Windows or WPF. Yet somehow the IDE is seeing it.

It does seem to only happen in the classic projects, so a workaround may be to upgrade to the SDK-style projects.

rozeboosje commented 3 weeks ago

Sorry can you explain what you mean by "classic" and "SDK-style" projects?

We are using a product called Aspose.Words in a Solution with 84 projects in it. That product has now been changed to include references to SkiaSharp and that's how the nuget packages for SkiaSharp ended up pulled into our Solution. I am not sure that we can justify the amount of work involved in the workaround...

mattleibow commented 3 weeks ago

This appears to be a IDE warning, and not a compile warning. So the IDE is doing this all on its own and we have no way to control it. It should not be happening as there is a condition around it that is false. Looking at a binlog, this warning does not exist - and it does not have a code either so we cannot ignore or even do anything.

mattleibow commented 3 weeks ago

SDK style projects are the new way to write csproj: https://learn.microsoft.com/en-us/dotnet/core/project-sdk/overview

For example, a File | New project will look like this:

<Project Sdk="Microsoft.NET.Sdk">

    <PropertyGroup>
        <OutputType>WinExe</OutputType>
        <TargetFramework>net48</TargetFramework>
        <UseWPF>true</UseWPF>
    </PropertyGroup>

</Project>

All the clutter has been removed.

mattleibow commented 3 weeks ago

You can also easily update from the old projects to the new project with the .net upgrade assistant: https://dotnet.microsoft.com/en-us/platform/upgrade-assistant

This will not actually upgrade anything with your app, just the csproj format.

Running a test now to confirm...

rozeboosje commented 3 weeks ago

Okay but this is a years old solution and we're stuck in .NET Framework 4.8 world so a move to .NET Core is not going to happen any time soon.

I had a look at the code you posted, though ... and I think I can see what the problem is.

<ShouldIncludeNativeSkiaSharp Condition=" '$(ShouldIncludeNativeSkiaSharp)' == '' ">True</ShouldIncludeNativeSkiaSharp>

So there is a condition under which the value is set to True, but there is no condition under which the value is set to False, so as far as I can tell from the code snippet, the value could be anything: '', 'george', 'something' or even null.

Similarly, the _AppIsFullMac value is set on the basis of various values != to some values, and again, I bet those values are not the "opposites" you're expecting them to be.

mattleibow commented 3 weeks ago

The condition is working as the second part ``'$(_AppIsFullMac)' == 'True' is false. When running a build, there is no warning and there is also all the cases where the checks are running and there are no native references:

image

Also, switching to SDK-style projects does not mean switching to .net core, you can just convert the xml to the modern format, and keep the same net46/net47/net48 that you already have - and you can mix it up as well.

But again, this is not a build issue - just the IDE/solution explorer bug.

rozeboosje commented 3 weeks ago

Okay but it pollutes our "Error list" with spurious warnings. We are not in the habit of ignoring warnings as we've been bitten a few times before when an ignored warning led to an actual problem. With all these warnings cluttering the Error List we're risking missing one that DOES require our attention. If it's an IDE bug, where can I report that and ask the makers of Visual Studio to address it?

mattleibow commented 3 weeks ago

I even wrapped the whole <NativeReference> item in a <ItemGroup Condition=" 'cat' == 'dog' "> and the IDE still sees it.

You can use the VS feedback in the help menu or the image

I will try replicate this in a simple project for you to add a code snippet.

mattleibow commented 3 weeks ago

Managed to reproduce this with the simplest thing:

<ItemGroup Condition=" 'dog' == 'cat' ">
  <NativeReference Include="BadFile.dylib" />
</ItemGroup>

Add that near the end of your csproj and the warning will appear. The condition directly excludes this, yet it is still there in the IDE.

mattleibow commented 3 weeks ago

I think I found a hack to fix it:

<ItemGroup Condition=" 'dog' == 'cat' ">
  <NativeReference Include="BadFile.dylib" />
</ItemGroup>
<ItemGroup Condition=" 'dog' != 'cat' ">
  <NativeReference Remove="BadFile.dylib" />
</ItemGroup>

This is all sorts of wrong, but the IDE seems happier.

mattleibow commented 3 weeks ago

Let's see.

rozeboosje commented 3 weeks ago

Thank you so much for putting effort into this