本文整理汇总了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;
}
示例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();
}