Skip to main content

Find VisualStudio Setup information

Project description

PyVisualStudioSetupConfiguration

overview

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.

install

pip install PyVisualStudioSetupConfiguration

or

copy PyVisualStudioSetupConfiguration.py to your project

usage

code example

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)

example output

[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

VSInstanceInfo define

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

implement

algorithm

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

COM implement

  1. use ctypes to load COM lib,

  2. then create COM object and get Interface.

  3. 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.

future work

  1. use meta class to generate com function

  2. use c_void_p class type to avoid explict to specify "this" pointer to COM interface

change log

check CHANGES.txt

Acknowledgement

Visual Studio Search algorithm reference from:

Official COM Interface and Document of Microsoft.VisualStudio.Setup.Configuration

Windows COM implement reference from:

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

PyVisualStudioSetupConfiguration-1.1.1.tar.gz (11.2 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file PyVisualStudioSetupConfiguration-1.1.1.tar.gz.

File metadata

File hashes

Hashes for PyVisualStudioSetupConfiguration-1.1.1.tar.gz
Algorithm Hash digest
SHA256 86fffd7f3f4e2c9f66a770e0cc4140a803ad9501789afead7e8aeacaf7834c5e
MD5 4bcf8eaa9c82761d468e480774e7cb29
BLAKE2b-256 f64256139027a6542f28303e77446fef5fbd8b425e009daa162b126bca6172b3

See more details on using hashes here.

File details

Details for the file PyVisualStudioSetupConfiguration-1.1.1-py3-none-any.whl.

File metadata

File hashes

Hashes for PyVisualStudioSetupConfiguration-1.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 4590a9477a6bbe2c7f621359f6a8ae5e6039182482180b655b404bc87199d01f
MD5 27ce551038abf56ddd524bd7103ab197
BLAKE2b-256 3bc21b1f5e6c80dc1b39e3d83148224556965723ba0dc951b203d470e61f2d7f

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page