Setting up Uno for Skia WPF

1k Views Asked by At

I'm having trouble getting my project to compile with Uno using the Skia/WPF runtime. I would have used UWP, but I need some hardware access that UWP limits. This is my .csproj file, loosely pasted together from the Skia WPF sample in the repo, and the GTK project from Uno Calculator:

<Project Sdk="MSBuild.Sdk.Extras/2.0.54">

    <PropertyGroup>
        <OutputType>Exe</OutputType>
        <TargetFrameworks>net472;netcoreapp3.1</TargetFrameworks>
        <UseWPF>true</UseWPF>
        <Platforms>AnyCPU;x86;x64</Platforms>
        <UnoSourceGeneratorUseGenerationHost>true</UnoSourceGeneratorUseGenerationHost>
        <UnoSourceGeneratorUseGenerationController>false</UnoSourceGeneratorUseGenerationController>
    </PropertyGroup>

    <ItemGroup Condition="'$(TargetFramework)'=='net472'">
        <Reference Include="System" />
        <Reference Include="System.Data" />
        <Reference Include="System.Xml" />
        <Reference Include="Microsoft.CSharp" />
        <Reference Include="System.Core" />
        <Reference Include="System.Xml.Linq" />
        <Reference Include="System.Data.DataSetExtensions" />
        <Reference Include="System.Net.Http" />
        <Reference Include="System.Xaml">
            <RequiredTargetFramework>4.0</RequiredTargetFramework>
        </Reference>
        <Reference Include="WindowsBase" />
        <Reference Include="PresentationCore" />
        <Reference Include="PresentationFramework" />
    </ItemGroup>

    <ItemGroup>
        <PackageReference Include="Uno.SourceGenerationTasks" Version="3.0.0-dev.16" />
        <PackageReference Include="Uno.UI.Skia.Wpf" Version="3.2.0-dev.206" />
        <PackageReference Include="Microsoft.Extensions.Logging.Console" Version="1.1.1" />
        <PackageReference Include="Microsoft.Extensions.Logging.Filter" Version="1.1.1" />
    </ItemGroup>


    <Import Project="..\UiProject.Shared\UiProject.Shared.projitems" Label="Shared" />
</Project>

I'm getting the following errors:

1>------ Build started: Project: UiProject.Skia.Wpf, Configuration: Debug x86 ------
1><repo>\UiProject.Skia.Wpf\UiProject.Skia.Wpf.csproj : warning NU1701: Package 'SkiaSharp.Views 2.80.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
1><repo>\UiProject.Skia.Wpf\UiProject.Skia.Wpf.csproj : warning NU1701: Package 'SkiaSharp.Views 2.80.0' was restored using '.NETFramework,Version=v4.6.1, .NETFramework,Version=v4.6.2, .NETFramework,Version=v4.7, .NETFramework,Version=v4.7.1, .NETFramework,Version=v4.7.2, .NETFramework,Version=v4.8' instead of the project target framework '.NETCoreApp,Version=v3.1'. This package may not be fully compatible with your project.
1><repo>\UiProject.Shared\App.xaml.cs(25,19,25,22): error CS0263: Partial declarations of 'App' must not specify different base classes
1><repo>\UiProject.Shared\MainPage.xaml.cs(24,33,24,41): error CS0263: Partial declarations of 'MainPage' must not specify different base classes
1><repo>\UiProject.Shared\App.xaml.cs(48,33,48,43): error CS0115: 'App.OnLaunched(LaunchActivatedEventArgs)': no suitable method found to override
1>Done building project "UiProject.Skia.Wpf.csproj" -- FAILED.
1><repo>\UiProject.Shared\App.xaml.cs(25,19,25,22): error CS0263: Partial declarations of 'App' must not specify different base classes
1><repo>\UiProject.Shared\MainPage.xaml.cs(24,33,24,41): error CS0263: Partial declarations of 'MainPage' must not specify different base classes
1><repo>\UiProject.Shared\App.xaml.cs(48,33,48,43): error CS0115: 'App.OnLaunched(LaunchActivatedEventArgs)': no suitable method found to override
1>Done building project "UiProject.Skia.Wpf.csproj" -- FAILED.
========== Build: 0 succeeded, 1 failed, 4 up-to-date, 0 skipped ==========

It looks like the XAML is compiling with .NET's assemblies, but the code is compiling with Uno's assemblies. I'm not sure how to resolve this. Is there any actual working Skia WPF example I can reference that is using NuGet references?

1

There are 1 best solutions below

0
On

Don't bother with the Visual Studio template, it's outdated. Instead, use the dotnet new template and the correct projects will be generated. See the VSCode setup instructions.