如何写入 Visual Studio 2010 AddIn 中的输出窗口?

发布于 2024-12-09 23:16:30 字数 276 浏览 1 评论 0原文

我正在编写一个简单的 Visual Studio 2010 插件来完成工作中的常见复制工作(从 libs sln 获取 dll)。

我希望将复制进度写入输出窗口。

我尝试了 Trace.WriteLine(...) 希望能够成功,但当我在调试器中运行加载项时却没有成功。我还没有尝试过任何其他方式。

我在 Visual Studio 2008 中找到了一些这样做的示例,但所需的库无法引用。

谁能告诉我如何写入输出窗口?我的谷歌搜索技巧让我失败了。

I'm writing a simple Visual Studio 2010 Add-In to do a common copying job here at work (getting dlls from libs sln).

I want the progress of the copying to be written to the output window.

I tried Trace.WriteLine(...) expecting that to make it, but it doesn't when I run the add-in in the debugger. I have not tried it any other way yet.

I found some examples of doing that in Visual Studio 2008, but the required libs are not available to reference.

Can anyone point me to how to write to the output window? My googling skills have failed me.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

柏拉图鍀咏恒 2024-12-16 23:16:31

正如 Robert 指出的,John 的代码在没有 ActivePane 时会抛出异常。如果存在活动窗格,它将使用活动窗格。

我对 Robert 的示例遇到的一个问题是取决于创建窗格的位置,在我的例子中是 Exec 方法,每次运行时都会创建多个具有相同名称的窗格。

包括我如何解决这个问题的例子。很简单,首先检查窗口是否存在......

      Window           window           = _applicationObject.Windows.Item( EnvDTE.Constants.vsWindowKindOutput );
      OutputWindow     outputWindow     = ( OutputWindow )window.Object;
      OutputWindowPane outputWindowPane = null;

      for ( uint i = 1; i <= outputWindow.OutputWindowPanes.Count; i++ )
      {
        if ( outputWindow.OutputWindowPanes.Item( i ).Name.Equals( OUTPUT_WINDOW_NAME , StringComparison.CurrentCultureIgnoreCase ) )
        {
          outputWindowPane = outputWindow.OutputWindowPanes.Item( i );
          break;
        }
      }

      if ( outputWindowPane == null )
        outputWindowPane = outputWindow.OutputWindowPanes.Add( OUTPUT_WINDOW_NAME );

      outputWindowPane.OutputString( "Message" );

As Robert pointed out, John's code will throw an exception when there is no ActivePane. If there is an active pane, it will use whichever pane is active.

One issue I have with Robert's example is depending on where you create the pane, which in my case is the Exec method, it will create multiple panes with the same name each time it is run.

Including my example as to how I got around that issue. Pretty simple, just check for the existence of the window first...

      Window           window           = _applicationObject.Windows.Item( EnvDTE.Constants.vsWindowKindOutput );
      OutputWindow     outputWindow     = ( OutputWindow )window.Object;
      OutputWindowPane outputWindowPane = null;

      for ( uint i = 1; i <= outputWindow.OutputWindowPanes.Count; i++ )
      {
        if ( outputWindow.OutputWindowPanes.Item( i ).Name.Equals( OUTPUT_WINDOW_NAME , StringComparison.CurrentCultureIgnoreCase ) )
        {
          outputWindowPane = outputWindow.OutputWindowPanes.Item( i );
          break;
        }
      }

      if ( outputWindowPane == null )
        outputWindowPane = outputWindow.OutputWindowPanes.Add( OUTPUT_WINDOW_NAME );

      outputWindowPane.OutputString( "Message" );
若水般的淡然安静女子 2024-12-16 23:16:31

我正在编写一个 Visual Studio 插件并遇到了同样的问题,但是当尝试上述答案时,我发现该行:

outputWindow.ActivePane.Activate();

给出了错误。

NullReferenceException -- 未将对象引用设置为对象的实例。

不过我现在找到了一种稍微不同的方法来解决这个问题:

Window window = applicationObject.Windows.Item(Constants.vsWindowKindOutput);
OutputWindow outputWindow = (OutputWindow)window.Object;
OutputWindowPane owp;
owp = outputWindow.OutputWindowPanes.Add("new pane");
owp.OutputString("hello");

I am writing a Visual studio add-in and had the same problem, however when trying the above answer I found that the line:

outputWindow.ActivePane.Activate();

gave an error.

NullReferenceException -- Object reference not set to an instance of an object.

However I have now found a slightly different way to solve the problem:

Window window = applicationObject.Windows.Item(Constants.vsWindowKindOutput);
OutputWindow outputWindow = (OutputWindow)window.Object;
OutputWindowPane owp;
owp = outputWindow.OutputWindowPanes.Add("new pane");
owp.OutputString("hello");
ゃ人海孤独症 2024-12-16 23:16:30

我已经为我编写的宏完成了此操作:

Window window = dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
OutputWindow outputWindow = (OutputWindow) window.Object;
outputWindow.ActivePane.Activate();
outputWindow.ActivePane.OutputString(message);

这是 DTE 接口的链接:
http://msdn.microsoft.com/en-us/library /envdte.dte(v=VS.100).aspx

I've done this for a macro I wrote:

Window window = dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput);
OutputWindow outputWindow = (OutputWindow) window.Object;
outputWindow.ActivePane.Activate();
outputWindow.ActivePane.OutputString(message);

Here is a link for the DTE Interface:
http://msdn.microsoft.com/en-us/library/envdte.dte(v=VS.100).aspx

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文