Repository navigation
Description
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
GlobalStaticResourcesthat 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
GlobalStaticResourcesalready initializes every assembly it references).
How to reproduce it (as minimally and precisely as possible) 🔬
- Create an Uno.Sdk class library that lists
SkiainUnoFeaturesand contains one XAML file (e.g. aUserControl) but no code that uses SkiaSharp orSKCanvasElement. dotnet packit.- The built
.dllreferencesUno.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