系统相关
首页 > 系统相关> > c# – 通用Windows应用程序项目中的MSBuild错误

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

作者:互联网

我目前在使用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文件,就会发生此错误.文件包含的内容无关紧要.将其构建操作设置为Page或ApplicationDefinition的单个空XAML文件足以显示此错误.

进一步查看诊断日志似乎在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(或命令行)

解决方法:

在Chris W.的评论中,在this article的帮助下,我能够弄明白.在这种情况下,错误表示项目中的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相关问题(模板上的无效事件处理程序等)引起.

标签:c,msbuild,xaml,windows-10-universal
来源: https://codeday.me/bug/20190702/1356751.html