Search code examples
.net-standard-2.0avaloniauiavalonia

Using Avalonia with netstandard


I try to run my Avalonia app on .net framework. However, when I downgrade targetframework to netstandard2.0, AppBuilder becomes unavailable and I just couldn't figure out, how to fix that problem.

I couldn't find any template, that targets .net framework or netstandard. Documentation contains nothing regarding this issue. The only thing I could find is this Github issue. As I understood, AppBuilder is not supposed to be used in netstandard. Then, what is proper replacement for following code?

public static AppBuilder BuildAvaloniaApp()
    => AppBuilder.Configure<App>()
    .UsePlatformDetect()
    .LogToTrace()
    .UseReactiveUI();

Edit:

As it was pointed out, netstandard can't be used as a target for Avalonia apps, but we can specify multiple targets. So I replaced

<TargetFramework>net7.0</TargetFramework>

with

<TargetFrameworks>net7.0;net48</TargetFrameworks>

And it worked on .NET core and .NET Framework


Solution

  • netstandard2.0 isn't an actual .NET framework version: it's a specification of the common API beteen .NET framework 4.6.1 and .NET core 2.0 (among others). As such netstandard2.0 only makes sense as the target framework for libraries, not applications.

    If you want your app to target .NET framework then you need to use a .NET framework version as the target framework, for example net48 for .NET Framework 4.8.