当 运行 一个 MsBuild.exe 命令作为服务时,如何修复 "error APPX0002: Task 'ValidateAppxManifest' failed" 错误?

How to fix "error APPX0002: Task 'ValidateAppxManifest' failed" error when running an MsBuild.exe command as a service?

我尝试运行 MSBuild 命令从 azure TFS 构建步骤打包 UWP 应用程序。

"C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild.0\Bin\MSBuild.exe" "C:\TFSagent\_work\s\MyProject.sln" /t:Build /p:Configuration=master /p:Platform=x86"

当我登录到远程 VM 代理时,这个命令执行得很好,我只是执行命令:包创建得很好。

但是当通过 运行 作为服务的 TFS 代理执行命令时,我收到以下错误:

2019-06-16T22:15:16.0141845Z C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild\Microsoft\VisualStudio\v15.0\AppxPackage\Microsoft.AppXPackage.Targets(2638,5): error APPX0002: Task 'ValidateAppxManifest' failed. Namespace prefix 'm' is not defined. [C:\TFSagent\_work\s\MyProject.vcxproj]
2019-06-16T22:15:16.0142853Z C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild\Microsoft\VisualStudio\v15.0\AppxPackage\Microsoft.AppXPackage.Targets(2638,5): error APPX0002:  [C:\TFSagent\_work\s\MyProject.vcxproj]
2019-06-16T22:15:16.9689847Z C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild\Microsoft\VisualStudio\v15.0\AppxPackage\Microsoft.AppXPackage.Targets(2638,5): error MSB4018: The "ValidateAppxManifest" task failed unexpectedly. [C:\TFSagent\_work\s\MyProject.vcxproj]
2019-06-16T22:15:16.9690436Z C:\Program Files (x86)\Microsoft Visual Studio17\Professional\MSBuild\Microsoft\VisualStudio\v15.0\AppxPackage\Microsoft.AppXPackage.Targets(2638,5): error MSB4018: System.Xml.XPath.XPathException: Namespace prefix 'm' is not defined. [C:\TFSagent\_work\s\MyProject.vcxproj]
...

运行:Microsoft Visual Studio Team Foundation Server 版本 16.131.28507.4

代理设置为服务,在 windows 10 虚拟机上,使用本地用户,被授予管理员权限。

构建步骤就像命令行执行上面的命令一样简单。 我试过添加 /nodeReuse:false /m:1.

在相应的清单中没有使用任何 'm' 命名空间(并且当它在 运行nning 'by hand' 时工作,我想清单本身是好的)

我只是希望命令在 运行来自用户或服务时同样有效。

编辑 1:

我可能已经找到了 'm' 命名空间的来源(使用 /v:diag 时:

Task Parameter:
      AppxManifestSchemas=
          C:\Program Files (x86)\Windows Kits\Include.0.18362.0\WinRT\FoundationManifestSchema.xsd
                  NamespaceAlias=m
                  NamespaceUri=http://schemas.microsoft.com/appx/manifest/foundation/windows10
          C:\Program Files (x86)\Windows Kits\Include.0.18362.0\WinRT\UapManifestSchema.xsd
                  NamespaceAlias=uap
                  NamespaceUri=http://schemas.microsoft.com/appx/manifest/uap/windows10 (TaskId:271)

编辑 2

在非工作 msbuild diag 日志中,参数 AppxManifestSchemas 根本没有出现,可能解释了初始错误。 下一步:找出参数未发送到任务的原因。

已找到解决方案! 的 我的构建定义中有一个名为 "SdkVersion" 的变量,用于控制我想要构建的目标 sdk。 此变量仅在我的命令行中使用。

事实是,TFS 正在为构建配置中的每个变量创建一个环境变量。 的 在 MsBuild 过程中,特别是任务 'GetSdkPropertyValue'(任务是 ValidateAppxManifest' 的依赖项,它显然添加了一些 AppxManifestSchema,包括带有 NamespaceAlias=m 的任务)

,有一个名为 'SDKVERSION' 的参数 .. 默认情况下(当 运行 手动时)它取值 '10.0' 但因为我有一个同名的变量,它被覆盖了'10.0.18362.0' 导致不添加 appxmanifestschema ... 的 花了我一个月的时间 :p