microsoft / microsoft-ui-xaml

Windows UI Library: the latest Windows 10 native controls and Fluent styles for your applications
MIT License
6.31k stars 676 forks source link

WinUI 3 - Blank App, Packaged with Windows Application Packaging Project (WinUI 3 in Desktop) - The App Package generated cannot be started #9740

Closed jvecc closed 2 months ago

jvecc commented 3 months ago

Describe the bug

The Visual Studio Template "Blank App, Packaged with Windows Application Packaging Project (WinUI 3 in Desktop)" does not build a proper msix package when using the WapProject to do so. Whether in Debug or Release, when trying to run a package built by this template (as a separated project), it never starts.

When looking at the EventViewer >Windows Logs > Application: We can see a sequence of errors and informations related to the App. image

I attached the details for those 5 Event Logs. EventLog.txt

I would assume this could be related to #9675 - but I do not want to make the wrong assumptions as I tried the suggested workaround mentioned here - without success.

Steps to reproduce the bug

  1. Create a new "Blank App, Packaged with Windows Application Packaging Project (WinUI 3 in Desktop)" from Visual Studio called App1
  2. Modify the win-x64.pubxml to replace win10-x64 to win-x64 on line 10 (otherwise the publish of the .Net application does not work)
  3. Right Click on the package App1 (Package), then Publish the Package app as a sideloading application (either Debug or Release x64) using a self-signed certificate.
  4. When the package is built, try to install it with the "Install.ps1" provided alongside with the package

Expected behavior

The App1 application embedded within the package starts properly (in our case, the basic default UI)

Screenshots

No response

NuGet package version

WinUI 3 - Windows App SDK 1.5.4: 1.5.240607001

Windows version

Windows Insider Build (xxxxx)

Additional context

Windows Insider Build version: 26120.961 Microsoft.Windows.SDK.BuildTools: 1.5.240607001 Microsoft.WindowsAppSDK: 1.5.240607001 DotNet Sdk used to build: 8.0.301

Visual Studio Version : 17.11.0 Preview 1.1

Target Frameworks / Platforms App1

net8.0-windows10.0.19041.0 10.0.17763.0

App1 (Package)

10.0.19041.0 10.0.17763.0
github-actions[bot] commented 3 months ago

Hi I'm an AI powered bot that finds similar issues based off the issue title.

Please view the issues below to see if they solve your problem, and if the issue describes your problem please consider closing this one. Thank you!

Open similar issues:

Closed similar issues:

Note: You can give me feedback by thumbs upping or thumbs downing this comment.

IsmailHassani commented 3 months ago

I also tried several options and builds. The strange thing that unpackaged app in release mode works fine. Only packaged output causes these issues. The same behavior i noticed in .Net Maui (Windows) which caused me to use the win10-x64 runtime with -p:UseRidGraph=true build parameter. In WinUI this trick didn't help, but something is wrong for a while now.

ghostidentity commented 3 months ago

@jvecc have you tried this ? https://github.com/microsoft/microsoft-ui-xaml/issues/9675#issuecomment-2183960887

jvecc commented 3 months ago

@ghostidentity unfortunately, I cannot review your document as it is not publicly accessible. Could please make it accessible to everyone ? Thanks

ghostidentity commented 3 months ago

@ghostidentity unfortunately, I cannot review your document as it is not publicly accessible. Could please make it accessible to everyone ? Thanks

done try again https://drive.google.com/file/d/1XTKQTb6-pbjYkf6yX8FKS00ZpTwgy1ze/view?usp=sharing

jvecc commented 3 months ago

@ghostidentity - I tried to update my project and it worked as you mentioned. But working on such a newer version of Windows would not be possible for me. Therefore I tried to go with something a little lower :

    <TargetPlatformVersion>10.0.20348.0</TargetPlatformVersion>
    <TargetPlatformMinVersion>10.0.19041.0</TargetPlatformMinVersion>

And it also worked ! 😃

Although, based on the MS Documentation:

WinUI 3 works downlevel to Windows 10 October 2018 Update (Version 1809, OS build 17763).

Is there something that should be done, either on the documentation or else?

Scottj1s commented 3 months ago

@jvecc Thanks for your report. Unfortunately, I cannot repro this issue, based on the instructions provided. If you're seeing it as well with Debug configuration, that would rule out any trimming-related problems (such as https://github.com/microsoft/microsoft-ui-xaml/issues/9675).

The event log includes this error: Exception Info: System.DllNotFoundException: Unable to load DLL 'Microsoft.ui.xaml.dll' or one of its dependencies: The specified module could not be found. (0x8007007E) This is not a trimming-related issue, as Microsoft.ui.xaml.dll is a native DLL. Instead it indicates that Install.ps1 was unable to install ".\Dependencies\x64\Microsoft.WindowsAppRuntime.1.5.msix". Do you see any errors when you run Install.ps1? If so, you could attempt to directly install (via double-click) first the WindowsAppRuntime framework package msix, and then the app msix.

If none of this helps root cause, please provide a repro project.

jvecc commented 2 months ago

Hi @Scottj1s - apologies for the delay in responding to your last comment.

AFAIK, the issue was related to the version of the Win App SDK I was using in my project.

Basically, the problem still stands when I start from a blank application (Blank App, Packaged with WAP), try to build a side-loading app (in Debug), and try to start it. Per your suggestion, I put a project together that you can find here : https://github.com/jvecc/gh-issue-9740-repro

This is where I get the same issue : image

Scottj1s commented 2 months ago

Hi @jvecc, thanks for your patience. I was able to repro with your project.

The issue is indeed related to trimming, and the recommendations are the same as reported here: https://github.com/microsoft/microsoft-ui-xaml/issues/9675:

  1. Set PublishTrimmed to False and/or
  2. Update to WinAppSDK 1.6 when available, for full trimming support

The reason this also affects Debug configurations, is due to another issue. Conditional expressions in publish profiles (pubxml files) are not supported across project references. This surfaces when a solution has a wapproj referencing the app project. In this situation, the last assignment of PublishTrimmed in the pubxml applies, regardless of the condition: <PublishTrimmed Condition="'$(Configuration)' != 'Debug'">True</PublishTrimmed>

The workaround for this is to move all such conditional assignments from the pubxml to the app's csproj files. The Windows App SDK templates have been fixed to address this and will be included in Visual Studio 17.12.

Scottj1s commented 2 months ago

Closing with suggested workarounds - please reopen if these aren't effective