Handling different Visual Studio versions
This article explains how to use the TwinCAT Automation Interface with different versions of Visual Studio, e.g. Visual Studio 2010 and 2012, in case you have installed two or more versions in parallel. It consists of the following topics:
- Visual Studio Program ID
- Specify Visual Studio version in Automation Interface code
Visual Studio Program ID
As you have already seen in our basic articles, you need to create a Visual Studio DTE object before implementing Automation Interface code because of the TwinCAT 3 integration into the Visual Studio environment. If you have installed more than one Visual Studio version on your Engineering PC and would like to choose which version should be used along with the Automation Interface code, you need to determine the so-called Program ID (ProgID) of the corresponding Visual Studio version. The ProgID is located in the Windows Registry under HKEY_CLASSES_ROOT and has the following format: VisualStudio.DTE.X.Y.
The following table shows the ProgIDs for the currently supported versions of Visual Studio:
Version | ProgID |
---|---|
Visual Studio 2010 | VisualStudio.DTE.10.0 |
Visual Studio 2012 | VisualStudio.DTE.11.0 |
Visual Studio 2013 | VisualStudio.DTE.12.0 |
Visual Studio 2015 | VisualStudio.DTE.14.0 |
Visual Studio 2017 | VisualStudio.DTE.15.0 |
TwinCAT XAE Shell | TcXaeShell.DTE.15.0 |
Specify Visual Studio version in Automation Interface code
To specify the Visual Studio version in Automation Interface code, you need to use the ProgID as a paremeter of the GetTypeDromProgID() method during the creation process of the DTE object.
Code Snippet (C#):
Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.15.0");
EnvDTE.DTE dte = (EnvDTE.DTE)System.Activator.CreateInstance(t);
Code Snippet (Powershell):
$dte = new-object-com VisualStudio.DTE.15.0