WindowsPlatform: fix Visual Studio path discovery for uwp target

It was hardcoding VS 2017, but now uses vswhere.exe to find newer Visual Studio versions too.

Newer versions of VS don't actually support UWP JavaScript, though. However, if users have UWP installed in VS, the error message will be clearer about that lack of support.
This commit is contained in:
Josh Tynjala
2024-02-12 10:02:21 -08:00
parent 458ee49fbd
commit 045920596c

View File

@@ -238,7 +238,23 @@ class WindowsPlatform extends PlatformTarget
{
System.runCommand("", "haxe", [hxml]);
var msBuildPath = "C:\\Program Files (x86)\\Microsoft Visual Studio\\2017\\Community\\MSBuild\\15.0\\Bin\\MSBuild.exe";
// start by finding visual studio
var programFilesX86 = Sys.getEnv("ProgramFiles(x86)");
var vswhereCommand = programFilesX86 + "\\Microsoft Visual Studio\\Installer\\vswhere.exe";
var vswhereOutput = System.runProcess("", vswhereCommand, ["-latest", "-products", "*", "-requires", "Microsoft.Component.MSBuild", "-property", "installationPath"]);
var visualStudioPath = StringTools.trim(vswhereOutput);
// then, find MSBuild inside visual studio
var msBuildPath = visualStudioPath + "\\MSBuild\\Current\\Bin\\MSBuild.exe";
if (!FileSystem.exists(msBuildPath))
{
// fallback for VS 2017, which didn't use Current
msBuildPath = visualStudioPath + "\\MSBuild\\15.0\\Bin\\MSBuild.exe";
if (!FileSystem.exists(msBuildPath))
{
Log.error("MSBuild not found");
return;
}
}
var args = [
Path.tryFullPath(targetDirectory + "/source/" + project.app.file + ".jsproj"),
"/p:Configuration=Release"