You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Windows Docker容器构建C# WinUI自包含应用遇XamlCompiler错误-1073741515

错误码-1073741515的含义及修复方案

错误含义

错误码-1073741515对应Windows系统错误码0xC0000135,核心原因是XamlCompiler.exe找不到所需的运行时依赖——该工具基于.NET Framework 4.7.2开发,但你使用的mcr.microsoft.com/dotnet/sdk:6.0镜像默认基于Windows Nano Server,不包含.NET Framework环境,也缺少WinUI应用构建必需的Windows桌面组件,导致工具无法启动。

修复步骤

1. 强制指定构建架构(快速临时修复)

当前构建默认尝试编译arm64架构,但你的主机是x64的Windows 10,容器内缺少arm64的编译工具链。添加--arch x64参数指定架构,避免跨架构编译问题:

docker run `
  --platform windows `
  --rm `
  --interactive `
  --tty `
  --mount "type=bind,source=$PWD,target=C:\application" `
  --workdir /application `
  mcr.microsoft.com/dotnet/sdk:6.0 `
  dotnet publish --configuration Release --arch x64

2. 使用包含完整依赖的构建镜像(长期解决方案)

创建自定义Docker镜像,预装.NET 6 SDK、.NET Framework 4.7.2和Windows App SDK运行时,确保构建环境完整:

编写Dockerfile

FROM mcr.microsoft.com/windows/servercore:ltsc2022

# 安装.NET 6 SDK
RUN powershell -Command \
    Invoke-WebRequest -Uri https://dot.net/v1/dotnet-install.ps1 -OutFile dotnet-install.ps1; \
    ./dotnet-install.ps1 -Channel 6.0 -InstallDir C:\dotnet; \
    Remove-Item dotnet-install.ps1

ENV PATH="$PATH;C:\dotnet"

# 安装.NET Framework 4.7.2
RUN powershell -Command \
    Invoke-WebRequest -Uri https://download.microsoft.com/download/6/E/4/6E48E8AB-DC00-419E-9704-06DD46E5F81D/NDP472-KB4054530-x86-x64-AllOS-ENU.exe -OutFile NDP472.exe; \
    Start-Process -FilePath .\NDP472.exe -ArgumentList '/quiet /norestart' -Wait; \
    Remove-Item NDP472.exe

# 安装Windows App SDK 1.3运行时
RUN powershell -Command \
    Invoke-WebRequest -Uri https://aka.ms/windowsappsdk/1.3/windowsappruntimeinstall-x64.exe -OutFile WindowsAppRuntimeInstall.exe; \
    Start-Process -FilePath .\WindowsAppRuntimeInstall.exe -ArgumentList '/quiet' -Wait; \
    Remove-Item WindowsAppRuntimeInstall.exe

WORKDIR C:\application

构建镜像并运行构建

# 构建自定义镜像
docker build -t winui-build-env .

# 执行构建
docker run `
  --rm `
  --interactive `
  --tty `
  --mount "type=bind,source=$PWD,target=C:\application" `
  winui-build-env `
  dotnet publish --configuration Release --arch x64

3. 验证依赖是否安装完成

如果仍有问题,可以进入容器手动检查XamlCompiler.exe能否运行:

docker run `
  --platform windows `
  --rm `
  --interactive `
  --tty `
  mcr.microsoft.com/windows/servercore:ltsc2022 `
  cmd /k "C:\Users\ContainerUser\.nuget\packages\microsoft.windowsappsdk\1.3.230331000\tools\net472\XamlCompiler.exe"

如果弹出提示缺少clr.dll或其他.NET Framework相关文件,说明.NET Framework 4.7.2未正确安装,需重新执行安装步骤。

内容的提问来源于stack exchange,提问作者Trey Brisbane

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.14 07:52:33