从一个控制台应用程序自动化的Visual Studio 2010 [英] Automating Visual Studio 2010 from a console app

查看:301
本文介绍了从一个控制台应用程序自动化的Visual Studio 2010的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图运行下面的code(这是我从这里了>)。在code只是创建在Visual Studio中新的输出窗格中,写几行吧。

I am trying to run the following code (which I got from here). The code just creates a new "Output" pane in Visual Studio and writes a few lines to it.

Public Sub WriteToMyNewPane()
    Dim win As Window = _
       dte.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
    Dim ow As OutputWindow = win.Object
    Dim owPane As OutputWindowPane
    Dim cnt As Integer = ow.OutputWindowPanes.Count
    owPane = ow.OutputWindowPanes.Add("My New Output Pane")
    owPane.Activate()
    owPane.OutputString("My text1" & vbCrLf)
    owPane.OutputString("My text2" & vbCrLf)
    owPane.OutputString("My text3" & vbCrLf)
End Sub

而不是运行它作为一个宏观的,我要运行它连接到Visual Studio 2010中我有一个很难搞清楚如何设置的值<强的当前运行的实例一个独立的控制台应用程序> DTE 。我想我可能需要调用GetActiveObject,但我不知道怎么样。任何指针?

Instead of running it as a Macro, I want to run it as an independent console application that connects to a currently running instance of Visual Studio 2010. I'm having a hard time figuring out how to set the value of dte. I think I may need to call GetActiveObject, but I'm not sure how. Any pointers?

推荐答案

是的,这是有点可能,DTE接口支持外的进程激活。这里的样本code,显示方式:

Yes, this is somewhat possible, the DTE interface supports out-of-process activation. Here's sample code that shows the approach:

Imports EnvDTE

Module Module1
    Sub Main()
        Dim dte As DTE = DirectCast(Interaction.CreateObject("VisualStudio.DTE.10.0"), EnvDTE.DTE)
        dte.SuppressUI = False
        dte.MainWindow.Visible = True
        Dim win As Window = dte.Windows.Item(Constants.vsWindowKindOutput)
        Dim ow As OutputWindow = DirectCast(win.Object, OutputWindow)
        Dim owPane As OutputWindowPane = ow.OutputWindowPanes.Add("My New Output Pane")
        owPane.Activate()
        owPane.OutputString("My text1" & vbCrLf)
        owPane.OutputString("My text2" & vbCrLf)
        owPane.OutputString("My text3" & vbCrLf)
        Console.WriteLine("Press enter to terminate visual studio")
        Console.ReadLine()
    End Sub
End Module

在previous到最后一条语句说明了为什么这是不是真的实用。只要你的程序停止运行时,在组件类的最后一个引用计数消失,使得Visual Studio中退出。

The previous to last statement shows why this isn't really practical. As soon as your program stops running, the last reference count on the coclass disappears, making Visual Studio quit.

这篇关于从一个控制台应用程序自动化的Visual Studio 2010的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
相关文章
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆