Skip to content

[XAML generator] Generated GlobalStaticResources hard-references every add-in a library is compiled against #25612

Open

Description

@Xiaoy312

Current behavior 🐛

The generated GlobalStaticResources of every Uno library calls GlobalStaticResources.Initialize() (and RegisterDefaultStyles / RegisterResourceDictionariesBySource) on every referenced assembly that references Uno.UI and has a *GlobalStaticResources type (BuildAmbientResources(), emitted calls). Each call is a hard IL reference, so a library's DLL references every Uno add-in it was compiled against, whether or not it uses anything from it.

This includes add-ins with nothing to initialize. Uno.WinUI.Graphics2DSK contains no XAML, but its project imports the XAML generator, so it ships an empty public GlobalStaticResources. A library compiled against it (for example to use SKCanvasElement) references Uno.WinUI.Graphics2DSK.dll from its generated code, and an app can only drop the add-in (and SkiaSharp with it) if no library it uses was compiled against it.

With an upcoming Uno.Sdk change (branch dev/xygu/20261020/dont-imply-skia-on-libs), the Uno.Sdk no longer adds the Skia packages to a library that doesn't list the Skia feature, so most libraries no longer hit this. It remains for a library that lists Skia, and for any library that keeps an add-in out of its NuGet dependencies with PrivateAssets while still compiling against it.

Expected behavior 🎯

A library's DLL doesn't reference an add-in only because the add-in was on its compile references. Either:

  • an assembly with no XAML doesn't contribute a GlobalStaticResources that others chain into (for Graphics2DSK: drop the generator import, or have the generator emit nothing to chain into when there is no XAML), and/or
  • the chaining doesn't produce hard references to assemblies that may be absent at run time (the app's own GlobalStaticResources already initializes every assembly it references).

How to reproduce it (as minimally and precisely as possible) 🔬

  1. Create an Uno.Sdk class library that lists Skia in UnoFeatures and contains one XAML file (e.g. a UserControl) but no code that uses SkiaSharp or SKCanvasElement.
  2. dotnet pack it.
  3. The built .dll references Uno.WinUI.Graphics2DSK (visible with ILSpy, or by searching its metadata strings).

Workaround 🛠️

Don't list Skia in a library that doesn't draw with SkiaSharp, or remove the add-in with PackageReference Remove before compilation. Marking it PrivateAssets isn't enough: the library is still compiled against it, so it fails to load in an app without the add-in.

Affected platforms 📱💻🖥️

Build tasks

Uno.Sdk version (and other relevant versions) 📦

Uno.Sdk 7.0 (master @ 3888a8cfe4)

IDE version 🧑‍💻

N/A

Anything else we need to know? 💬

Changing what Uno.WinUI.Graphics2DSK exposes needs care: libraries already compiled against it call Uno.WinUI.Graphics2DSK.GlobalStaticResources.Initialize(), so removing that type outright would make them fail to load. A generator-side fix (stop chaining into assemblies with no XAML, or stop emitting hard calls) avoids that.

Activity

  1. added
    triage/untriaged
    on Oct 21, 2026
  2. removed
    triage/untriaged
    on Oct 29, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions