[BUG] SkiaSharp 2.88.0 PackageReference break csproj pack logic
Description
When referencing the SkiaSharp package (2.88.0) in a csproj where NuGet pack is enabled using
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
The following errors are generated
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\skiasharp.nativeassets.win32\2.88.0\runtimes\win-x86\native\libSkiaSharp.dll' is not added because the package already contains file 'content\libSkiaSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\skiasharp.nativeassets.win32\2.88.0\runtimes\win-x86\native\libSkiaSharp.dll' is not added because the package already contains file 'contentFiles\any\net472\libSkiaSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\skiasharp.nativeassets.win32\2.88.0\runtimes\win-x64\native\libSkiaSharp.dll' is not added because the package already contains file 'content\libSkiaSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\skiasharp.nativeassets.win32\2.88.0\runtimes\win-x64\native\libSkiaSharp.dll' is not added because the package already contains file 'contentFiles\any\net472\libSkiaSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\skiasharp.nativeassets.win32\2.88.0\runtimes\win-x64\native\libSkiaSharp.dll' is not added because the package already contains file 'content\libSkiaSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\skiasharp.nativeassets.win32\2.88.0\runtimes\win-x64\native\libSkiaSharp.dll' is not added because the package already contains file 'contentFiles\any\net472\libSkiaSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\skiasharp.nativeassets.win32\2.88.0\runtimes\win-arm64\native\libSkiaSharp.dll' is not added because the package already contains file 'content\libSkiaSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\skiasharp.nativeassets.win32\2.88.0\runtimes\win-arm64\native\libSkiaSharp.dll' is not added because the package already contains file 'contentFiles\any\net472\libSkiaSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\skiasharp.nativeassets.win32\2.88.0\runtimes\win-arm64\native\libSkiaSharp.dll' is not added because the package already contains file 'content\libSkiaSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\skiasharp.nativeassets.win32\2.88.0\runtimes\win-arm64\native\libSkiaSharp.dll' is not added because the package already contains file 'contentFiles\any\net472\libSkiaSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\harfbuzzsharp.nativeassets.win32\2.8.2.3\runtimes\win-x86\native\libHarfBuzzSharp.dll' is not added because the package already contains file 'content\libHarfBuzzSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\harfbuzzsharp.nativeassets.win32\2.8.2.3\runtimes\win-x86\native\libHarfBuzzSharp.dll' is not added because the package already contains file 'contentFiles\any\net472\libHarfBuzzSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\harfbuzzsharp.nativeassets.win32\2.8.2.3\runtimes\win-x64\native\libHarfBuzzSharp.dll' is not added because the package already contains file 'content\libHarfBuzzSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\harfbuzzsharp.nativeassets.win32\2.8.2.3\runtimes\win-x64\native\libHarfBuzzSharp.dll' is not added because the package already contains file 'contentFiles\any\net472\libHarfBuzzSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\harfbuzzsharp.nativeassets.win32\2.8.2.3\runtimes\win-x64\native\libHarfBuzzSharp.dll' is not added because the package already contains file 'content\libHarfBuzzSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\harfbuzzsharp.nativeassets.win32\2.8.2.3\runtimes\win-x64\native\libHarfBuzzSharp.dll' is not added because the package already contains file 'contentFiles\any\net472\libHarfBuzzSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\harfbuzzsharp.nativeassets.win32\2.8.2.3\runtimes\win-arm64\native\libHarfBuzzSharp.dll' is not added because the package already contains file 'content\libHarfBuzzSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\harfbuzzsharp.nativeassets.win32\2.8.2.3\runtimes\win-arm64\native\libHarfBuzzSharp.dll' is not added because the package already contains file 'contentFiles\any\net472\libHarfBuzzSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\harfbuzzsharp.nativeassets.win32\2.8.2.3\runtimes\win-arm64\native\libHarfBuzzSharp.dll' is not added because the package already contains file 'content\libHarfBuzzSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5118: File 'C:\Users\username\.nuget\packages\harfbuzzsharp.nativeassets.win32\2.8.2.3\runtimes\win-arm64\native\libHarfBuzzSharp.dll' is not added because the package already contains file 'contentFiles\any\net472\libHarfBuzzSharp.dll'
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5100: The assembly 'content\libSkiaSharp.dll' is not inside the 'lib' folder and hence it won't be added as a reference when the package is installed into a project. Move it into the 'lib' folder if it needs to be referenced.
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5100: The assembly 'contentFiles\any\net472\libSkiaSharp.dll' is not inside the 'lib' folder and hence it won't be added as a reference when the package is installed into a project. Move it into the 'lib' folder if it needs to be referenced.
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5100: The assembly 'content\libHarfBuzzSharp.dll' is not inside the 'lib' folder and hence it won't be added as a reference when the package is installed into a project. Move it into the 'lib' folder if it needs to be referenced.
C:\Program Files\dotnet\sdk\6.0.407\Sdks\NuGet.Build.Tasks.Pack\build\NuGet.Build.Tasks.Pack.targets(221,5): error NU5100: The assembly 'contentFiles\any\net472\libHarfBuzzSharp.dll' is not inside the 'lib' folder and hence it won't be added as a reference when the package is installed into a project. Move it into the 'lib' folder if it needs to be referenced.
0 Warning(s)
24 Error(s)
Code
<ItemGroup>
<PackageReference Include="HarfBuzzSharp" />
<PackageReference Include="ReactiveUI" />
<PackageReference Include="SkiaSharp" />
<PackageReference Include="Topten.RichTextKit" />
</ItemGroup>
<PropertyGroup>
<GeneratePackageOnBuild>true</GeneratePackageOnBuild>
</PropertyGroup>
Workarround Adding these properties to my csproj ensure the native files are not added as content
<!-- Workarround to ensure the Native files of SkiaSharp and Harfbuzz are not included in the package -->
<ShouldIncludeNativeSkiaSharp>False</ShouldIncludeNativeSkiaSharp>
<ShouldIncludeNativeHarfBuzzSharp>False</ShouldIncludeNativeHarfBuzzSharp>
Expected Behavior
I expect a NuGet package of my assembly is generated containing my assembly and a dependency on the SkiaSharp package. The assemblies part of the SkiaSharp and Harfbuzz packages should not be considered as input files to pack.
Actual Behavior
MSBuild fails with the below error. The SkiaSharp (and HarfBuzz) win32 package is injecting the native assemblies as content. Which is picked up by MSBuild.
Possible solution
The build targets included in the package contain logic to have it included as content. One solution could be to use a None include instead of a Content included Another solution could be to also set the Pack attribute, to ensure the content files is not considered as a file to pack.
<!-- include everything -->
<Content Include="@(_NativeSkiaSharpFile)">
<Link>%(Dir)%(Filename)%(Extension)</Link>
<Visible>False</Visible>
<CopyToOutputDirectory>PreserveNewest</CopyToOutputDirectory>
<Pack>False</Pack>
</Content>
Basic information Using Visual Studio 2022 17.4 and .NET 6 SDK version 6.0.407
I have a similar behavior with the native SkiaSharp libraries being included throughout all transitive dependencies Ex: AppA -> LibA -> LibB -> SkiaSharp
AppA, LibA and LibB will all embed the native dependencies in the nupkg, even when AppA end LibA are pulling it transitively
I also just stumbled upon this issue.
I have added the following code to Directory.Build.targets, but would prefer to have the Pack property set in the nuget's .props file, as is outlined in the bug report as a possible solution.
<ItemGroup>
<Content Update="@(_NativeSkiaSharpFile)">
<Pack>False</Pack>
</Content>
</ItemGroup>
Setting ShouldIncludeNativeSkiaSharp to False is not an option in my case because I need to run my application from the bin folder.
This problem still occurs when building NuGet-Packages. I'm using version 2.88.6. Sometimes, but not always, an error occurs during compilation when the compiler tries to copy the DLLs into the bin directory.
We also have to start our application from the bin folder, but we also pack NuGet packages for some assemblies.
Is there a satisfying solution for this?