开发者

Add item to Error List in Macro

I want to notify the user of the macro if something went wrong during the execution of the macro. I was wondering if it would be possible to add an item to the Visual Studio error list?

It is possible to do so from within an AddIn (like here), but I would like to do the same thing from a macro.

Edit


To further clarify what i want to achive, here is the sample from the Samples macro library (Alt+F8 -> Samples -> Utilities -> SaveView())

Sub SaveView()
    Dim name As String

    name = InputBox(开发者_C百科"Enter the name you want to save as:", "Save window layout")
    If (name = "") Then
        MsgBox("Empty string, enter a valid name.")
    Else
        DTE.WindowConfigurations.Add(name)
    End If
End Sub

Instead of the MsgBox("...") alert I want to put the error into the VS error list.


You can add an item in the Task List easily from your macro. Just use the AddTaskToList method from that article and change m_objDTE to DTE. I've tried it and it worked.

However, adding the item in Error List, is probably impossible. You need to call VS services, see how adding an error is done in an add-in. I created a macro from this code and it didn't work. In general, VS services don't work in macros. I was able to create ErrorListProvider successfully. I could access it's methods and properties. But calling ErrorListProvider.Task.Add caused COM exception. If you want to play with it, several notes: As described in the article, you need to get 4 assemblies out of the GAC e.g. to c:\dlls\ directory. Since Macros IDE doesn't allow you to browse when you Add Reference, you need to copy these dlls into ...\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies directory (change the 10.0 to your VS version). Then, when you Add Reference in Macros IDE, you should see the assemblies.

The GetService function always returned Nothing. Add the following field to the class:

Private serviceProvider As IServiceProvider = New Microsoft.VisualStudio.Shell.ServiceProvider(CType(DTE, Microsoft.VisualStudio.OLE.Interop.IServiceProvider))

and in GetService function change line:

objService = Microsoft.VisualStudio.Shell.Package.GetGlobalService(serviceType)

to

objService = serviceProvider.GetService(serviceType)

As I wrote, everything seems OK then but ErrorListProvider.Task.Add fails.


I think that for your situation outputting something to your own output pane would be more suitable. The error list is generally used for errors within the project the user is working on, not for errors caused by running macros. Especially when someone says it can't be done. :)

Outputting to your own output pane is pretty easy:

DTE.Windows.Item(Constants.vsWindowKindOutput).Activate()
Dim panes As OutputWindowPanes = window.OutputWindowPanes
Dim my_pane As OutputWindowPane
Try
    my_pane = panes.Item("SaveView")
Catch exception As System.ArgumentException
    my_pane = panes.Add("SaveView")
End Try
my_pane.Activate()
my_pane.OutputString("Empty string, enter a valid name." + vbCrLf)

Hope this helps.

Cheers,

Sebastiaan


Is this not what you want?

HOWTO: Add an error with navigation to the Error List from a Visual Studio add-in

http://www.mztools.com/articles/2008/MZ2008022.aspx

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜