How can I check what version/edition of Visual Studio is installed programmatically?

前端 未结 10 1059
萌比男神i
萌比男神i 2020-12-16 09:16

I could read registry HKEY_LOCAL_MACHINE\\SOFTWARE\\Microsoft\\VisualStudio\\10.0. However, it doesn\'t give me any information about the edition of it - Profes

相关标签:
10条回答
  • 2020-12-16 09:47

    An updated answer to this question would be the following :

    "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property productId
    

    Resolves to 2019

    "C:\Program Files (x86)\Microsoft Visual Studio\Installer\vswhere.exe" -latest -property catalog_productLineVersion
    

    Resolves to Microsoft.VisualStudio.Product.Professional

    0 讨论(0)
  • 2020-12-16 09:51

    For anyone stumbling on this question, here is the answer if you are doing C++: You can check in your cpp code for vs version like the example bellow which links against a library based on vs version being 2015 or higher:

    #if (_MSC_VER > 1800)
    #pragma comment (lib, "legacy_stdio_definitions.lib")
    #endif
    

    This is done at link time and no extra run-time cost.

    0 讨论(0)
  • 2020-12-16 09:52

    Put this code somewhere in your C++ project:

    #ifdef _DEBUG
    TCHAR version[50];
    sprintf(&version[0], "Version = %d", _MSC_VER);
    MessageBox(NULL, (LPCTSTR)szMsg, "Visual Studio", MB_OK | MB_ICONINFORMATION);
    #endif
    

    Note that _MSC_VER symbol is Microsoft specific. Here you can find a list of Visual Studio versions with the value for _MSC_VER for each version.

    0 讨论(0)
  • 2020-12-16 09:55

    All the information in this thread is now out of date with the recent release of vswhere. Download that and use it.

    0 讨论(0)
  • 2020-12-16 10:03

    Its not very subtle, but there is a folder in the install location that carries the installed version name.

    eg I've got:

    C:\Program Files\Microsoft Visual Studio 9.0\Microsoft Visual Studio 2008 Standard Edition - ENU

    and

    C:\Program Files\Microsoft Visual Studio 10.0\Microsoft Visual Studio 2010 Professional - ENU

    You could find the install location from the registry keys you listed above.

    Alternatively this will be in the registry at a number of places, eg:

    HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\9.0\Setup\Microsoft Visual Studio 2008 Standard Edition - ENU

    There are loads of values and keys with the string in, you can find them by looking for "Microsoft Visual Studio 2010" in the Regedit>Edit>Find function.

    You'd just need to pick the one you want and do a little bit of string matching.

    0 讨论(0)
  • 2020-12-16 10:04

    In Visual Studio, the Tab 'Help'-> 'About Microsoft Visual Studio' should give you the desired infos.

    0 讨论(0)
提交回复
热议问题