Skip to content

Self-contained deployment breaks WinUI codegen in libraries #6091

@dongle-the-gadget

Description

@dongle-the-gadget

Describe the bug

When WindowsAppSDKSelfContained is enabled in a library project, it causes a codegen error in WinUI (XAML).

Steps to reproduce the bug

  1. Clone https://github.com/dongle-the-gadget/WinUISelfCrash and open WinUISelfCrash.slnx
  2. Run the main app project (WinUISelfCrash), observe that it runs as normal with a "Hello world" button in the middle
  3. Close the app, clean the solution, and set WindowsAppSDKSelfContained to true in the WinUISelfCrashLib (Library) project
  4. Run the app again, observe Microsoft.UI.Xaml.Markup.XamlParseException: 'XAML parsing failed.'
  5. Delete WindowsAppSDKSelfContained from the library project and clean the solution once more.
  6. Open up a command line and navigate it to the repository.
  7. Run dotnet msbuild /p:Platform=[platform] /p:WindowsAppSDKSelfContained=true, replacing [platform] with your machine's architecture.
  8. Run the app and see that it fails to launch (briefly hanging with waiting cursor before turning back to normal)

Expected behavior

The app should launch normally regardless of whether WindowsAppSDKSelfContained is set to true in the library project.

Screenshots

No response

NuGet package version

Windows App SDK 1.8.3: 1.8.251106002

Packaging type

Unpackaged

Windows version

Insider Build (xxxxx)

IDE

No response

Additional context

This is caused by _OverrideGetPriIndexName in Microsoft.WindowsAppSDK.SelfContained.targets file in Microsoft.WindowsAppSDK.Base NuGet, which doesn't check if it's in a library, and hence will set the PRI root to empty (which should be used for apps and not libraries)

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions