static void Main(string[] args) { Type t = System.Type.GetTypeFromProgID("VisualStudio.DTE.10.0"); EnvDTE.DTE dte = (EnvDTE.DTE)System.Activator.CreateInstance(t); dte.SuppressUI = false; dte.MainWindow.Visible = true; EnvDTE.Solution sol = dte.Solution; sol.Open(@"C:\Temp\SolutionFolder\MySolution1\MySolution1.sln"); EnvDTE.Project pro = sol.Projects.Item(1); ITcSysManager sysMan = pro.Object; sysMan.ActivateConfiguration(); sysMan.StartRestartTwinCAT(); }
//Activate Actual Configuration public static void ActivateActualConfiguration(IConfigurationRoot configuration, ITcSysManager systemManager, bool debugMode) { systemManager.ActivateConfiguration(); systemManager.StartRestartTwinCAT(); }
private static void Main() { LoadSettings(); var solutionPath = Path.Combine( Environment.GetEnvironmentVariable("temp") ?? string.Empty, SolutionName); MessageFilter.Register(); try { // Parse Commandline Options var alwaysYes = false; var commandLineArgs = Environment.GetCommandLineArgs(); foreach (var cmd in commandLineArgs) { if (cmd == "-y") { alwaysYes = true; } } // Close all TwinCAT Autd Server solutions currently opened var processes = System.Diagnostics.Process.GetProcesses().Where(x => x.MainWindowTitle.StartsWith(SolutionName) && x.ProcessName.Contains("devenv")); foreach (var process in processes) { GetDte(process.Id)?.Quit(); } // Wait for input Console.WriteLine("Please Enter the IP Address of your Client to allow connection: [127.0.0.1]"); var ipaddrStr = "127.0.0.1"; if (!alwaysYes) { ipaddrStr = Console.ReadLine(); } IPAddress.TryParse(ipaddrStr ?? string.Empty, out var ipAddr); Console.WriteLine("Connecting to TcXaeShell DTE..."); var t = Type.GetTypeFromProgID("TcXaeShell.DTE.15.0"); var dte = (DTE2)Activator.CreateInstance(t); dte.SuppressUI = false; dte.MainWindow.Visible = true; dte.UserControl = true; Console.WriteLine("Switching TwinCAT3 to Config Mode..."); SetConfigMode(); System.Threading.Thread.Sleep(1000); Console.WriteLine("Creating a Project..."); var project = CreateProject(dte, solutionPath); ITcSysManager sysManager = project.Object; if (ipAddr != null) { Console.WriteLine("Setting up the Routing Table to " + ipAddr); AddRoute(sysManager, ipAddr); } Console.WriteLine("Scanning Devices..."); var autds = ScanAutDs(sysManager); AssignCpuCores(sysManager); SetupTask(sysManager, autds); Console.WriteLine("Activating and Restarting TwinCAT3..."); sysManager.ActivateConfiguration(); sysManager.StartRestartTwinCAT(); Console.WriteLine("Saving the Project..."); SaveProject(dte, project, solutionPath); Console.WriteLine("Done. Do you want to close the TwinCAT config window? [Yes]/No"); var closeWindow = "Yes"; if (!alwaysYes) { closeWindow = Console.ReadLine(); } if (closeWindow != "No") { dte.Quit(); } } catch (Exception e) { Console.WriteLine("Error. Press any key to exit. Check your license of TwinCAT3."); Console.WriteLine(e.Message); Console.ReadLine(); } MessageFilter.Revoke(); }