Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Publishing WinUI 3 unpackaged desktop project project leads to Unable to load DLL 'Microsoft.WindowsAppRuntime.Bootstrap.dll' #7587

Closed
DanJBower opened this issue Apr 29, 2022 · 3 comments
Labels
bug needs-triage Have yet to determine what bucket this goes in.

Comments

@DanJBower
Copy link

Issue Description

When I add /p:PublishProfile=x64Profile to msbuild publish command, the .exe created does not open. On inspecting the windows event viewer, it reveals an exception was thrown trying to open the exe.

This is specifically for a WinUI 3 unpackaged desktop project.

Steps to Reproduce

A copy of a sample project can be found here: https://github.com/DanJBower/PusblishMcve

I added 2 batch files to demonstrate the issue

The steps I followed to set up the project were:

  1. Install the latest dotnet sdk preview, I'm using 6.0.300-preview.22204.3

  2. Install Windows App SDK 1.1 Preview 2

  3. Install the latest Microsoft Visual C++ Redistributable

  4. In Visual Studio Installer, make sure you have the following selected on Visual Studio 2022

    • Main Page

      • Universal Windows Platform development

        • C++ (v143) Universal Windows Platform tools
      • .NET Desktop Development

        • Windows App SDK C# Templates
      • Desktop development with C++

    • Individual Components Page

      • Windows 10 SDK (10.0.19041.0)
  5. Create a new C# Blank App, Packaged (WinUI 3 in Desktop) in Visual Studio 2022

  6. In the .csproj, add

     <WindowsPackageType>None</WindowsPackageType>
     <PublishSingleFile Condition="'$(Configuration)' == 'Release'">true</PublishSingleFile>
     <SelfContained>true</SelfContained>
     <RuntimeIdentifier>win-x64</RuntimeIdentifier>
     <PublishReadyToRun>true</PublishReadyToRun>
     <PublishTrimmed>false</PublishTrimmed>
     <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
     <DebugType Condition="'$(Configuration)' == 'Release'">None</DebugType>
     <DebugSymbols Condition="'$(Configuration)' == 'Release'">false</DebugSymbols>
     <PublishReadyToRunShowWarnings Condition="'$(Configuration)' == 'Release'">true</PublishReadyToRunShowWarnings>
    
  7. Run the publish command

     msbuild PusblishMcve.csproj -t:restore /t:Build;Publish /p:Configuration=Release /p:Platform=x64 /p:PublishProfile=x64Profile /p:OutputPath=.\Published
    

Running

msbuild PusblishMcve.csproj -t:restore /t:Build;Publish /p:Configuration=Release /p:Platform=x64 /p:OutputPath=.\Published

creates an exe I can use, however, it is not self-contained so there are 100s of files

Expected Behavior

It should create a single .exe file that opens

Actual Behavior

When opening in NotWorkingPusblished I get the error

Application: PusblishMcve.exe
CoreCLR Version: 6.0.322.12309
.NET Version: 6.0.3
Description: The process was terminated due to an unhandled exception.
Exception Info: System.TypeInitializationException: The type initializer for '<Module>' threw an exception.
 ---> System.DllNotFoundException: Unable to load DLL 'Microsoft.WindowsAppRuntime.Bootstrap.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
   at Microsoft.Windows.ApplicationModel.DynamicDependency.NativeMethods.MddBootstrapInitialize2(UInt32 majorMinorVersion, String versionTag, PackageVersion packageVersion, InitializeOptions options)
   at Microsoft.Windows.ApplicationModel.DynamicDependency.Bootstrap.TryInitialize(UInt32 majorMinorVersion, String versionTag, PackageVersion minVersion, InitializeOptions options, Int32& hresult)
   at Microsoft.Windows.ApplicationModel.DynamicDependency.BootstrapCS.AutoInitialize.AccessWindowsAppSDK()
   at .cctor()
   --- End of inner exception stack trace ---

When opening in NotWorkingPusblishedpublish, I get the error

Application: PusblishMcve.exe
CoreCLR Version: 6.0.322.12309
.NET Version: 6.0.3
Description: The process was terminated due to an unhandled exception.
Exception Info: System.TypeInitializationException: The type initializer for '<Module>' threw an exception.
 ---> System.DllNotFoundException: Dll was not found.
   at Microsoft.Windows.ApplicationModel.DynamicDependency.NativeMethods.MddBootstrapInitialize2(UInt32 majorMinorVersion, String versionTag, PackageVersion packageVersion, InitializeOptions options)
   at Microsoft.Windows.ApplicationModel.DynamicDependency.Bootstrap.TryInitialize(UInt32 majorMinorVersion, String versionTag, PackageVersion minVersion, InitializeOptions options, Int32& hresult)
   at Microsoft.Windows.ApplicationModel.DynamicDependency.BootstrapCS.AutoInitialize.AccessWindowsAppSDK()
   at .cctor()
   --- End of inner exception stack trace ---

Analysis

I'm afraid I don't know what the issue is. I also tried dotnet publish but that had different errors. msbuild#7452

Versions & Configurations

msbuild -version: 17.2.0.20702
dotnet --version: 6.0.300-preview.22204.3

@DanJBower DanJBower added bug needs-triage Have yet to determine what bucket this goes in. labels Apr 29, 2022
@benvillalobos
Copy link
Member

Team Triage: Is this a recent regression?

@marcpop do you know anyone on WinUI? This sounds like it could be MSBuild. Maybe it's not placing the bootstrap dll in the right place. It could also be WinUI targets

@sude22
Copy link

sude22 commented Jun 7, 2022

It would be very welcome if this error would be investigated.
Currently it is not possible to deloy a WinUI3 App unpacked as SingleFile via CI/DevOps.
Neither with msbuild nor with dotnet publish.

@benvillalobos
Copy link
Member

We're not confident this is an MSBuild bug, can you try filing the issue over at https://github.com/microsoft/windowsappsdk? Feel free to reopen if it turns out this is an msbuild issue.

@benvillalobos benvillalobos closed this as not planned Won't fix, can't repro, duplicate, stale Jul 28, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug needs-triage Have yet to determine what bucket this goes in.
Projects
None yet
Development

No branches or pull requests

3 participants