PyVisualStudioSetupConfiguration is pure python single file to search Visual Studio installation information.
The result is list of Visual Studio instances with version, path, and chip information.
Windows COM implement using python standard library ctypes, inspired by comtypes and pywin32.
Visual Studio search algorithm inspired by CMake.
pip install PyVisualStudioSetupConfiguration
or
copy PyVisualStudioSetupConfiguration.py to your project
from PyVisualStudioSetupConfiguration import GetAllVSInstanceInfo
if __name__ == '__main__':
# get list of VisualStudio Instance Info
vsInstances = GetAllVSInstanceInfo()
# print the list
print(vsInstances)
# get version of first instance
if len(vsInstances):
vsInstance = vsInstances[0]
s = 'vsInstances[0] :\n'
s += f' VSInstallLocation : {vsInstance.VSInstallLocation}\n'
s += f' Version : {vsInstance.getVersion()}\n'
s += f' versionMajor : {vsInstance.getVerionMajor()}\n'
s += f' VCToolsetVersion : {vsInstance.VCToolsetVersion}\n'
s += f' bWin10SDK : {vsInstance.bWin10SDK}\n'
s += f' bWin81SDK : {vsInstance.bWin81SDK}\n'
s += f' chip : {vsInstance.chip}\n'
print(s)
[VSInstanceInfo :
VSInstallLocation : d:\Program Files\Microsoft Visual Studio\2022\Community
Version : 17.4.33213.308
versionMajor : 17
VCToolsetVersion : 14.34.31933
bWin10SDK : True
bWin81SDK : None
chip : x64
]
vsInstances[0] :
VSInstallLocation : d:\Program Files\Microsoft Visual Studio\2022\Community
Version : 17.4.33213.308
versionMajor : 17
VCToolsetVersion : 14.34.31933
bWin10SDK : True
bWin81SDK : None
chip : x64
class VSInstanceInfo:
def __init__(self) -> None:
# exampel:
# VSInstallLocation : d:\Program Files\Microsoft Visual Studio\2022\Community
# Version : 17.4.33213.308
# versionMajor : 17
# VCToolsetVersion : 14.34.31933
# bWin10SDK : True
# bWin81SDK : False
# chip : x64
self.VSInstallLocation = None # option, string
self.Version = None # mandatory, string
self.VCToolsetVersion = None # option
self.bWin10SDK = None # option
self.bWin81SDK = None # option
self.chip = None # option or string
def getVersion(self):
return self.Version or ""
# string of version major
def getVerionMajor(self):
if self.Version:
numbers = self.Version.split('.')
return numbers[0] if len(numbers) else None
return None
algorithm to find VisualStudio Instance
GetAllVSInstanceInfo:
if driver develop machine:
Get Instance for EWDK(Enterprise Windows Driver Kit)
if found nothing:
try to find new version from version 15 2017 by windows COM, with detail setup info
if found nothing:
try to find new version from verion 15 2017 by VSWhere.exe, with limit setup info
if found nothing:
try to find old version from register table
when get vsinstance, we can know the cmake generator based on the table:
cmake generators for VS major version with cmake --help:
Visual Studio 17 2022 = Generates Visual Studio 2022 project files.
Use -A option to specify architecture.
Visual Studio 16 2019 = Generates Visual Studio 2019 project files.
Use -A option to specify architecture.
Visual Studio 15 2017 [arch] = Generates Visual Studio 2017 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 14 2015 [arch] = Generates Visual Studio 2015 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 12 2013 [arch] = Generates Visual Studio 2013 project files.
Optional [arch] can be "Win64" or "ARM".
Visual Studio 11 2012 [arch] = Deprecated. Generates Visual Studio 2012
project files. Optional [arch] can be
"Win64" or "ARM".
Visual Studio 9 2008 [arch] = Deprecated. Generates Visual Studio 2008
-
use ctypes to load COM lib,
-
then create COM object and get Interface.
-
use RAII to manage COM reference, call Release() at destructor, if constructor object by already created object, call AddRef() at constructor to be also an owner.
-
use meta class to generate com function
-
use c_void_p class type to avoid explict to specify "this" pointer to COM interface
check CHANGES.txt
Visual Studio Search algorithm reference from:
Official COM Interface and Document of Microsoft.VisualStudio.Setup.Configuration
Windows COM implement reference from: