private static void GenerateSolution(SolutionData solutionData) { try { MessageFilter.Register(); System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE"); Object obj = System.Activator.CreateInstance(type, true); EnvDTE.DTE dte = (EnvDTE.DTE)obj; dte.MainWindow.Visible = false; // create a new solution dte.Solution.Create(solutionData.directoryPath + "\\", solutionData.solutionName); dte.ExecuteCommand("File.SaveAll"); Solution2 solution = (Solution2)dte.Solution; createProject(solutionData, solution, dte); EnvDTE.Project project = solution.Projects.Item(1); DTE2 dte2 = (DTE2)dte; addContentToProject(solutionData, project, dte2); // save and quit dte.ExecuteCommand("File.SaveAll"); dte.Quit(); MessageFilter.Revoke(); } catch { ErrorHandling.handleWrongUsage(); } }
private void generateProject(string solutionName, string projectName, string generateLocation) { Console.WriteLine($"{solutionName} {projectName} {generateLocation}"); System.Threading.Thread.Sleep(1000); System.Type dteType = Type.GetTypeFromProgID("VisualStudio.DTE.15.0", true); Object obj = System.Activator.CreateInstance(dteType, true); EnvDTE.DTE dte = (EnvDTE.DTE)obj; dte.MainWindow.Visible = true; dte.Solution.Create(generateLocation, solutionName); var solution = dte.Solution; System.Threading.Thread.Sleep(1000); string projectPath = generateLocation + "\\" + solutionName; EnvDTE.Project project = solution.AddFromTemplate(@"D:\WindowsApplication\CustomizeTemplate.vstemplate", projectPath, projectName); System.Threading.Thread.Sleep(5000); dte.ExecuteCommand("File.SaveAll"); System.Threading.Thread.Sleep(0); dte.Quit(); }