/// <summary> /// Provide UI to add a JAR reference. /// </summary> private void AddJarReference() { // Get the current project var project = (IVsHierarchy)GetCurrentProject(); using (var dialog = new AddJarReferenceDialog()) { if (dialog.ShowDialog() == DialogResult.OK) { var jarPath = dialog.JarPath; var libName = dialog.LibraryName; var importCode = dialog.ImportCode; var item = BuildProject.AddItem("JarReference", jarPath).Single(); if (!string.IsNullOrEmpty(libName)) { item.SetMetadataValue("LibraryName", libName); } if (importCode) { item.SetMetadataValue("ImportCode", "yes"); } // Save project BuildProject.Save(); // Unload the project - also saves the modifications ErrorHandler.ThrowOnFailure(solution.CloseSolutionElement((uint)__VSSLNCLOSEOPTIONS.SLNCLOSEOPT_UnloadProject, project, 0)); // Reload project dte.ExecuteCommand("Project.ReloadProject", ""); } } }
protected override Task <bool> BuildProjectAsync() { var taskSource = new TaskCompletionSource <bool>(); _ = new VsUpdateSolutionEvents(_buildManager, taskSource); // Build the project. When project build is done, set the task source as being done. // (Either succeeded, cancelled, or failed). _dte.ExecuteCommand("Build.BuildSelection"); return(taskSource.Task); }
public void ValidateNewFileOpenedWithEditor() { UIThreadInvoker.Invoke((ThreadInvoker) delegate() { TestUtils testUtils = new TestUtils(); testUtils.CloseCurrentSolution(__VSSLNSAVEOPTIONS.SLNSAVEOPT_NoSave); testUtils.CreateEmptySolution(TestContext.TestDir, "CreateEmptySolution"); //Add new file to the solution and save all string name = "mynewfile"; EnvDTE.DTE dte = VsIdeTestHostContext.Dte; EnvDTE.Window win = dte.ItemOperations.NewFile(@"Haskell editor Files\Haskell editor", name, EnvDTE.Constants.vsViewKindPrimary); Assert.IsNotNull(win); dte.ExecuteCommand("File.SaveAll", string.Empty); //get the currect misc files state object OriginalValueMiscFilesSavesLastNItems = dte.get_Properties("Environment", "Documents").Item("MiscFilesProjectSavesLastNItems").Value; if ((int)OriginalValueMiscFilesSavesLastNItems == 0) { dte.get_Properties("Environment", "Documents").Item("MiscFilesProjectSavesLastNItems").Value = 5; } //get a handle to the project item in the solution explorer EnvDTE.ProjectItem item = win.Document.ProjectItem; Assert.IsNotNull(item); //close window win.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo); //reset the miscfiles property if it was modified if (OriginalValueMiscFilesSavesLastNItems != dte.get_Properties("Environment", "Documents").Item("MiscFilesProjectSavesLastNItems").Value) { dte.get_Properties("Environment", "Documents").Item("MiscFilesProjectSavesLastNItems").Value = OriginalValueMiscFilesSavesLastNItems; } }); }
/// <summary> /// This function is the callback used to handle the cmdidSetParamDescription command. /// </summary> private void OnSetParamDescription(object sender, EventArgs e) { OleMenuCmdEventArgs eventArgs = (OleMenuCmdEventArgs)e; string strCommandArg = eventArgs.InValue.ToString(); if (strCommandArg.Length > 0) { // Retrieve the command and set it's ParametersDescription property OleMenuCommandService mcs = GetService(typeof(IMenuCommandService)) as OleMenuCommandService; if (null != mcs) { CommandID testCommandId = new CommandID(GuidList.guidAllowParamsCmdSet, (int)PkgCmdIDList.cmdidTestCommand); OleMenuCommand testCommand = mcs.FindCommand(testCommandId) as OleMenuCommand; if (testCommand != null) { // Set the ParametersDescription testCommand.ParametersDescription = strCommandArg; // Update the AllowParams Options Dialog as well EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE)); dte.get_Properties("AllowParams Package", "Settings").Item("ParametersDescription").Value = strCommandArg; } } } else // invoke options dialog when command invoked with no parameters { EnvDTE.DTE dte = (EnvDTE.DTE)GetService(typeof(EnvDTE.DTE)); dte.ExecuteCommand("Tools.Options", typeof(OptionsPage).GUID.ToString()); } }
public void Execute() { subCommand?.Execute(); ThreadHelper.ThrowIfNotOnUIThread(); dte.PrintMessageLine($"Open UserSecret file. {path}"); dte.ExecuteCommand("File.OpenFile", path); }
private void StartRemoteIntegrationService(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.IntegrationTestServiceStart).IsAvailable)) { RetryRpcCall(() => dte.ExecuteCommand(WellKnownCommandNames.IntegrationTestServiceStart)); } }
private static void OpenFileToLine(EnvDTE.DTE dte, string filePath, int lineNumber) { // Ask VS to open the desired file MessageFilter.Register(); try { // Show the Main Window dte.MainWindow.Activate(); // Open the desired file dte.ExecuteCommand("File.OpenFile", filePath); // Go to the desired line if (lineNumber > 0) { dte.ExecuteCommand("Edit.GoTo", lineNumber.ToString()); } } finally { MessageFilter.Revoke(); } }
public static void TryExecuteCommand(this EnvDTE.DTE dte, string command) { try { if (dte.Commands.Item(command).IsAvailable) { dte.ExecuteCommand(command); } } catch (System.Runtime.InteropServices.COMException ex) { System.Windows.Forms.MessageBox.Show(ex.ToString()); if (System.Diagnostics.Debugger.IsAttached) { System.Diagnostics.Debugger.Break(); } } }
private void ExecuteCommand(string name, string args) { try { _dte.ExecuteCommand(name, args ?? string.Empty); } catch (Exception ex) when(!ex.IsCriticalException()) { #if !DEV15_OR_LATER if (name == "File.OpenFolder") { OpenInWindowsExplorer(args.Trim('"')); return; } #endif var outputWindow = OutputWindowRedirector.GetGeneral(this); outputWindow.WriteErrorLine(ex.Message); } }
/// <summary> /// Show messages if it's possible. /// </summary> public void show() { try { if (dte != null) { dte.ExecuteCommand("View.Output"); //TODO: } if (upane != null) { upane.Activate(); } } catch (Exception ex) { Log.Debug("Log: error of showing '{0}'", ex.Message); } }
static void ShowGraphInVS <S>(int k, IAutomaton <S> fa, string name, Func <S, string> describeS = null) { string filename = name + (name.EndsWith(".dgml") ? "" : ".dgml"); //Access the top-level VS automation object model EnvDTE.DTE dte = (EnvDTE.DTE)VS; #region Close the dgml file if it is open try { System.Collections.IEnumerator wins = dte.Windows.GetEnumerator(); while (wins.MoveNext() == true) { EnvDTE.Window w = wins.Current as EnvDTE.Window; if (filename.Equals(w.Caption)) { w.Close(EnvDTE.vsSaveChanges.vsSaveChangesNo); break; } } } catch { //the operation dte.Windows.GetEnumerator() //may sometimes cause COMException //Ignore this exception, //then the window with given filename may still be open //and VS may ask to save changes, instead of ignoring //when the file is subsequently changed on disk } #endregion SaveGraph(k, fa, name, describeS); #region Open the dgml file in VS try { var dir = System.Environment.CurrentDirectory; var fullfilename = dir + "/" + filename; dte.ExecuteCommand("File.OpenFile", dir + "/" + filename); } catch { OpenFileInNewProcess(filename); } #endregion }
public void Open(string fullPath, int lineNumber, int columnNumber) { if (!String.IsNullOrEmpty(fullPath)) { //System.Diagnostics.Process process = new System.Diagnostics.Process() { EnableRaisingEvents = false }; ////process.StartInfo.FileName = "editplus.exe"; ////process.StartInfo.Arguments = String.Format("-e {0} -cursor {1}:{2}", fullPath, lineNumber, columnNumber); ////process.StartInfo.FileName = @"C:\Program Files (x86)\Microsoft Visual Studio 12.0\Common7\IDE\devenv.exe"; ////process.StartInfo.Arguments = String.Format("/edit \"{0}\" /command \"edit.goto {1}\"", fullPath, lineNumber, columnNumber); //process.StartInfo.FileName = @"C:\WINDOWS\system32\WindowsPowerShell\v1.0\powershell.exe"; //process.StartInfo.Arguments = String.Format("/edit \"{0}\" /command \"edit.goto {1}\"", fullPath, lineNumber, columnNumber); //process.Start(); EnvDTE.DTE dte = (EnvDTE.DTE)System.Runtime.InteropServices.Marshal.GetActiveObject("VisualStudio.DTE.12.0"); dte.ExecuteCommand("File.OpenFile", fullPath); dte.ActiveDocument.Selection.MoveToDisplayColumn(lineNumber, columnNumber); dte.MainWindow.Activate(); } }
// http://stackoverflow.com/questions/2525457/automating-visual-studio-with-envdte // http://stackoverflow.com/questions/2651617/is-it-possible-to-programmatically-clear-the-ouput-window-in-visual-studio // http://stackoverflow.com/questions/2391473/can-the-visual-studio-debug-output-window-be-programatically-cleared public static void VstClearOutputWindow() { if (!Debugger.IsAttached) { return; } //Application.DoEvents(); // This is for Windows.Forms. // This delay to get it to work. Unsure why. See http://stackoverflow.com/questions/2391473/can-the-visual-studio-debug-output-window-be-programatically-cleared Thread.Sleep(1000); // In VS2008 use EnvDTE80.DTE2 EnvDTE.DTE ide = (EnvDTE.DTE)Marshal.GetActiveObject("VisualStudio.DTE.10.0"); ide.ExecuteCommand("Edit.ClearOutputWindow", ""); Marshal.ReleaseComObject(ide); // EnvDTE80.DTE2 ide = (EnvDTE80.DTE2)Marshal.GetActiveObject("VisualStudio.DTE.10.0"); // ide.ExecuteCommand("Edit.ClearOutputWindow", ""); // Marshal.ReleaseComObject(ide); }
public void Show() { if (_dte == null) { // Check whether there are any VS processes running. // TODO: Show dialog with instances to connect to. For now make a new one...? // var instances = MsdevManager.Msdev.GetIDEInstances(false); // For now, just create a new instance Type type = Type.GetTypeFromProgID("VisualStudio.DTE"); object dte = Activator.CreateInstance(type, true); _dte = (EnvDTE.DTE)dte; //System.IServiceProvider serviceProvider = new Microsoft.VisualStudio.Shell.ServiceProvider(_dte as Microsoft.VisualStudio.OLE.Interop.IServiceProvider); //IVsShell shell = serviceProvider.GetService(typeof(SVsShell)) as IVsShell; //if (shell == null) //{ // return; //} //IEnumPackages enumPackages; //int result = shell.GetPackageEnum(out enumPackages); //IVsPackage package = null; //Guid PackageToBeLoadedGuid = // new Guid("10e82a35-4493-43be-b6d3-228399509924"); //shell.LoadPackage(ref PackageToBeLoadedGuid, out package); _dte.MainWindow.WindowState = EnvDTE.vsWindowState.vsWindowStateNormal; // Load the AppToolsClient into Visual Studio, and connect the pipes. } _dte.MainWindow.Visible = true; // Now bring the _dte to the front (this might be done by the AppToolsClient?) if (_dte.MainWindow.WindowState == EnvDTE.vsWindowState.vsWindowStateMinimize) { _dte.MainWindow.WindowState = EnvDTE.vsWindowState.vsWindowStateNormal; } _dte.MainWindow.Activate(); _dte.MainWindow.SetFocus(); _dte.ExecuteCommand("ExcelDna.AttachExcel", _pipeName); }
public static bool TryShowDgmlFileInVS(string filename) { #if NETFRAMEWORK if (!__tried_to_load_VS) { //only try to load VS automation object model one time TryLoadVS(); __tried_to_load_VS = true; } try { EnvDTE.DTE dte = (EnvDTE.DTE)VS; dte.ExecuteCommand("File.OpenFile", System.IO.Path.GetFullPath(filename)); return(true); } catch { } #endif return(false); }
public static void AddScript(string script) { Type type = Type.GetTypeFromProgID("VisualStudio.DTE"); object obj = Activator.CreateInstance(type, true); EnvDTE.DTE dte = (EnvDTE.DTE)obj; try { dte.MainWindow.Visible = false; // optional if you want to See VS doing its thing dte.Solution.Open(assemblyPath); var solution = dte.Solution; solution.Projects.Item(1).ProjectItems.AddFromFile(script); dte.ExecuteCommand("File.SaveAll"); solution.SolutionBuild.Build(true); }catch (Exception e) { Debug.Log("Failed to add file to solution: " + e.Message); } dte.Quit(); }
/// <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) { // Ref: https://msdn.microsoft.com/en-us/library/bb166773.aspx?f=255&MSPPError=-2147217396 EnvDTE.DTE dte = (EnvDTE.DTE)Package.GetGlobalService(typeof(EnvDTE.DTE)); if (dte == null) { throw new Exception("Unable to retrieve DTE"); } //Array activeSolutionProjects = (Array)dte.ActiveSolutionProjects; //if (activeSolutionProjects == null || activeSolutionProjects.Length == 0) //{ // throw new Exception("Active Solution Projects is null"); //} //EnvDTE.Project dteProject = (EnvDTE.Project)activeSolutionProjects.GetValue(0); //if (dteProject == null) //{ // throw new Exception("Active Solution Projects [0] is null"); //} dte.ExecuteCommand("Project.SetasStartUpProject"); //string message = string.Format(CultureInfo.CurrentCulture, "Inside {0}.MenuItemCallback()", this.GetType().FullName); //string title = "SetStartupButton"; //// Show a message box to prove we were here //VsShellUtilities.ShowMessageBox( // this.ServiceProvider, // message, // title, // OLEMSGICON.OLEMSGICON_INFO, // OLEMSGBUTTON.OLEMSGBUTTON_OK, // OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST); }
} // AddToolBoxItems /// <summary> /// Load the root object of the Visual Studio automation object model. /// </summary> /// <returns></returns> private EnvDTE.DTE LoadDTE() { EnvDTE.DTE dte = null; Type dteType = Type.GetTypeFromProgID( "VisualStudio.DTE"); // version latest of VS.NET // "VisualStudio.DTE.7" ); // version 2002 of VS.NET // "VisualStudio.DTE.7.1"); // version 2003 of VS.NET if (dteType == null) { System.Windows.Forms.MessageBox.Show( "No type for Visual Studio.DTE. Exiting...", "Debugging"); return(null); } try { object objDTE = System.Activator.CreateInstance(dteType, true); dte = (EnvDTE.DTE)objDTE; } catch (Exception ex) { System.Windows.Forms.MessageBox.Show( "CreateInstance(EnvDTE) threw Exception" + ex.ToString() + ". Exiting...", "Debugging"); return(null); } // Work around a VS.NET bug when installing toolbox icons // by making the properties window visible if (dte != null) // work around { dte.ExecuteCommand("View.PropertiesWindow", String.Empty); } return(dte); }
private static void CreateProjectFile1() { System.Type type = System.Type.GetTypeFromProgID("VisualStudio.DTE.11.0"); Object obj = System.Activator.CreateInstance(type, true); EnvDTE.DTE dte = (EnvDTE.DTE)obj; dte.MainWindow.Visible = true; // optional if you want to See VS doing its thing // create a new solution dte.Solution.Create(@"C:\NewSolution\", "NewSolution"); var solution = dte.Solution; // create a C# WinForms app solution.AddFromTemplate(@"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ProjectTemplatesCache\CSharp\Windows\1033\WindowsApplication\csWindowsApplication.vstemplate", @"C:\NewSolution\WinFormsApp", "WinFormsApp"); // create a C# class library solution.AddFromTemplate(@"C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\ProjectTemplatesCache\CSharp\Windows\1033\ClassLibrary\csClassLibrary.vstemplate", @"C:\NewSolution\ClassLibrary", "ClassLibrary"); // save and quit dte.ExecuteCommand("File.SaveAll"); dte.Quit(); }
public static bool CreateSolution(string path, string name) { Type type = Type.GetTypeFromProgID("VisualStudio.DTE"); object obj = Activator.CreateInstance(type, true); EnvDTE.DTE dte = (EnvDTE.DTE)obj; try { dte.MainWindow.Visible = false; // optional if you want to See VS doing its thing string template = System.IO.Path.GetFullPath("../Data/assemblyFiles/MyTemplate.vstemplate"); dte.Solution.AddFromTemplate(template, path, name); //create a new solution dte.Solution.Create(path, name + ".sln"); var solution = dte.Solution; EnvDTE.Project project = solution.AddFromFile(path + "\\" + name + ".csproj"); // create a C# class library System.IO.Directory.CreateDirectory(path + "\\Assets"); project.ProjectItems.AddFromDirectory(path + "\\Assets"); assemblyPath = path + "\\" + name + ".sln"; solution.SolutionBuild.Build(true); // save and quit dte.ExecuteCommand("File.SaveAll"); dte.Quit(); return(true); } catch (Exception e) { Debug.Log("Error creating project: " + e.Message); return(false); } }
private void GenerateClick(object sender, RoutedEventArgs e) { var originalCursor = Cursor; try { Cursor = Cursors.Wait; _packageInstaller.InstallPackage(_project, "WAQS.Client." + _clientKind, _packageInstallerServices); var edmxPath = edmx.SelectedValue as string; var servicePath = service.SelectedValue as string; var appKind = _project.Properties.Cast <EnvDTE.Property>().Any(p => p.Name.StartsWith("WebApplication")) ? "Web" : "App"; var netVersion = _project.GetNetVersion(); var kind = (GenerationOptions.KindViewModel)generationOptions.SelectedItem; var projectDirectoryPath = Path.GetDirectoryName(_project.FullName); string waqsDirectory; string edmxName = null; string waqsGeneralDirectory = null; string contextsPath = null; bool servicePathIsUrl = false; if (kind.Kind == GenerationOptions.Kind.FrameworkOnly) { waqsDirectory = Path.Combine(projectDirectoryPath, "WAQS.Framework"); } else { if (!(edmxPath.EndsWith(".edmx") && File.Exists(edmxPath))) { ShowError("Edmx path is not correct"); return; } if (!((servicePathIsUrl = Regex.IsMatch(servicePath, "^http(s)?://")) || servicePath.EndsWith(".svc") && File.Exists(servicePath))) { ShowError("Service path is not correct"); return; } edmxName = Path.GetFileNameWithoutExtension(edmxPath); waqsDirectory = Path.Combine(projectDirectoryPath, "WAQS." + edmxName); } if (Directory.Exists(waqsDirectory)) { ShowError(waqsDirectory + "already exists"); return; } var projectUIHierarchyItems = _dte.GetProjectsUIHierarchyItems().First(uihi => ((EnvDTE.Project)uihi.Object).FullName == _project.FullName).UIHierarchyItems; var referencesUIHierarchyItems = projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().FirstOrDefault(uihi => uihi.Name == "References")?.UIHierarchyItems; var referencesExpanded = referencesUIHierarchyItems?.Expanded ?? false; var toolsPath = Path.Combine(_packageInstallerServices.GetPackageLocation("WAQS.Client." + _clientKind), "tools"); var clientToolsPath = Path.Combine(toolsPath, "Client." + _clientKind); var defaultNamespace = _project.GetDefaultNamespace(); var references = ((VSProject)_project.Object).References; references.Add("System"); references.Add("System.Core"); references.Add("System.Runtime.Serialization"); references.Add("System.ServiceModel"); if (_clientKind == GenerationOptions.WPF) { references.Add("System.ComponentModel.DataAnnotations"); references.Add("System.Drawing"); references.Add("PresentationCore"); references.Add("PresentationFramework"); references.Add("System.Xaml"); references.Add("System.Xml"); _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "System.Windows.Interactivity.WPF", "2.0.20525", false); _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "Unity", "3.5.1404", false); _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "Rx-WPF", "2.2.5", false); } else if (_clientKind == GenerationOptions.PCL) { _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "Microsoft.Bcl.Async", "1.0.168", false); } try { referencesUIHierarchyItems.Expanded = referencesExpanded; } catch { } bool withGlobal = (kind.Kind & GenerationOptions.Kind.GlobalOnly) != 0; string appConfigPath = null; string appXamlPath = null; string appXamlCsPath = null; if (withGlobal) { appConfigPath = Path.Combine(projectDirectoryPath, "app.config"); if (File.Exists(appConfigPath)) { try { _dte.SourceControl.CheckOutItem(appConfigPath); } catch { } } appXamlPath = Path.Combine(projectDirectoryPath, "App.xaml"); if (File.Exists(appXamlPath)) { try { _dte.SourceControl.CheckOutItem(appXamlPath); } catch { } } appXamlCsPath = Path.Combine(projectDirectoryPath, "App.xaml.cs"); if (File.Exists(appXamlCsPath)) { try { _dte.SourceControl.CheckOutItem(appXamlCsPath); } catch { } } if (kind.Kind == GenerationOptions.Kind.GlobalOnly) { waqsGeneralDirectory = Path.Combine(projectDirectoryPath, "WAQS"); contextsPath = Path.Combine(waqsGeneralDirectory, "Contexts.xml"); if (File.Exists(contextsPath)) { try { _dte.SourceControl.CheckOutItem(contextsPath); } catch { } } } } var entitiesProjectPath = _dte.Solution.FindProjectItem(edmxName + ".Server.Entities.tt")?.ContainingProject.FullName; string entitiesSolutionPath = null; if (!string.IsNullOrEmpty(entitiesProjectPath)) { entitiesSolutionPath = _dte.Solution.FileName; } string vsVersion = _dte.GetVsVersion(); string svcUrl = null; if (servicePathIsUrl) { svcUrl = servicePath; } else if (!string.IsNullOrEmpty(servicePath)) { var svcProjectProperties = _dte.Solution.FindProjectItem(servicePath)?.ContainingProject.Properties.Cast <EnvDTE.Property>(); if (svcProjectProperties != null && (kind.Kind != GenerationOptions.Kind.FrameworkOnly)) { svcUrl = StartService(servicePath, vsVersion, svcProjectProperties); } } var exePath = Path.Combine(clientToolsPath, "InitWAQSClient" + _clientKind + ".exe"); var exeArgs = new StringBuilder("\"" + edmxPath + "\" \"" + (_clientKind == GenerationOptions.WPF ? projectDirectoryPath + "\" \"" : "") + clientToolsPath + "\" \"" + defaultNamespace + "\" \"" + svcUrl + "\" \"" + waqsDirectory + "\" \"" + waqsGeneralDirectory + "\" \"" + (kind.Kind == GenerationOptions.Kind.GlobalOnly ? _dte.Solution.FindProjectItem(edmxName + ".Client." + _clientKind + ".ClientContext.tt").ProjectItems.Cast <EnvDTE.ProjectItem>().FirstOrDefault(pi => pi.Name == edmxName + "ExpressionTransformer.cs")?.GetFilePath() : "") + "\" \"" + (kind.Kind == GenerationOptions.Kind.GlobalOnly ? _dte.Solution.FindProjectItem(edmxName + ".Client." + _clientKind + ".ServiceProxy.tt").ProjectItems.Cast <EnvDTE.ProjectItem>().FirstOrDefault(pi => pi.Name == "I" + edmxName + "Service.cs")?.GetFilePath() : "") + "\" \"" + (kind.Kind == GenerationOptions.Kind.GlobalOnly ? _dte.Solution.FindProjectItem(edmxName + ".Client." + _clientKind + ".Entities.tt")?.GetFirstCsFilePath() : "") + "\" \"" + (kind.Kind == GenerationOptions.Kind.GlobalOnly ? _dte.Solution.FindProjectItem(edmxName + ".Client." + _clientKind + ".ClientContext.tt").ProjectItems.Cast <EnvDTE.ProjectItem>().FirstOrDefault(pi => pi.Name == edmxName + "ClientContext.cs")?.GetFilePath() : "") + "\" \"" + (kind.Kind == GenerationOptions.Kind.GlobalOnly ? _dte.Solution.FindProjectItem(edmxName + ".Client." + _clientKind + ".ClientContext.Interfaces.tt").ProjectItems.Cast <EnvDTE.ProjectItem>().FirstOrDefault(pi => pi.Name == "I" + edmxName + "ClientContext.cs")?.GetFilePath() : "") + "\" \"" + entitiesSolutionPath + "\" \"" + entitiesProjectPath + "\" \"" + netVersion + "\" \"" + vsVersion + "\" \"" + kind.Key + "\" " + (copyTemplates.IsChecked == true ? "WithSourceControl" : "WithoutSourceControl") + " \"" + _dte.Solution.FullName + "\""); if ((kind.Kind & GenerationOptions.Kind.WithoutGlobalWithoutFramework) != 0) { var projectsItems = _dte.GetProjects().SelectMany(p => p.GetAllProjectItems()); var specificationsProjectItem = projectsItems.FirstOrDefault(pi => ((string)pi.Properties.Cast <EnvDTE.Property>().First(p => p.Name == "FullPath").Value).EndsWith("\\Specifications\\")); exeArgs.Append(" \"" + specificationsProjectItem.ContainingProject.FullName + "\""); exeArgs.Append(" \"" + Path.GetDirectoryName(specificationsProjectItem.GetFilePath()) + "\""); var dtoProjectItem = projectsItems.FirstOrDefault(pi => ((string)pi.Properties.Cast <EnvDTE.Property>().First(p => p.Name == "FullPath").Value).EndsWith("\\DTO\\")); exeArgs.Append(" \"" + dtoProjectItem.ContainingProject.FullName + "\""); exeArgs.Append(" \"" + Path.GetDirectoryName(dtoProjectItem.GetFilePath()) + "\""); exeArgs.Append(" \"" + _dte.Solution.FindProjectItem(edmxName + ".Server.Entities.tt")?.GetFirstCsFilePath() + "\""); } var process = new Process(); process.StartInfo.FileName = exePath; process.StartInfo.Arguments = exeArgs.ToString(); process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.Start(); process.WaitForExit(); if (copyTemplates.IsChecked == true) { string templatesFolder; HashSet <string> existingTTIncludes; EnvDTE.ProjectItems templatesProjectItems; TemplatesCopying.CopyTemplates(_dte, _clientKind + "ClientTemplates", netVersion, toolsPath, vsVersion, out templatesFolder, out existingTTIncludes, out templatesProjectItems); var ttInclude = @"%AppData%\WAQS\Templates\Includes\WAQS.Roslyn.Assemblies.ttinclude"; var ttIncludeName = Path.GetFileName(ttInclude); TemplatesCopying.AddItem(ttInclude, vsVersion, netVersion, ttIncludeName, templatesFolder, existingTTIncludes, templatesProjectItems); } if (kind.Kind == GenerationOptions.Kind.FrameworkOnly) { edmxName = "Framework"; } _project.ProjectItems.AddFromFile(Path.Combine(waqsDirectory, edmxName + ".Client." + _clientKind + ".waqs")); if (kind.Kind != GenerationOptions.Kind.GlobalOnly) { _project.ProjectItems.AddFromFile(Path.Combine(waqsDirectory, edmxName + ".Client." + _clientKind + ".tt")); } try { projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().First(uihi => uihi.Name == "WAQS." + edmxName).UIHierarchyItems.Expanded = false; } catch { } if (withGlobal) { if (_clientKind == GenerationOptions.WPF) { _project.ProjectItems.AddFromFile(appConfigPath); } if (kind.Kind == GenerationOptions.Kind.GlobalOnly) { EnvDTE.UIHierarchyItems waqsGeneralUIHierarchyItems = null; Action setWAQSGeneralUIHierarchyItems = () => waqsGeneralUIHierarchyItems = projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().FirstOrDefault(uihi => uihi.Name == "WAQS")?.UIHierarchyItems; setWAQSGeneralUIHierarchyItems(); bool waqsGeneralUIHierarchyItemsExpanded = false; if (waqsGeneralUIHierarchyItems != null) { waqsGeneralUIHierarchyItemsExpanded = waqsGeneralUIHierarchyItems.Expanded; } _project.ProjectItems.AddFromFile(contextsPath); if (waqsGeneralUIHierarchyItems == null) { try { setWAQSGeneralUIHierarchyItems(); waqsGeneralUIHierarchyItems.Expanded = false; } catch { } } else { try { waqsGeneralUIHierarchyItems.Expanded = waqsGeneralUIHierarchyItemsExpanded; } catch { } } } } try { _dte.ExecuteCommand("File.TfsRefreshStatus"); } catch { } _dte.ItemOperations.Navigate("https://github.com/MatthieuMEZIL/waqs/blob/master/README.md"); Close(); } catch (Exception ex) { MessageBox.Show(ex.GetType().ToString() + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } finally { Cursor = originalCursor; } }
void MouseHook_MouseAction(object sender, EventArgs e) { dte.ExecuteCommand("Build.BuildSolution"); }
private void GenerateClick(object sender, RoutedEventArgs e) { var originalCursor = Cursor; try { Cursor = Cursors.Wait; _packageInstaller.InstallPackage(_project, "WAQS.Server", _packageInstallerServices); var edmxPath = edmx.SelectedValue as string; var appKind = _project.Properties.Cast <EnvDTE.Property>().Any(p => p.Name.StartsWith("WebApplication")) ? "Web" : "App"; var netVersion = _project.GetNetVersion(); var kind = (GenerationOptions.KindViewModel)generationOptions.SelectedItem; var projectDirectoryPath = Path.GetDirectoryName(_project.FullName); string waqsDirectory; string edmxName = null; EnvDTE.ProjectItem edmxProjectItem = null; string edmxProjectPath = null; if (kind.Kind == GenerationOptions.Kind.FrameworkOnly) { waqsDirectory = Path.Combine(projectDirectoryPath, "WAQS.Framework"); } else { if (!(edmxPath.EndsWith(".edmx") && File.Exists(edmxPath))) { ShowError("Edmx path is not correct"); return; } edmxName = Path.GetFileNameWithoutExtension(edmxPath); waqsDirectory = Path.Combine(projectDirectoryPath, "WAQS." + edmxName); edmxProjectItem = _dte.Solution.FindProjectItem(edmxPath); edmxProjectPath = edmxProjectItem.ContainingProject.FullName; } if (Directory.Exists(waqsDirectory)) { ShowError(waqsDirectory + "already exists"); return; } var projectUIHierarchyItems = _dte.GetProjectsUIHierarchyItems().First(uihi => ((EnvDTE.Project)uihi.Object).FullName == _project.FullName).UIHierarchyItems; var referencesUIHierarchyItems = projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().First(uihi => uihi.Name == "References").UIHierarchyItems; var referencesExpanded = referencesUIHierarchyItems.Expanded; var toolsPath = Path.Combine(_packageInstallerServices.GetPackageLocation("WAQS.Server"), "tools"); var toolsPathServer = Path.Combine(toolsPath, "Server"); var defaultNamespace = _project.GetDefaultNamespace(); EnvDTE.Project fxProject; if (kind.Kind == GenerationOptions.Kind.GlobalOnly || kind.Kind == GenerationOptions.Kind.WithoutGlobalWithoutFramework) { fxProject = _dte.Solution.FindProjectItem("ExpressionExtension.cs").ContainingProject; } else { fxProject = _project; } var assemblyName = (string)fxProject.Properties.Cast <EnvDTE.Property>().First(p => p.Name == "AssemblyName").Value; var assemblyVersion = (string)fxProject.Properties.Cast <EnvDTE.Property>().First(p => p.Name == "AssemblyVersion").Value; var references = ((VSProject)_project.Object).References; references.Add("System"); references.Add("System.Configuration"); references.Add("System.Core"); references.Add("System.Data"); references.Add("System.Runtime.Serialization"); references.Add("System.ServiceModel"); references.Add("System.ServiceModel.Activation"); references.Add("System.ServiceModel.Channels"); references.Add("System.Transactions"); references.Add("System.Web"); references.Add("System.Xml"); _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "Unity", "3.5.1404", false); _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "CommonServiceLocator", "1.3.0", false); _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "EntityFramework", "6.1.3", false); try { referencesUIHierarchyItems.Expanded = referencesExpanded; } catch { } bool withGlobal = (kind.Kind & GenerationOptions.Kind.GlobalOnly) != 0; var globalDirectory = Path.Combine(projectDirectoryPath, "Global"); string webConfigPath = null; string globalAsaxPath = null; string globalAsaxCsPath = null; string globalWCFService = null; if (withGlobal) { webConfigPath = Path.Combine(projectDirectoryPath, "Web.config"); if (File.Exists(webConfigPath)) { try { _dte.SourceControl.CheckOutItem(webConfigPath); } catch { } } globalAsaxPath = Path.Combine(projectDirectoryPath, "Global.asax"); if (File.Exists(globalAsaxPath)) { try { _dte.SourceControl.CheckOutItem(globalAsaxPath); } catch { } } globalAsaxCsPath = Path.Combine(projectDirectoryPath, "Global.asax.cs"); if (File.Exists(globalAsaxCsPath)) { try { _dte.SourceControl.CheckOutItem(globalAsaxCsPath); } catch { } } globalWCFService = Path.Combine(projectDirectoryPath, "GlobalWCFService.cs"); if (File.Exists(globalWCFService)) { try { _dte.SourceControl.CheckOutItem(globalWCFService); } catch { } } } string vsVersion; switch (_dte.Version) { case "12.0": vsVersion = "VS12"; break; case "14.0": default: vsVersion = "VS14"; break; } var exePath = Path.Combine(toolsPathServer, "InitWAQSServer.exe"); string specificationsFolder = null; string dtoFolder = null; var exeArgs = new StringBuilder("\"" + edmxPath + "\" \"" + edmxProjectPath + "\" \"" + projectDirectoryPath + "\" \"" + toolsPathServer + "\" \"" + defaultNamespace + "\" \"" + assemblyName + "\" \"" + assemblyVersion + "\" \"" + netVersion + "\" \"" + vsVersion + "\" \"" + kind.Key + "\" \"" + appKind + "\" \"" + waqsDirectory + "\" \"" + (edmxPath == null ? "" : _dte.Solution.FindProjectItem(edmxPath).ContainingProject.ProjectItems.Cast <EnvDTE.ProjectItem>().FirstOrDefault(pi => pi.Name == "App.Config")?.GetFilePath()) + "\" " + (copyTemplates.IsChecked == true ? "WithSourceControl" : "WithoutSourceControl") + " \"" + _dte.Solution.FullName + "\" WCF"); if (kind.Kind == GenerationOptions.Kind.GlobalOnly) { exeArgs.Append(" \"" + _dte.Solution.FindProjectItem(edmxName + ".Server.DAL.Interfaces.tt").GetFirstCsFilePath() + "\""); exeArgs.Append(" \"" + _dte.Solution.FindProjectItem(edmxName + ".Server.DAL.tt").GetFirstCsFilePath() + "\""); exeArgs.Append(" \"" + _dte.Solution.FindProjectItem("I" + edmxName + "Service.cs").GetFilePath() + "\""); exeArgs.Append(" \"" + _dte.Solution.FindProjectItem(edmxName + "Service.cs").GetFilePath() + "\""); exeArgs.Append(" \"" + _dte.Solution.FindProjectItem("I" + edmxName + "WCFService.cs").GetFilePath() + "\""); exeArgs.Append(" \"" + _dte.Solution.FindProjectItem(edmxName + "WCFService.cs").GetFilePath() + "\""); exeArgs.Append(" \"" + edmxProjectPath + "\""); var edmxProjectFolderPath = Path.GetDirectoryName(edmxProjectPath); exeArgs.Append(" \"" + Path.Combine(edmxProjectFolderPath, "Specifications") + "\""); exeArgs.Append(" \"" + Path.Combine(edmxProjectFolderPath, "DTO") + "\""); } else if (kind.Kind != GenerationOptions.Kind.FrameworkOnly) { exeArgs.Append(" \"" + _project.FullName + "\""); specificationsFolder = Path.Combine(projectDirectoryPath, "Specifications"); exeArgs.Append(" \"" + specificationsFolder + "\""); dtoFolder = Path.Combine(projectDirectoryPath, "DTO"); exeArgs.Append(" \"" + dtoFolder + "\""); } var process = new Process(); process.StartInfo.FileName = exePath; process.StartInfo.Arguments = exeArgs.ToString(); process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.Start(); process.WaitForExit(); if (copyTemplates.IsChecked == true) { string templatesFolder; HashSet <string> existingTTIncludes; EnvDTE.ProjectItems templatesProjectItems; TemplatesCopying.CopyTemplates(_dte, "ServerTemplates", netVersion, toolsPath, vsVersion, out templatesFolder, out existingTTIncludes, out templatesProjectItems); var ttInclude = @"%AppData%\WAQS\Templates\Includes\WAQS.Roslyn.Assemblies.ttinclude"; var ttIncludeName = Path.GetFileName(ttInclude); TemplatesCopying.AddItem(ttInclude, vsVersion, netVersion, ttIncludeName, templatesFolder, existingTTIncludes, templatesProjectItems); } if ((kind.Kind & GenerationOptions.Kind.WithoutGlobalWithoutFramework) != 0) { var edmxFileProperties = edmxProjectItem.Properties; edmxFileProperties.Item("CustomTool").Value = ""; edmxFileProperties.Item("BuildAction").Value = 0; foreach (var ttPath in edmxProjectItem.ProjectItems.Cast <EnvDTE.ProjectItem>().Where(pi => pi.Name.EndsWith(".tt")).Select(pi => pi.GetFilePath())) { _dte.Solution.FindProjectItem(ttPath).Delete(); } } if (kind.Kind == GenerationOptions.Kind.FrameworkOnly) { edmxName = "Framework"; } _project.ProjectItems.AddFromFile(Path.Combine(waqsDirectory, edmxName + ".Server.waqs")); _project.ProjectItems.AddFromFile(Path.Combine(waqsDirectory, edmxName + ".Server.tt")); var dalItem = _dte.Solution.FindProjectItem(Path.Combine(waqsDirectory, edmxName + ".Server.DAL.tt")); if (dalItem != null && dalItem.ProjectItems.Count < 2) // strange bug: sometimes code is not generated for this T4 only { ((VSProjectItem)dalItem.Object).RunCustomTool(); } try { projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().First(uihi => uihi.Name == "WAQS." + edmxName).UIHierarchyItems.Expanded = false; } catch { } if (withGlobal && appKind == "Web") { _project.ProjectItems.AddFromFile(webConfigPath); _project.ProjectItems.AddFromFile(globalAsaxPath); _project.ProjectItems.AddFromFile(globalAsaxCsPath); _project.ProjectItems.AddFromFile(Path.Combine(projectDirectoryPath, edmxName + ".svc")); if (kind.Kind == GenerationOptions.Kind.GlobalOnly) { var globalUIHierarchyItem = projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().FirstOrDefault(uihi => uihi.Name == "Global"); EnvDTE.UIHierarchyItems globalUIHierarchyItems = null; bool globalUIHierarchyItemsExpanded = false; if (globalUIHierarchyItem != null) { globalUIHierarchyItems = globalUIHierarchyItem.UIHierarchyItems; globalUIHierarchyItemsExpanded = globalUIHierarchyItems.Expanded; } _project.ProjectItems.AddFromFile(Path.Combine(globalDirectory, "GlobalWCFServiceContract.tt")); _project.ProjectItems.AddFromFile(Path.Combine(globalDirectory, "GlobalWCFService.cs")); _project.ProjectItems.AddFromFile(Path.Combine(projectDirectoryPath, "Global.svc")); if (globalUIHierarchyItem == null) { try { globalUIHierarchyItems = projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().FirstOrDefault(uihi => uihi.Name == "Global")?.UIHierarchyItems; } catch { } } if (globalUIHierarchyItems != null) { globalUIHierarchyItems.Expanded = globalUIHierarchyItemsExpanded; } } } if (specificationsFolder != null) { _project.ProjectItems.AddFromDirectory(specificationsFolder); } if (dtoFolder != null) { _project.ProjectItems.AddFromDirectory(dtoFolder); } try { _dte.ExecuteCommand("File.TfsRefreshStatus"); } catch { } _dte.ItemOperations.Navigate("https://github.com/MatthieuMEZIL/waqs/blob/master/README.md"); Close(); } catch (Exception ex) { MessageBox.Show(ex.GetType().ToString() + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } finally { Cursor = originalCursor; } }
public void Show() { EnvDTE.DTE dte = Microsoft.VisualStudio.Shell.Package.GetGlobalService(typeof(Microsoft.VisualStudio.Shell.Interop.SDTE)) as EnvDTE.DTE; dte.ExecuteCommand("View.Output", string.Empty); this.pane.Clear(); }
/// <summary> /// Moves the caret to line number. /// </summary> /// <param name="DTE">The DTE.</param> /// <param name="lineNumber">The line number.</param> internal static void GoToLine(EnvDTE.DTE DTE, int lineNumber) { DTE.ExecuteCommand("GotoLn", lineNumber.ToString()); }
private void GenerateClick(object sender, RoutedEventArgs e) { var originalCursor = Cursor; try { Cursor = Cursors.Wait; _packageInstaller.InstallPackage(_project, "WAQS.Server.Mock", _packageInstallerServices); var edmxPath = edmx.SelectedValue as string; var appKind = _project.Properties.Cast <EnvDTE.Property>().Any(p => p.Name.StartsWith("WebApplication")) ? "Web" : "App"; var netVersion = _project.GetNetVersion(); var kind = (GenerationOptions.KindViewModel)generationOptions.SelectedItem; var projectDirectoryPath = Path.GetDirectoryName(_project.FullName); string waqsDirectory; string waqsGeneralDirectory = null; string edmxName = null; EnvDTE.ProjectItem edmxProjectItem = null; string edmxProjectPath = null; if (kind.Kind == GenerationOptions.Kind.FrameworkOnly) { waqsDirectory = Path.Combine(projectDirectoryPath, "WAQS.Framework"); } else { if (!(edmxPath.EndsWith(".edmx") && File.Exists(edmxPath))) { ShowError("Edmx path is not correct"); return; } edmxName = Path.GetFileNameWithoutExtension(edmxPath); waqsDirectory = Path.Combine(projectDirectoryPath, "WAQS." + edmxName); edmxProjectItem = _dte.Solution.FindProjectItem(edmxPath); edmxProjectPath = edmxProjectItem.ContainingProject.FullName; } if (Directory.Exists(waqsDirectory)) { ShowError(waqsDirectory + "already exists"); return; } var projectUIHierarchyItems = _dte.GetProjectsUIHierarchyItems().First(uihi => ((EnvDTE.Project)uihi.Object).FullName == _project.FullName).UIHierarchyItems; var referencesUIHierarchyItems = projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().First(uihi => uihi.Name == "References").UIHierarchyItems; var referencesExpanded = referencesUIHierarchyItems.Expanded; var toolsPath = Path.Combine(_packageInstallerServices.GetPackageLocation("WAQS.Server.Mock"), "tools"); var toolsPathServerMock = Path.Combine(toolsPath, "Server.Mock"); var defaultNamespace = _project.GetDefaultNamespace(); var references = ((VSProject)_project.Object).References; references.Add("System"); references.Add("System.Core"); references.Add("System.Data"); references.Add("Microsoft.VisualStudio.QualityTools.UnitTestFramework.dll"); var dalInterfacesProjectItem = _dte.Solution.FindProjectItem(edmxName + ".Server.DAL.Interfaces.tt"); var dalInterfacesProject = dalInterfacesProjectItem?.ContainingProject; if (dalInterfacesProject != null) { references.AddProject(dalInterfacesProject); } var dalProjectItem = _dte.Solution.FindProjectItem(edmxName + ".Server.DAL.tt"); var dalProject = dalProjectItem?.ContainingProject; if (dalProject != null) { references.AddProject(dalProject); } var dtoProject = _dte.Solution.FindProjectItem(edmxName + ".Server.DTO.tt")?.ContainingProject; if (dtoProject != null) { references.AddProject(dtoProject); } var entitiesProjectItem = _dte.Solution.FindProjectItem(edmxName + ".Server.Entities.tt"); var entitiesProject = entitiesProjectItem?.ContainingProject; if (entitiesProject != null) { references.AddProject(entitiesProject); } var serviceProject = _dte.Solution.FindProjectItem(edmxName + ".Server.Service.tt")?.ContainingProject; if (serviceProject != null) { references.AddProject(serviceProject); } EnvDTE.Project fxProject = null; if (kind.Kind == GenerationOptions.Kind.WithoutGlobalWithoutFramework) { fxProject = _dte.Solution.FindProjectItem("WAQS.Server.Fx.DAL.Mock.tt")?.ContainingProject; if (fxProject != null) { references.AddProject(fxProject); } } _packageInstaller.InstallPackage("http://packages.nuget.org", _project, "EntityFramework", "6.1.2", false); try { referencesUIHierarchyItems.Expanded = referencesExpanded; } catch { } string vsVersion; switch (_dte.Version) { case "12.0": vsVersion = "VS12"; break; case "14.0": default: vsVersion = "VS14"; break; } var entitiesProjectPath = entitiesProject.FullName; var entitiesSolutionPath = entitiesProject == null ? null : _dte.Solution.FileName; var exePath = Path.Combine(toolsPathServerMock, "InitWAQSServerMock.exe"); var exeArgs = new StringBuilder("\"" + edmxPath + "\" \"" + projectDirectoryPath + "\" \"" + toolsPathServerMock + "\" \"" + defaultNamespace + "\" \"" + waqsDirectory + "\" \"" + waqsGeneralDirectory + "\" \"" + entitiesSolutionPath + "\" \"" + entitiesProjectPath + "\" \"" + netVersion + "\" \"" + vsVersion + "\" \"" + kind.Key + "\" \"" + (copyTemplates.IsChecked == true ? "WithSourceControl" : "WithoutSourceControl") + "\" \"" + _dte.Solution.FullName + "\""); if ((kind.Kind & GenerationOptions.Kind.WithoutGlobalWithoutFramework) != 0) { var specificationsProjectItem = entitiesProject?.GetAllProjectItems().FirstOrDefault(pi => ((string)pi.Properties.Cast <EnvDTE.Property>().First(p => p.Name == "FullPath").Value).EndsWith("\\Specifications\\")); exeArgs.Append(" \"" + specificationsProjectItem?.ContainingProject.FullName + "\""); exeArgs.Append(" \"" + specificationsProjectItem?.GetFilePath() + "\""); var dtoProjectItem = (dtoProject ?? entitiesProject).GetAllProjectItems().FirstOrDefault(pi => ((string)pi.Properties.Cast <EnvDTE.Property>().First(p => p.Name == "FullPath").Value).EndsWith("\\DTO\\")); exeArgs.Append(" \"" + dtoProjectItem?.ContainingProject.FullName + "\""); exeArgs.Append(" \"" + dtoProjectItem?.GetFilePath() + "\""); var entityCsProjectItem = entitiesProjectItem?.ProjectItems.Cast <EnvDTE.ProjectItem>().FirstOrDefault(pi => pi.Name.EndsWith(".cs")); exeArgs.Append(" \"" + entityCsProjectItem?.GetFilePath() + "\""); var dalInterfaceCsProjectItem = dalInterfacesProjectItem?.ProjectItems.Cast <EnvDTE.ProjectItem>().FirstOrDefault(pi => pi.Name.EndsWith(".cs")); exeArgs.Append(" \"" + dalInterfaceCsProjectItem?.GetFilePath() + "\""); var dalCsProjectItem = dalProjectItem?.ProjectItems.Cast <EnvDTE.ProjectItem>().FirstOrDefault(pi => pi.Name.EndsWith(".cs")); exeArgs.Append(" \"" + dalCsProjectItem?.GetFilePath() + "\""); exeArgs.Append(" \"" + edmxProjectPath + "\""); var configProjectItem = edmxProjectItem.ContainingProject.ProjectItems.Cast <EnvDTE.ProjectItem>().FirstOrDefault(pi => string.Equals(pi.Name, "App.config", StringComparison.CurrentCultureIgnoreCase) || string.Equals(pi.Name, "Web.config", StringComparison.CurrentCultureIgnoreCase)); exeArgs.Append(" \"" + configProjectItem?.GetFilePath() + "\""); } var process = new Process(); process.StartInfo.FileName = exePath; process.StartInfo.Arguments = exeArgs.ToString(); process.StartInfo.WindowStyle = ProcessWindowStyle.Hidden; process.Start(); process.WaitForExit(); if (copyTemplates.IsChecked == true) { string templatesFolder; HashSet <string> existingTTIncludes; EnvDTE.ProjectItems templatesProjectItems; TemplatesCopying.CopyTemplates(_dte, "ServerMockTemplates", netVersion, toolsPath, vsVersion, out templatesFolder, out existingTTIncludes, out templatesProjectItems); var ttInclude = @"%AppData%\WAQS\Templates\Includes\WAQS.Roslyn.Assemblies.ttinclude"; var ttIncludeName = Path.GetFileName(ttInclude); TemplatesCopying.AddItem(ttInclude, vsVersion, netVersion, ttIncludeName, templatesFolder, existingTTIncludes, templatesProjectItems); } if (kind.Kind == GenerationOptions.Kind.FrameworkOnly) { edmxName = "Framework"; } _project.ProjectItems.AddFromFile(Path.Combine(waqsDirectory, edmxName + ".Server.Mock.waqs")); _project.ProjectItems.AddFromFile(Path.Combine(waqsDirectory, edmxName + ".Server.Mock.tt")); try { projectUIHierarchyItems.Cast <EnvDTE.UIHierarchyItem>().First(uihi => uihi.Name == "WAQS." + edmxName).UIHierarchyItems.Expanded = false; } catch { } try { _dte.ExecuteCommand("File.TfsRefreshStatus"); } catch { } _dte.ItemOperations.Navigate("https://github.com/MatthieuMEZIL/waqs/blob/master/README.md"); Close(); } catch (Exception ex) { MessageBox.Show(ex.GetType().ToString() + "\r\n" + ex.Message + "\r\n" + ex.StackTrace); } finally { Cursor = originalCursor; } }
void EnvDTE._DTE.ExecuteCommand(string CommandName, string CommandArgs) { dte.ExecuteCommand(CommandName, CommandArgs); }