jenkins - 在命令行中构建 UWP 应用程序(使用 MSBUILD)

标签 jenkins uwp msbuild nuget-package-restore

我正在尝试从 Jenkins 设置的命令行构建 UWP 应用程序(目标为 16299)。 系统只有VS构建工具2017。 使用此命令来构建

C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\msbuild.exe" /t:Rebuild /p:Configuration=Release;AppxBundle=Always;AppxBundlePlatforms="x86\x64\ARM" /p:BuildAppxUploadPackageForUap=true SOLUTION_FILE.sln 

error MSB4226: The imported project "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\Microsoft\WindowsXaml\v15.0\Microsoft.Windows.UI.Xaml.CSharp.targets" was not found. Also, tried to find "Microsoft\WindowsXaml\v15.0\Microsoft.Windows.UI.Xaml.CSharp.targets" in the fallback search path(s) for $(MSBuildExtensionsPath) - "C:\Program Files (x86)\MSBuild" . These search paths are defined in "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\Bin\MSBuild.exe.Config". Confirm that the path in the declaration is correct, and that the file exists on disk in one of the search paths.

发现的另一个问题是 nuget 没有恢复任何包,因此将 nuget 更新到 4.4.1 然后出现错误

MSBuild auto-detection: using msbuild version '15.5.180.51428' from 'C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\MSBuild\15.0\bin'. Nothing to do. None of the projects in this solution specify any packages for NuGet to restore.

nuget 4.6.0 也存在同样的问题

我尝试在项目文件中添加以下内容

<PropertyGroup>
<RestoreProjectStyle>PackageReference</RestoreProjectStyle> </PropertyGroup>

与 msbuild 和 nuget 相同的问题,有人在 Jenkins 中成功构建 UWP 吗?

2015 年 5 月 1 日更新

  • 按照答案遵循说明。
  • 已复制 NuGet 文件夹
  • 复制“WindowsXaml”文件夹。
  • 使用 MSbuild 还原而不是 Nuget 还原来修复 msbuild 尝试在“C:\WINDOWS\system32\config\systemprofile.nuget\packages\”中查找包的问题

通过所有这些更改,构建中不再出现问题, 但 appx bundle 不存在。可能必须为 x86/x64/ARM 创建单独的 appx,然后需要某种合并。

所以需要进一步调查

最佳答案

从 MSBuild 的目录路径中,我发现您可能安装了 MSBuildTools 安装程序,而不是社区版、专业版等。

我之前尝试过,发现它不完整,并且没有构建Uwp工具的所有依赖项,看看一些评论here关于问题。

第一个解决方法:您可以从 VS Community or Professional 安装 Uwp Workload因为它具有所有依赖项,直到 Microsoft 修复 BuildTools 安装程序中的问题。

奖励:如果您想从命令行运行安装程序,您可以像这样编写命令行:

vs_installer.exe --installPath "C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools" ^
--add Microsoft.VisualStudio.Workload.Universal ^
--add Microsoft.VisualStudio.Component.Windows10SDK.14393 ^
--add Microsoft.Component.MSBuild ^
--passive --wait --norestart

较长的解决方法,我设法安装了其他依赖项,但我相信如果您要自动化此安装,这会有点麻烦,来自此 article 的片段

Copy the Sdks folder from a machine that has VS2017 installed at: c:\Program Files(x86)\Visual Studio\2017\Professional\Build MSBuild\Sdks to your build machine at: c:\Program Files(x86)\Visual Studio\2017\Build Tools\MSBuild\Sdks

对于掘金问题:

Copying the NuGet import files will do the tr Again, from a machine with VS2017, copy the following folder: C:\Program Files (x86)\Microsoft Visual Studio\2017\Professional\Common7\IDE\CommonExtensions\Microsoft\NuGet to your build machine at: C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\CommonExtensions\Microsoft\NuGet

注意:如果您稍后发现 Microsoft 修复了 MSBuildTools 安装程序中与 Uwp 相关的问题,请在此答案中发表评论以进行更新。

关于jenkins - 在命令行中构建 UWP 应用程序(使用 MSBUILD),我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48071924/

相关文章:

c# - 在 UWP 应用中切换音频

winrt-xaml - 如何覆盖或操作 KeyDown : Space or Enter for ListView in UWP?

msbuild - 开源 msbuild 任务

c++ - Visual Studio 的 "Add reference"实际上是做什么的?

groovy - 在 jenkins 中使用带有循环的构建流程插件的并行作业

c# - 如何在 Windows 10 UWP 应用程序中播放 (MIDI) 声音?

jenkins - 在管道工作流程中使用 Jenkins 'Mailer'

c# - 自动化 Windows 服务部署的最佳方式是什么?

jenkins - 如何修复 Ansible 中的内存错误?

javascript - 从 javascript 访问 jenkins 远程 api,无需 JSONP