uwpwindows-10-universalchocolateygithub-actionsgithub-ci

Install SDK for UWP development in GithubActions CI?


I'm trying to build some UWP libraries and I receive this error:

D:\a\ZXing.Net.Xamarin\ZXing.Net.Xamarin\Source\ZXing.Net.Mobile.WindowsUniversal\ZXing.Net.Mobile.WindowsUniversal.csproj(155,3): error MSB4019: The imported project "C:\Program Files (x86)\MSBuild\Microsoft\WindowsXaml\v11.0\Microsoft.Windows.UI.Xaml.CSharp.targets" was not found. Confirm that the path in the declaration is correct, and that the file exists on disk.

The import clause in the .csproj file looks like this:

<Import Project="$(MSBuildExtensionsPath)\Microsoft\WindowsXaml\v$(VisualStudioVersion)\Microsoft.Windows.UI.Xaml.CSharp.targets" />

So I've tried to install the UWP workload programatically in the Windows2019 VM via chocolatey (both with this package and this other; not the Windows10SDK one because it gives an error when trying to install) with:

- run: |
  choco install visualstudio2019-workload-universal
  choco install visualstudio2019-workload-universalbuildtools

But this doesn't seem to cut it (the package gets installed successfully, apparently) because I still keep getting that compilation error.

Also tried including optional packages, to no avail:

choco install visualstudio2019-workload-universal --package-parameters "--includeOptional"

UPDATE: Turns out that my CI VM already had the file Microsoft.Windows.UI.Xaml.CSharp.targets, but it was located in C:\Program Files (x86)\Microsoft Visual Studio\2019\Enterprise\MSBuild\Microsoft\WindowsXaml\v16.0 (and other versions of it in subfolders underneath this one). For more details, look at my answer.


Solution

  • Turns out that the VS2019 version installed in GithubActions VMs does already include UWP components (and others such as Xamarin.iOS, Xamarin.Android, Xamarin.Mac, etc); the problem was that my build was somehow defaulting to use an old version of MSBuild (the one located in C:/windows/Microsoft.NET/Framework/v4.0.30319/MSBuild.exe) that wasn't aware of these extensions.

    As soon as I made sure that I used the version of MSBuild bundled with VS2019 (the one in %ProgramFiles(x86)%\Microsoft Visual Studio\2019\Enterprise\MSBuild\Current\Bin\MSBuild.exe) everything started to work again.

    To fix it in my particular build I had to modify a build.cake file (IMO it might actually be a bug in CAKE to not detect the proper version of MSBuild by default...). If you want to take a look at the exact fix (that uses vswhere to locate MSBuild), it's this.