def _find_devenv_path(vs_version):
devenv_path = None
# First try the registry, because the environment variable is unreliable
# (case of Visual Studio installed on a different drive; it still sets
# the envvar to point to C:\Program Files even if devenv.com is on D:\)
#pylint: disable=import-error
from winreg import OpenKey, QueryValue, HKEY_LOCAL_MACHINE
key_path = 'SOFTWARE\\Classes\\VisualStudio.accessor.' + vs_version + '.0\\shell\\Open'
try:
with OpenKey(HKEY_LOCAL_MACHINE, key_path) as key:
cmdline = QueryValue(key, 'Command')
if cmdline[:1] == '"':
cmdline = cmdline.split('"')[1]
elif ' ' in cmdline:
cmdline = cmdline.split(' ')[0]
devenv_path = cmdline.replace('devenv.exe', 'devenv.com')
#pylint: disable=broad-except
except Exception:
pass
# If the registry key is unhelpful, try the environment variable
if not devenv_path:
vstools_path = os.getenv('VS' + vs_version + '0COMNTOOLS')
if vstools_path is not None:
# Sanitize this because os.path.join sometimes gets confused
if vstools_path[-1] in [ '/', '\\' ]:
vstools_path = vstools_path[:-1]
devenv_path = os.path.join(vstools_path, '../../Common7/IDE/devenv.com')
if not devenv_path or not os.path.exists(devenv_path):
return None
logging.info("Found Visual Studio at %s", devenv_path)
return devenv_path
评论列表
文章目录