Pages

▼

23 May 2007

How to detect version of MS Visual Studio or compiler in compilation time

To do this you should use _MSC_VER define like in this code:
#if _MSC_VER >= 1400 // this is Visual C++ 2005
#elif _MSC_VER >= 1310 // this is Visual C++ .NET 2003
#elif _MSC_VER > 1300 // this is Visual C++ .NET 2002
#endif

2 comments:

  1. but this code does not work with C#
    as with #if preprocessor directive we can use a bool variable.

    ReplyDelete
  2. for VS package,
    add envDTE as reference and use the following code:

    EnvDTE.

    DTE dteObj = Package.GetGlobalService(typeof(EnvDTE.DTE)) as EnvDTE.DTE;

    string strVSVersion = dteObj.Version;

    ReplyDelete