使用 DTE 激活 Visual Studio 的输出 window
Activate Visual Studio's Output window using DTE
我为我的 VSPackage
:
创建了自定义 输出 window 窗格
使用此代码:
// Creating Output Window for our package.
IVsOutputWindow output = GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;
Guid guildGeneral = Microsoft.VisualStudio.VSConstants.OutputWindowPaneGuid.GeneralPane_guid;
int hr = output.CreatePane(guildGeneral, "Codex", 1, 0);
hr = output.GetPane(guildGeneral, out ApplicationConstants.pane);
ApplicationConstants.pane.Activate();
问题
如何在当前 select 编辑其他选项卡时 select 输出 选项卡?
激活(关注)Visual Studio 的 输出 window:
DTE dte = (DTE)GetService(typeof(DTE));
Window window = dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
window.Activate();
这是我的版本,更新到VS2019
class GetOutputPanel
{
private int retries;
public IVsOutputWindowPane pane;
void writeToOutputPanel(string txt)
{
ThreadHelper.ThrowIfNotOnUIThread();
pane.OutputString(txt);
}
void getOutputPanel(AsyncPackage package, EnvDTE80.DTE2 dte2)
{
ThreadHelper.ThrowIfNotOnUIThread();
EnvDTE.Window w = dte2.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
w.Activate();
var output_windows_opening_async = package.GetServiceAsync(typeof(SVsOutputWindow));
Timer timer = new Timer();
retries = 0;
timer.Tick += (object sender, EventArgs e) => {
ThreadHelper.ThrowIfNotOnUIThread();
if (pane != null)
{
(sender as Timer).Stop();
return;
}
if(!output_windows_opening_async.IsCompleted)
{
if(retries++ > 10) (sender as Timer).Stop();
return;
}
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
output_windows_opening_async.Wait();
IVsOutputWindow output = (output_windows_opening_async.Result) as IVsOutputWindow;
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
Guid guildGeneral = Microsoft.VisualStudio.VSConstants.OutputWindowPaneGuid.GeneralPane_guid;
output.CreatePane(guildGeneral, "Ambar - DEMO Builder", 1, 0);
output.GetPane(guildGeneral, out pane);
pane.Activate();
(sender as Timer).Stop();
};
timer.Interval = 1000;
timer.Start();
}
}
我为我的 VSPackage
:
使用此代码:
// Creating Output Window for our package.
IVsOutputWindow output = GetService(typeof(SVsOutputWindow)) as IVsOutputWindow;
Guid guildGeneral = Microsoft.VisualStudio.VSConstants.OutputWindowPaneGuid.GeneralPane_guid;
int hr = output.CreatePane(guildGeneral, "Codex", 1, 0);
hr = output.GetPane(guildGeneral, out ApplicationConstants.pane);
ApplicationConstants.pane.Activate();
问题
如何在当前 select 编辑其他选项卡时 select 输出 选项卡?
激活(关注)Visual Studio 的 输出 window:
DTE dte = (DTE)GetService(typeof(DTE));
Window window = dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
window.Activate();
这是我的版本,更新到VS2019
class GetOutputPanel
{
private int retries;
public IVsOutputWindowPane pane;
void writeToOutputPanel(string txt)
{
ThreadHelper.ThrowIfNotOnUIThread();
pane.OutputString(txt);
}
void getOutputPanel(AsyncPackage package, EnvDTE80.DTE2 dte2)
{
ThreadHelper.ThrowIfNotOnUIThread();
EnvDTE.Window w = dte2.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
w.Activate();
var output_windows_opening_async = package.GetServiceAsync(typeof(SVsOutputWindow));
Timer timer = new Timer();
retries = 0;
timer.Tick += (object sender, EventArgs e) => {
ThreadHelper.ThrowIfNotOnUIThread();
if (pane != null)
{
(sender as Timer).Stop();
return;
}
if(!output_windows_opening_async.IsCompleted)
{
if(retries++ > 10) (sender as Timer).Stop();
return;
}
#pragma warning disable VSTHRD002 // Avoid problematic synchronous waits
output_windows_opening_async.Wait();
IVsOutputWindow output = (output_windows_opening_async.Result) as IVsOutputWindow;
#pragma warning restore VSTHRD002 // Avoid problematic synchronous waits
Guid guildGeneral = Microsoft.VisualStudio.VSConstants.OutputWindowPaneGuid.GeneralPane_guid;
output.CreatePane(guildGeneral, "Ambar - DEMO Builder", 1, 0);
output.GetPane(guildGeneral, out pane);
pane.Activate();
(sender as Timer).Stop();
};
timer.Interval = 1000;
timer.Start();
}
}