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 2017 and 2019, if you have both or more versions installed at the same time.
Visual Studio program ID
Due to the installation of TwinCAT 3 Engineering in Visual Studio, you must create an instance of Visual Studio (DTE object) in order to access the Automation Interface. To create this instance, the ProgID is required, which specifies which version of Visual Studio is to be used. Different versions of Visual Studio or TcXaeShell can be installed on a system, which can be distinguished by the ProgID. 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 of the currently supported Visual Studio versions:
Version | ProgID |
|---|---|
Visual Studio 2017 | VisualStudio.DTE.15.0 |
Visual Studio 2019 | VisualStudio.DTE.16.0 |
Visual Studio 2022 | VisualStudio.DTE.17.0 |
TwinCAT XAE Shell | TcXaeShell.DTE.15.0 |
TwinCAT XAE Shell 64-bit | TcXaeShell.DTE.17.0 |
Specifying the Visual Studio version in the Automation Interface code
To specify the Visual Studio version in the Automation Interface code, you must use the ProgID as a parameter in the GetTypeDromProgID() method when creating 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