Skip to content

Commit

Permalink
feat: Add WPF SelfContained support
Browse files Browse the repository at this point in the history
  • Loading branch information
ebariche committed Aug 6, 2024
1 parent 5038a08 commit 81022c2
Showing 1 changed file with 9 additions and 7 deletions.
16 changes: 9 additions & 7 deletions src/Uno.UI.Runtime.Skia.Wpf/Builder/WpfHostBuilder.cs
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,7 @@ public WpfHostBuilder()
{
if (Environment.OSVersion.Platform == PlatformID.Win32NT)
{
RegisterAssemblyResolver();
RegisterAssemblyResolver(UseSharedFramework);
}
}

Expand Down Expand Up @@ -56,7 +56,7 @@ private static void AdjustPath(string dotnetSharedDirectory, string runtimeVersi
}
}

private void RegisterAssemblyResolver()
private void RegisterAssemblyResolver(bool useSharedFramework)
{
AssemblyLoadContext.Default.Resolving += OnAssemblyResolving;

Expand All @@ -71,12 +71,11 @@ private void RegisterAssemblyResolver()
var version = Path.GetFileName(Path.GetDirectoryName(uri.LocalPath))!;
var dotnetShared = Path.Combine(Path.GetDirectoryName(uri.LocalPath)!, "..", "..");

_windowsDesktopFrameworkPath = Path.GetFullPath(Path.Combine(
dotnetShared,
"Microsoft.WindowsDesktop.App",
version));
_windowsDesktopFrameworkPath = useSharedFramework ?
Path.GetFullPath(Path.Combine(dotnetShared, "Microsoft.WindowsDesktop.App", version)) :
Path.Combine(Path.GetDirectoryName(typeof(object).Assembly.Location)!, "Microsoft.WindowsDesktop.App");

if (!Directory.Exists(_windowsDesktopFrameworkPath))
if (useSharedFramework && !Directory.Exists(_windowsDesktopFrameworkPath))
{
AdjustPath(dotnetShared, version, ref _windowsDesktopFrameworkPath);
}
Expand Down Expand Up @@ -160,6 +159,9 @@ private static void LoadNativeImage(string image)
public bool IsSupported
=> OperatingSystem.IsWindows();

private static bool UseSharedFramework
=> AppContext.TryGetSwitch("UseSharedWpfFramework", out var enabled) ? enabled : true;

Func<Application>? IWindowsSkiaHostBuilder.WpfApplication
{
get => _wpfApplication;
Expand Down

0 comments on commit 81022c2

Please sign in to comment.