当前位置: 首页>>代码示例>>C#>>正文


C# EnvDTE.ExecuteCommand方法代码示例

本文整理汇总了C#中EnvDTE.ExecuteCommand方法的典型用法代码示例。如果您正苦于以下问题:C# EnvDTE.ExecuteCommand方法的具体用法?C# EnvDTE.ExecuteCommand怎么用?C# EnvDTE.ExecuteCommand使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在EnvDTE的用法示例。


在下文中一共展示了EnvDTE.ExecuteCommand方法的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。

示例1: StartNoDebug

        /// <summary>Run project output without debugging.</summary>
        /// <returns>true - if it's OK</returns>
        static bool StartNoDebug(EnvDTE.DTE dte)
        {
            var startupProjects = (object[])dte.Solution.SolutionBuild.StartupProjects;

            if (startupProjects.Length < 1)
                throw new ApplicationException("No startup projects.");

            var startupProjectFullName = Path.GetFullPath(Path.Combine(Path.GetDirectoryName(dte.Solution.FullName), (string)startupProjects[0]));
            NemerleOAProject nemerleOAProject = GetProject(dte, startupProjectFullName) as NemerleOAProject;

            if (nemerleOAProject == null)
                return false;

            var projectNode = nemerleOAProject.Project.ProjectMgr;
            var currentConfigName = Utilities.GetActiveConfigurationName(nemerleOAProject);

            projectNode.SetConfiguration(currentConfigName);

            dte.ExecuteCommand("File.SaveAll", "");

            bool ok;
            projectNode.BuildTarget("Build", out ok);

            if (!ok)
            {
                var message = "There were build errors. Would you like to continue and run the last successful build?";
                OLEMSGICON icon = OLEMSGICON.OLEMSGICON_QUERY;
                OLEMSGBUTTON buttons = OLEMSGBUTTON.OLEMSGBUTTON_YESNO;
                OLEMSGDEFBUTTON defaultButton = OLEMSGDEFBUTTON.OLEMSGDEFBUTTON_FIRST;
                var res = VsShellUtilities.ShowMessageBox(projectNode.Site,
                    message, NemerleConstants.ProductName, icon, buttons, defaultButton);

                if (res == NativeMethods.IDNO)
                    return true;
            }

            var path = projectNode.GetProjectProperty("StartProgram");

            if (string.IsNullOrEmpty(path))
                path = projectNode.GetOutputAssembly(currentConfigName);

            if (!File.Exists(path))
                throw new ApplicationException("Visual Studio cannot start debugging because the debug target '"
                    + path + "' is missing. Please build the project and retry, or set the OutputPath and AssemblyName properties appropriately to point at the correct location for the target assembly.");

            if (string.Compare(Path.GetExtension(path), ".dll", StringComparison.InvariantCultureIgnoreCase) == 0)
                throw new ApplicationException("A project with an Output Type of Class Library cannot be started directly.\nAlso you can't use DLL as debug target.\n\nIn order to debug this project, add an executable project to this solution which references the library project. Set the executable project as the startup project.");

            var isConsole = PEReader.IsConsole(path);

            var cmdArgs = projectNode.GetProjectProperty("CmdArgs");
            var workingDirectory = projectNode.GetProjectProperty("WorkingDirectory");

            if (!string.IsNullOrEmpty(workingDirectory) && !Path.IsPathRooted(workingDirectory))
                workingDirectory = Path.Combine(projectNode.BaseURI.AbsoluteUrl, workingDirectory);

            if (string.IsNullOrEmpty(workingDirectory))
                workingDirectory = Path.GetDirectoryName(path);

            if (!Directory.Exists(workingDirectory))
                throw new ApplicationException("The working directory '" + workingDirectory + "' not exists.");

            var psi = new ProcessStartInfo();
            string cmdFilePath = null;

            if (isConsole)
            {
                // Make temp cmd-file and run it...
                cmdFilePath = Path.Combine(Path.GetDirectoryName(path), Path.GetTempFileName());
                cmdFilePath = Path.ChangeExtension(cmdFilePath, "cmd");
                var oemCodePage = CultureInfo.CurrentCulture.TextInfo.OEMCodePage;
                var consoleEncoding = Encoding.GetEncoding(oemCodePage);
                File.WriteAllText(cmdFilePath, "@echo off\n\"" + path + "\" " + cmdArgs + "\npause",
                        consoleEncoding);
                psi.FileName = cmdFilePath;
            }
            else
            {
                psi.FileName = path;
                psi.Arguments = cmdArgs;
            }

            psi.WorkingDirectory = workingDirectory;

            var process = OsProcess.Start(psi);

            if (isConsole)
                DeleteTempCmdFile(process, cmdFilePath);

            return true;
        }
开发者ID:vestild,项目名称:nemerle,代码行数:93,代码来源:NemerleProjectNode.cs

示例2: AddToolBoxItem

        private void AddToolBoxItem(EnvDTE.DTE env)
        {
            EnvDTE.Window toolboxWindow = env.Windows.Item(EnvDTE.Constants.vsWindowKindToolbox);
            EnvDTE.ToolBox toolbox = (EnvDTE.ToolBox)toolboxWindow.Object;
            EnvDTE.ToolBoxTabs toolboxTabs = toolbox.ToolBoxTabs;

            EnvDTE.ToolBoxTab newTab = null;

            bool tabExists = false;
            foreach (EnvDTE.ToolBoxTab tab in toolboxTabs)
            {
                if (tab.Name == this.TabName)
                {
                    newTab = tab;
                    tabExists = true;
                    break;
                }
            }

            if (!tabExists)
            {
                newTab = toolboxTabs.Add(this.TabName);
            }

            newTab.Activate();
            env.ExecuteCommand("View.PropertiesWindow", "");
            newTab.ToolBoxItems.Item(1).Select();

            newTab.ToolBoxItems.Add(this.ComponentName, this.ComponentPath,
                EnvDTE.vsToolBoxItemFormat.vsToolBoxItemFormatDotNETComponent);

            env.Quit();
        }
开发者ID:mattberther,项目名称:vs-toolbox-installer,代码行数:33,代码来源:ToolboxInstallerBase.cs


注:本文中的EnvDTE.ExecuteCommand方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。