简体   繁体   中英

Building UWP app in command line (using MSBUILD)

I am trying to build UWP app (targeting 16299) from command line from Jenkins setup. The system has only VS build tools 2017. used this command to build

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.

Another issue found is nuget is not restoring any package, so updated nuget to 4.4.1 then I got the error

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.

same issue with nuget 4.6.0 also

I tried by adding following in project file

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

same issue with msbuild and nuget, anyone succeed in building UWP in Jenkins?

Update 05-01-2015

  • Followed instruction according to answer.
  • Copied NuGet folder
  • Copied the "WindowsXaml" folder.
  • Used MSbuild restore instead of Nuget restore to fix msbuild trying to find packages in "C:\\WINDOWS\\system32\\config\\systemprofile.nuget\\packages\\"

With all these changes no more issues in build, But the appx bundle is not present. may be individual appx for x86/x64/ARM has to be created and then some kind of merging is required.

so need further investigations

From the directory path that you have for MSBuild, I see that you may have installed MSBuildTools installer instead of the community, professional,... editions.

I tried that before and found that it's incomplete and doesn't have all dependencies for building Uwp tools, take a look at some of the comments here about the issues.

First Workaround: You can install Uwp Workload from VS Community or Professional as it has all dependencies, till Microsoft fix the issues in BuildTools installer.

Bonus: if you want to run the installer from command line, you can compose command line like that:

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

The longer workaround, I managed to install other dependencies but I believe it's kind of hassle if you are automating this installation, snippets from this 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

And for the nuggets issue:

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

Note: If you come by this later and found that Microsoft fixed the issues related to Uwp in MSBuildTools installer, please leave a comment about it in this answer to update it.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM