//simple demo showing how to activate a previously created configuration
static void Main(string[] args)
{
//Create an instance of Visual Studio
//Different Visual Studio versions must be handled
//Visual Studio 2010 -> VisualStudio.DTE.10.0
//Visual Studio 2012 -> VisualStudio.DTE.11.0
Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.11.0");
EnvDTE.DTE dte = (EnvDTE.DTE)System.Activator.CreateInstance(t);
dte.SuppressUI = true;
dte.MainWindow.Visible = false;
//Create a path to a project solution
EnvDTE.Solution solution = dte.Solution;
solution.Open(@"path_to_your_solution.sln");
//Select the corresponding project in the solution
EnvDTE.Project project = solution.Item(1);
//ITcSysManager is the main interface of the automation interface
ITcSysManager systemManager = project.Object;
//Activate the TwinCAT configuration
systemManager.ActivateConfiguration();
//Starts or restarts the TwinCAT system. If TwinCAT is already started the function performs a restart otherwise it performs a start
systemManager.StartRestartTwinCAT();
}