“Microsoft.ui.xaml.dll”无法加载

BAR*_*BAR 15 visual-studio winui-3

我的 WinUI3 应用程序出现Microsoft.ui.xaml.dll无法加载的异常。我已将 Microsoft.UI.Xaml 和 Microsoft.Graphics.Win2D 包含在 nuget 中。

System.DllNotFoundException
  HResult=0x80131524
  Message=Unable to load DLL 'Microsoft.ui.xaml.dll' or one of its dependencies: The specified module could not be found. (0x8007007E)
  Source=TibraUI
  StackTrace:
   at TibraUI.Program.XamlCheckProcessRequirements()
   at TibraUI.Program.Main(String[] args) in C:\Users\Bryan\src\tibra\Tibra\TibraUI\obj\x64\Debug\net6.0-windows10.0.19041.0\win10-x64\App.g.i.cs:line 28
Run Code Online (Sandbox Code Playgroud)

Windows 版本 21H1 内部版本 19043.1348

我的应用程序.xaml

<Application
    x:Class="TibraUI.App"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:TibraUI">
    <Application.Resources>
        <ResourceDictionary>
            <ResourceDictionary.MergedDictionaries>
                <XamlControlsResources xmlns="using:Microsoft.UI.Xaml.Controls" />
                <!-- Other merged dictionaries here -->
            </ResourceDictionary.MergedDictionaries>
            <!-- Other app resources here -->
        </ResourceDictionary>
    </Application.Resources>
</Application>
Run Code Online (Sandbox Code Playgroud)

N-a*_*ate 18

将包作为启动项目运行。这并不直观,但主项目并不意味着要运行。

这个答案仅适用于那些创建了包含包项目的项目的人。

  • 我该怎么做呢? (3认同)

X-M*_*aya 13

在应用程序项目文件的主 PropertyGroup 内,添加<WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>如下所示。

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net6.0-windows10.0.19041.0</TargetFramework>
    <TargetPlatformMinVersion>10.0.17763.0</TargetPlatformMinVersion>
    <RootNamespace>EPicker</RootNamespace>
    <ApplicationManifest>app.manifest</ApplicationManifest>
    <Platforms>x86;x64;arm64</Platforms>
    <RuntimeIdentifiers>win10-x86;win10-x64;win10-arm64</RuntimeIdentifiers>
    <PublishProfile>win10-$(Platform).pubxml</PublishProfile>
    <UseWinUI>true</UseWinUI>
    <EnableMsixTooling>true</EnableMsixTooling>
    <WindowsAppSDKSelfContained>true</WindowsAppSDKSelfContained>
  </PropertyGroup>

Run Code Online (Sandbox Code Playgroud)