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(); } }
public void RunFinished() { String sPath = BlankProject.FullName; String sName = BlankProject.Name; String sReplace = sName + "\\" + sName + "\\" + sName + ".csproj"; try { dte.Solution.Remove(BlankProject); } catch { } sPath = sPath.Replace(sReplace, sName + ".sln"); dte.ExecuteCommand("File.SaveAll"); dte.ExecuteCommand("File.CloseSolution"); dte.Solution.Open(sPath); try { sPath = sPath.Replace(".sln", "\\" + sName); if (Directory.Exists(sPath)) { // Create the directory. Directory.Delete(sPath, true); } } catch { } }
private static void OpenFileAtLine(EnvDTE.DTE dte, string file, int line) { if (dte == null) { Console.WriteLine("DTE is null"); return; } file = $"\"{file}\""; Console.WriteLine("Opening file: " + file + " on line: " + line); dte.MainWindow.Visible = true; dte.ExecuteCommand("File.OpenFile", file); dte.ExecuteCommand("Edit.GoTo", line.ToString()); }
/// <summary> /// This function is the callback used to execute the command when the menu item is clicked. /// See the constructor to see how the menu item is associated with this function using /// OleMenuCommandService service and MenuCommand class. /// </summary> /// <param name="sender">Event sender.</param> /// <param name="e">Event args.</param> private void MenuItemCallback(object sender, EventArgs e) { EnvDTE80.Solution2 solution; var dte = (EnvDTE.DTE)ServiceProvider.GetService(typeof(EnvDTE.DTE)); if (dte != null) { solution = (EnvDTE80.Solution2)dte.Solution; if (solution != null) { VsShellUtilities.ShowMessageBox( this.ServiceProvider, "開始下載JQuery至專案中", "Info", OLEMSGICON.OLEMSGICON_INFO, OLEMSGBUTTON.OLEMSGBUTTON_OK, OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); if (solution.Projects.Count > 0) { Projects projects = solution.Projects; var list = new List <Project>(); var item = projects.GetEnumerator(); while (item.MoveNext()) { var project = item.Current as Project; EnvDTE.DTE _ObjDTE = project.DTE; var script = "Install-Package Newtonsoft.Json -ProjectName " + project.Name; _ObjDTE.ExecuteCommand("View.PackageManagerConsole", script); } } } } }
private void StartRemoteIntegrationService(EnvDTE.DTE dte) { // We use DTE over RPC to start the integration service. All other DTE calls should happen in the host process. if (RetryRpcCall(() => dte.Commands.Item(WellKnownCommandNames.Test_IntegrationTestService_Start).IsAvailable)) { RetryRpcCall(() => dte.ExecuteCommand(WellKnownCommandNames.Test_IntegrationTestService_Start)); } }
/// <summary> /// Navigates to the specific line in the specific file /// </summary> public void NavigateToItem() { // First open the file applicationObject.ExecuteCommand("File.OpenFile", String.Format("\"{0}\"", FullFilename)); // Then get a reference to the active document TextSelection objSel = (TextSelection)applicationObject.ActiveDocument.Selection; // Finally, jump to the line and highlight it objSel.GotoLine(Line, true); }
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(); }
public static void createProjectsFromTemplates(EnvDTE.DTE dte, string filename) { try { // Create a solution with two projects in it, based on project // templates. Solution2 soln = (Solution2)dte.Solution; //= "abcd"; string csTemplatePath; string csPrjPath = string.Format("C:\\Downloads\\DB\\MyDBProject\\{0}", Path.GetFileName(filename).Replace("dacpac", "")); // Get the project template path for a C# console project. // Console Application is the template name that appears in // the right pane. "CSharp" is the Language(vstemplate) as seen // in the registry. csTemplatePath = soln.GetProjectTemplate("SSDT.vstemplate", "Database"); //System.Windows.Forms.MessageBox.Show("SQL template path: " + csTemplatePath); // Create a new C# console project using the template obtained // above. Project prj = soln.AddFromTemplate(csTemplatePath, csPrjPath, Path.GetFileName(filename).Replace("dacpac", ""), false); string commandArg = string.Format(CultureInfo.InvariantCulture, "/FileName {0} " + "/GroupByType " + "/GroupBySchema", filename); System.Threading.Thread.Sleep(1000 * 10); dte.ExecuteCommand("Project.SSDTImportDac", commandArg); } catch (System.Exception ex) { Console.WriteLine("ERROR: " + ex.Message); } }
/// <summary> /// سلوشن را به طور كامل ذخيره ميكند /// </summary> public void SaveSolution() { dte.ExecuteCommand("File.SaveAll", ""); }