GeezerVison is showing github.com — Find msbuild.exe path from registry · Mu-L/pythonnet@cfcc36a
File tree
Expand file treeCollapse file tree
Open diff view settings
Expand file treeCollapse file tree
Open diff view settings
Collapse file
Copy file name to clipboardExpand all lines: pythonnet/setup.py +32-6Lines changed: 32 additions & 6 deletions | Original file line number | Diff line number | Diff line change |
|---|
|
18 | 18 | DEVTOOLS = "MsDev" if sys.platform == "win32" else "Mono" |
19 | 19 | VERBOSITY = "minimal" # quiet, minimal, normal, detailed, diagnostic |
20 | 20 |
|
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") |
24 | 40 |
|
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() |
28 | 54 | _defines_sep = ";" |
29 | 55 | _config = "%sWin" % CONFIG |
30 | 56 | _npython_exe = "nPython.exe" |
|