Skip to content

Commit 2a83fe5

Browse files
authored
Update vswhere usage (#1105)
Updates to newer version of vswhere.exe Follows the recommended way of finding MSBuild.exe from https://github.com/microsoft/vswhere#example Also, updates to allow finding newer versions of VS.
1 parent 5d28a8d commit 2a83fe5

File tree

3 files changed

+13
-24
lines changed

3 files changed

+13
-24
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,7 @@ This document follows the conventions laid out in [Keep a CHANGELOG][].
2525
- Changed usage of obselete function GetDelegateForFunctionPointer(IntPtr, Type) to GetDelegateForFunctionPointer<TDelegate>(IntPtr)
2626
- When calling C# from Python, enable passing argument of any type to a parameter of C# type `object` by wrapping it into `PyObject` instance. ([#881][i881])
2727
- Added support for kwarg parameters when calling .NET methods from Python
28+
- Changed method for finding MSBuild using vswhere
2829

2930
### Fixed
3031

setup.py

+12-24
Original file line numberDiff line numberDiff line change
@@ -457,26 +457,20 @@ def _find_msbuild_tool(self, tool="msbuild.exe", use_windows_sdk=False):
457457
# trying to search path with help of vswhere when MSBuild 15.0 and higher installed.
458458
if tool == "msbuild.exe" and use_windows_sdk == False:
459459
try:
460-
basePathes = subprocess.check_output(
460+
basePaths = subprocess.check_output(
461461
[
462462
"tools\\vswhere\\vswhere.exe",
463463
"-latest",
464464
"-version",
465-
"[15.0, 16.0)",
465+
"[15.0,)",
466466
"-requires",
467467
"Microsoft.Component.MSBuild",
468-
"-property",
469-
"InstallationPath",
468+
"-find",
469+
"MSBuild\**\Bin\MSBuild.exe",
470470
]
471471
).splitlines()
472-
if len(basePathes):
473-
return os.path.join(
474-
basePathes[0].decode(sys.stdout.encoding or "utf-8"),
475-
"MSBuild",
476-
"15.0",
477-
"Bin",
478-
"MSBuild.exe",
479-
)
472+
if len(basePaths):
473+
return basePaths[0].decode(sys.stdout.encoding or "utf-8")
480474
except:
481475
pass # keep trying to search by old method.
482476

@@ -528,26 +522,20 @@ def _find_msbuild_tool(self, tool="msbuild.exe", use_windows_sdk=False):
528522
def _find_msbuild_tool_15(self):
529523
"""Return full path to one of the Microsoft build tools"""
530524
try:
531-
basePathes = subprocess.check_output(
525+
basePaths = subprocess.check_output(
532526
[
533527
"tools\\vswhere\\vswhere.exe",
534528
"-latest",
535529
"-version",
536-
"[15.0, 16.0)",
530+
"[15.0,)",
537531
"-requires",
538532
"Microsoft.Component.MSBuild",
539-
"-property",
540-
"InstallationPath",
533+
"-find",
534+
"MSBuild\**\Bin\MSBuild.exe",
541535
]
542536
).splitlines()
543-
if len(basePathes):
544-
return os.path.join(
545-
basePathes[0].decode(sys.stdout.encoding or "utf-8"),
546-
"MSBuild",
547-
"15.0",
548-
"Bin",
549-
"MSBuild.exe",
550-
)
537+
if len(basePaths):
538+
return basePaths[0].decode(sys.stdout.encoding or "utf-8")
551539
else:
552540
raise RuntimeError("MSBuild >=15.0 could not be found.")
553541
except subprocess.CalledProcessError as e:

tools/vswhere/vswhere.exe

55.5 KB
Binary file not shown.

0 commit comments

Comments
 (0)