使用MSBuild(GENERATEPROJECTPRIFILE)发行UWP应用程序时出现问题

使用MSBuild(GENERATEPROJECTPRIFILE)发行UWP应用程序时出现问题

问题描述:

我正在尝试从命令行构建UWP应用,以使从签入到发布到商店的过程自动化.从Visual Studio中运行构建时,一切正常,当我创建应用程序包时,一切都正常(但时间太长,大约需要15分钟).

I am trying to build a UWP app from the command-line in an effort to automate the builds from check-in to publishing to the store. Everything works fine when running the builds from within Visual Studio and when I create app packages, it all works fine (but takes too long, 15 minutes or so).

在每个平台上调用msbuild时(x86,x64和ARM),只有ARM似乎会失败,并出现以下错误:

While invoking msbuild per platform (x86, x64 & ARM), only ARM seems to fail with the following error:

_CreatePriConfigXmlForSplitting

"C:\Source\MyProject\src\MyProject\MyProject.csproj" (Build target) (1) ->
(_SplitResourcesPri target) ->
  error PRI175 : 0x80070002 - Processing Resources failed with error : The system cannot find the file specified. [C:\Source\MyProject\src\MyProject\MyProject.csproj]
  GENERATEPROJECTPRIFILE : error PRI252: 0xdef00071 - File C:\Source\MyProject\output\Release\x86\arm\MyProject\resources.pri not found. [C:\Source\MyProject\src\MyProject\MyProject.csproj]

    0 Warning(s)
    2 Error(s)

您可能已经注意到,它使用的是x86\arm目录而不是arm,因此构建失败.

As you probably noticed, it's using x86\arm directory instead of arm, hence the build is failing.

我正在使用蛋糕来构建它,下面是脚本的(相关部分):

I am using Cake to build this, below is (relevant part of) the script:

Task("Build")
    .IsDependentOn("Clean")
    .IsDependentOn("UpdateVersion")
    .IsDependentOn("RestorePackages")
    .Does(() =>
{
    var platforms = new Dictionary<string, PlatformTarget>();
    platforms["ARM"] = PlatformTarget.ARM;
    platforms["x86"] = PlatformTarget.x86;
    platforms["x64"] = PlatformTarget.x64;

    foreach (var platform in platforms)
    {
        Information("Building project for platform {0}", platform.Key);

        var outputDirectory = "../../" + outputRootDirectory + "/" + platform.Value.ToString();
        var projectFileName = string.Format("./src/{0}/{0}.csproj", solutionName);

        var msBuildSettings = new MSBuildSettings {
            Verbosity = Verbosity.Diagnostic, // Verbosity.Minimal
            ToolVersion = MSBuildToolVersion.VS2017,
            Configuration = configurationName,
            MSBuildPlatform = MSBuildPlatform.x86, // Always require x86, see platform for actual target platform
            PlatformTarget = platform.Value
        };

        // Need special path since this is relative to the project file, not the cake build directory
        //msBuildSettings.Properties["OutputPath"] = new List<string>(new [] { outputDirectory });

        // We don't create native builds, we will use MSIL builds which the store will recompile,
        // for more info see https://oren.codes/2015/12/03/continuous-integration-for-uwp-projects-making-builds-faster/
        msBuildSettings.Properties["UseDotNetNativeToolchain"] = new List<string>(new [] { "false" });
        msBuildSettings.Properties["BuildAppxUploadPackageForUap"] = new List<string>(new [] { "true" });
        //msBuildSettings.Properties["AppxPackageArtifactsDir"] = new List<string>(new [] { outputDirectory });

        // Fix for broken targets
        //msBuildSettings.Properties["ProjectPriFileName"] = new List<string>(new [] { "resources.pri" });
        //msBuildSettings.Properties["ProjectPriFullPath"] = new List<string>(new [] { outputDirectory + "/resources.pri" });
        //msBuildSettings.Properties["_TransformedProjectPriFullPath"] = new List<string>(new [] { outputDirectory + "/resources.pri" });

        MSBuild(projectFileName, msBuildSettings);
    }
});

A.如您所见,我通过手动覆盖ms build属性进行了一些试验,但到目前为止还没有运气.

A. As you can see I am experimenting a bit by manually overriding the ms build properties, but no luck so far.

B.起初我以为是GenerateProjectPriFile任务失败了.但是,经过一番调查,我发现创建拆分文件已经显示使用错误的startIndexAt值:

B. At first I thought it was GenerateProjectPriFile task that was failing. However, after some investigation I found out that creating the split files already show use the wrong startIndexAt value:

<?xml version="1.0" encoding="utf-8"?>
<resources targetOsVersion="10.0.0" majorVersion="1">
  <packaging>
    <autoResourcePackage qualifier="Language" />
    <autoResourcePackage qualifier="Scale" />
    <autoResourcePackage qualifier="DXFeatureLevel" />
    <omitSchemaFromResourcePacks />
  </packaging>
  <index root="\" startIndexAt="C:\Source\MyProject\output\Release\x86\arm\MyProject\resources.pri">
    <default>
      <qualifier name="Language" value="en-US" />
      <qualifier name="Contrast" value="standard" />
      <qualifier name="Scale" value="200" />
      <qualifier name="HomeRegion" value="001" />
      <qualifier name="TargetSize" value="256" />
      <qualifier name="LayoutDirection" value="LTR" />
      <qualifier name="DXFeatureLevel" value="DX9" />
      <qualifier name="Configuration" value="" />
      <qualifier name="AlternateForm" value="" />
      <qualifier name="Platform" value="UAP" />
    </default>
    <indexer-config type="PRI" />
  </index>
</resources>

我不知道为什么在为ARM进行构建时它会在ARM之前添加x86.任何帮助表示赞赏.同时,如果我发现新内容,我将继续调查并更新这篇文章.

I have no idea why it prepends x86 before ARM when building for ARM. Any help is appreciated. In the meantime I'll continue investigating and update this post if I find something new.

似乎我必须指定sln文件,而不是csproj文件.这有点不幸,因为现在它的构建量超过了所需的量(同一解决方案中有多个项目),但是我可以通过创建自定义的MyProject.Build.sln文件

It looks like I have to specify the sln file, not the csproj file. This is a bit unfortunate since now it builds much more than it needs to (there are multiple projects in the same solution), but I can get around that by creating a custom MyProject.Build.sln file