From 045920596ce32e5d16978b3ba3d66e38c96b3a2e Mon Sep 17 00:00:00 2001 From: Josh Tynjala Date: Mon, 12 Feb 2024 10:02:21 -0800 Subject: [PATCH] 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. --- tools/platforms/WindowsPlatform.hx | 18 +++++++++++++++++- 1 file changed, 17 insertions(+), 1 deletion(-) diff --git a/tools/platforms/WindowsPlatform.hx b/tools/platforms/WindowsPlatform.hx index 46433c6e9..018194bb0 100644 --- a/tools/platforms/WindowsPlatform.hx +++ b/tools/platforms/WindowsPlatform.hx @@ -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"