Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit cfcc36a

Browse files
committed
Find msbuild.exe path from registry
1 parent 91f7ebd commit cfcc36a

File tree

1 file changed

+32
-6
lines changed

1 file changed

+32
-6
lines changed

pythonnet/setup.py

Lines changed: 32 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -18,13 +18,39 @@
1818
DEVTOOLS = "MsDev" if sys.platform == "win32" else "Mono"
1919
VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic
2020

21-
if DEVTOOLS == "MsDev":
22-
from distutils import msvc9compiler
23-
msvc9compiler.VERSION = 11
21+
def FindMsBuildPath():
22+
import _winreg
23+
24+
aReg = _winreg.ConnectRegistry(None,_winreg.HKEY_LOCAL_MACHINE)
25+
try:
26+
keysToCheck = [r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\12.0", r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\4.0", r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\3.5", r"SOFTWARE\Microsoft\MSBuild\ToolsVersions\2.0"]
27+
aKey = None
28+
for key in keysToCheck:
29+
try:
30+
aKey = _winreg.OpenKey(aReg, key)
31+
break
32+
except WindowsError:
33+
pass
34+
35+
if aKey==None:
36+
raise RuntimeError("MSBUILD.exe could not be found")
37+
38+
try:
39+
val, type = _winreg.QueryValueEx(aKey, "MSBuildToolsPath")
2440

25-
cc = msvc9compiler.MSVCCompiler()
26-
cc.initialize()
27-
_xbuild = "\"%s\"" % cc.find_exe("msbuild.exe")
41+
if type!=_winreg.REG_SZ:
42+
raise RuntimeError("MSBUILD.exe could not be found")
43+
finally:
44+
aKey.Close()
45+
finally:
46+
aReg.Close()
47+
48+
msbuildpath = os.path.join(val, "msbuild.exe")
49+
return msbuildpath
50+
51+
52+
if DEVTOOLS == "MsDev":
53+
_xbuild = "\"%s\"" % FindMsBuildPath()
2854
_defines_sep = ";"
2955
_config = "%sWin" % CONFIG
3056
_npython_exe = "nPython.exe"

0 commit comments

Comments
 (0)