通用 Windows 应用程序项目中的 MSBuild 错误

4

我目前在使用Visual Studio 2015构建通用Windows应用时遇到了问题。每当我尝试编译我的项目时,都会出现以下错误:

Child node "2" exited prematurely. Shutting down. Diagnostic information may be found in files in the temporary files directory named MSBuild_*.failure.txt.

每当应用程序中存在XAML文件时,就会出现此错误。无论这些文件包含什么内容都不重要。一个单独的空XAML文件,其构建操作设置为PageApplicationDefinition就足以导致此错误出现。

进一步查看诊断日志,似乎错误发生在CompileXaml任务中,具有以下异常:

Unhandled Exception: System.AccessViolationException: Attempted to read or write protected memory. This is often an indication that other memory is corrupt.
   at Microsoft.Windows.UI.Xaml.Build.Tasks.NativeMethods.WriteWithCheckSum(IStream[] xamlStreams, Int32 numFiles, String[] pbChecksum, Int32 checksumSize, IXbfMetadataProvider provider, TargetOSVersion targetVersion, UInt32 xbfGenerationFlags, IStream[] xbfStreams, Int32& errorCode, Int32& errorFileIndex, Int32& errorLine, Int32& errorColumn)
   at Microsoft.Xaml.XBF.XbfGenerator.GenerateXbfFromStreams(IStream[] inputStreams, IStream[] outputStreams, UInt32 xbfGenerationFlags, String[] checksums, TargetOSVersion targetOS, Int32& errorCode, Int32& errorFile, Int32& errorLine, Int32& errorPosition)
   at Microsoft.Xaml.XBF.XbfGenerator.GenerateAll(String targetPlatformVersion, UInt32 xbfGenerationFlags)
   at Microsoft.Xaml.XBF.XbfGenerator.GenerateXbfFiles(String targetPlatformVersion, UInt32 xbfGenerationFlags, Boolean v80Compat)
   at Microsoft.Windows.UI.Xaml.Build.Tasks.CompileXamlInternal.GenerateXbfFiles(List`1 xamlList)
   at Microsoft.Windows.UI.Xaml.Build.Tasks.CompileXamlInternal.DoExecute()
   at Microsoft.Windows.UI.Xaml.Build.Tasks.CompileXaml.Execute()

这个异常的原因可能是什么?

已经采取了以下故障排除步骤,但效果不佳:

  • 重启电脑
  • 重新安装Visual Studio和.NET框架
  • 从命令行构建
  • 以管理员身份启动VS(或命令行)

你尝试过重新启动电脑吗?同时尝试修复.NET Framework和Visual Studio安装。 - Camilo Terevinto
是的。我尝试了完整重新安装Visual Studio 2015和.NET框架,但无济于事。 - Leon Lucardie
尝试以管理员身份运行VS。 - Camilo Terevinto
另外,您是使用调试还是发布配置进行构建? - Camilo Terevinto
1
你是否遇到了类似于这里提到的情况(http://thomasmartinsen.com/2015/01/13/child-node-exited-prematurely-shutting-down/),即您可能正在将旧的东西移植到UWP上,但忘记了某个处理程序,该处理程序虽然不存在,但仍然在某个模板中? - Chris W.
显示剩余5条评论
1个回答

2
在Chris W.的评论中,通过这篇文章的帮助下,我成功解决了问题。在这种情况下,错误表明项目中的一个ResourceDictionary存在问题。
事实证明,我的项目中有一个ResourceDictionary包含了重复的命名空间声明。
<ResourceDictionary
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:local="using:MyApp.UAP.Base">

    <Style TargetType="local:TTBasePage"  xmlns:local="using:MyApp.UAP.Base"> <!-- This line caused  the error -->
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="local:TTBasePage">
                    <Border
                        Background="{TemplateBinding Background}"
                        BorderBrush="{TemplateBinding BorderBrush}"
                        BorderThickness="{TemplateBinding BorderThickness}">
                    </Border>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
</ResourceDictionary>

移除重复的命名空间声明可以解决构建错误。

根据文章所述,这也可能是由其他ResourceDictionary相关问题引起的(例如模板上的无效事件处理程序等)。


网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接