From 18046833f44c1531b33d4361397216ec7fe4f8ca Mon Sep 17 00:00:00 2001 From: xiaobfly Date: Thu, 22 May 2025 14:58:03 +0800 Subject: Fixed the issue where vstudio cannot be found when there are more versions of the same vstudio in the system. vswhere echo string: D:\Microsoft Visual Studio\2022\Professional2 D:\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build xmake thought it was a string, but in fact, it was two. so, should split it by "\n": { "D:\Microsoft Visual Studio\2022\Professional2", "D:\Microsoft Visual Studio\2022\Professional" } --- xmake/modules/detect/sdks/find_vstudio.lua | 27 +++++++++++++++++++-------- 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/xmake/modules/detect/sdks/find_vstudio.lua b/xmake/modules/detect/sdks/find_vstudio.lua index 3e687228a..d58886521 100644 --- a/xmake/modules/detect/sdks/find_vstudio.lua +++ b/xmake/modules/detect/sdks/find_vstudio.lua @@ -491,15 +491,17 @@ function _find_vstudio(opt) -- find VC install path (and aux build path) using `vswhere` (for version >= 15.0) -- * version > 15.0 eschews registry entries; but `vswhere` (included with version >= 15.2) can be used to find VC install path -- ref: https://github.com/Microsoft/vswhere/blob/master/README.md @@ https://archive.is/mEmdu - local vswhere_VCAuxiliaryBuildDir = nil - local vswhere_Common7ToolsDir = nil + local vswhere_VCAuxiliaryBuildDir = {} + local vswhere_Common7ToolsDir = {} if (tonumber(version) >= 15) and vswhere then local vswhere_vrange = format("%s,%s)", version, (version + 1)) -- build tools: https://github.com/microsoft/vswhere/issues/22 @@ https://aka.ms/vs/workloads local result = os.iorunv(vswhere.program, {"-products", "*", "-prerelease", "-property", "installationpath", "-version", vswhere_vrange}) if result then - vswhere_VCAuxiliaryBuildDir = path.join(result:trim(), "VC", "Auxiliary", "Build") - vswhere_Common7ToolsDir = path.join(result:trim(), "Common7", "Tools") + for _, vc_path in ipairs(result:split("\n")) do + table.insert(vswhere_VCAuxiliaryBuildDir, path.join(vc_path:trim(), "VC", "Auxiliary", "Build")) + table.insert(vswhere_Common7ToolsDir, path.join(vc_path:trim(), "Common7", "Tools")) + end end end @@ -514,8 +516,13 @@ function _find_vstudio(opt) if vsenvs[version] then table.insert(paths, format("$(env %s)\\..\\..\\VC", vsenvs[version])) end - if vswhere_VCAuxiliaryBuildDir and os.isdir(vswhere_VCAuxiliaryBuildDir) then - table.insert(paths, 1, vswhere_VCAuxiliaryBuildDir) + + if vswhere_VCAuxiliaryBuildDir then + for i, vc_path in ipairs(vswhere_VCAuxiliaryBuildDir) do + if os.isdir(vc_path) then + table.insert(paths, 1, vc_path) + end + end end if version == "6.0" and os.arch() == "x64" then table.insert(paths, "$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\WOW6432Node\\Microsoft\\DevStudio\\6.0\\Products\\Microsoft Visual C++;ProductDir)\\Bin") @@ -557,8 +564,12 @@ function _find_vstudio(opt) format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\Common7\\Tools", version), format("$(reg HKEY_LOCAL_MACHINE\\SOFTWARE\\Wow6432Node\\Microsoft\\VisualStudio\\SxS\\VS7;%s)\\Common7\\Tools", version) } - if vswhere_Common7ToolsDir and os.isdir(vswhere_Common7ToolsDir) then - table.insert(paths, 1, vswhere_Common7ToolsDir) + if vswhere_Common7ToolsDir then + for _, vc_path in ipairs(vswhere_Common7ToolsDir) do + if os.isdir(vc_path) then + table.insert(paths, 1, vc_path) + end + end end vcvarsall = find_file("VsDevCmd.bat", paths) end -- cgit v1.3.1 From 7d2b149206a53cb8f5bbfc7f3b70065a07faf11c Mon Sep 17 00:00:00 2001 From: ruki Date: Thu, 22 May 2025 22:11:58 +0800 Subject: Update find_vstudio.lua --- xmake/modules/detect/sdks/find_vstudio.lua | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/xmake/modules/detect/sdks/find_vstudio.lua b/xmake/modules/detect/sdks/find_vstudio.lua index d58886521..bf698c1b9 100644 --- a/xmake/modules/detect/sdks/find_vstudio.lua +++ b/xmake/modules/detect/sdks/find_vstudio.lua @@ -518,7 +518,7 @@ function _find_vstudio(opt) end if vswhere_VCAuxiliaryBuildDir then - for i, vc_path in ipairs(vswhere_VCAuxiliaryBuildDir) do + for _, vc_path in ipairs(vswhere_VCAuxiliaryBuildDir) do if os.isdir(vc_path) then table.insert(paths, 1, vc_path) end -- cgit v1.3.1