Visual Studio Plugin - PlcVersionInfo
The PlcVersionInfo sample demonstrates how to use the TwinCAT Automation Interface from within a Visual Studio Plugin. Its main purpose is to show how to create a simple tool that extends the PLC engineering with more functionalities. The small user interface allows to enter version and author information for PLC function blocks. When executing the sample, this information is placed in a VAR_CONSTANT area in all functionblocks within a PLC projeect. Although this might seem a pretty simple example, it clearly shows how powerfull Visual Studio Plugins can be and how they might greatly enhance the users engineering experience.
For more information about Visual Studio Plugins, please consult the MSDN webpage.
Basic concept
As previously noted, the tool starts an iteration over all PLC tree items of a PLC project. If the current tree item is either a functionblock, function or program, then the declaration text of the tree item is determined and extended with a VAR_CONSTANT block.
Notes about executing and debugging Visual Studio Plugins
Visual Studio Plugins may be located in different folders so that Visual Studio recognizes them. This documentation assumes that the Plugin should only be made available for a specific user account which is why the Plugin will be placed in a directory within the user profile. For more information, please consult the MSDN webpage about Add-In Registration.
To execute the Plugin without debugging, please copy the compiled DLL and the .AddIn file to the directory c:\Users\username\Documents\Visual Studio 201x\Addins\ and restart Visual Studio.
To execute the Plugin with debugging, simply execute the debugger from within the Plugin solution. If this causes you issues, you may also copy the .AddIn file the Addins directory (mentioned above) and edit the file with a text editor of your choice to change the <Assembly> node to the path of the compiled debug DLL. Then start a Visual Studio instance and attach your debugger to this instance/process.
The Visual Studio Plugin will be made available in the TwinCAT menu in Visual Studio.