将项目添加到宏中的错误列表

发布于 2024-10-21 00:28:32 字数 678 浏览 4 评论 0原文

如果宏执行期间出现问题,我想通知宏的用户。我想知道是否可以将项目添加到 Visual Studio 错误列表中?

可以从外接程序中执行此操作(例如此处),但我想从宏中做同样的事情。

编辑


为了进一步阐明我想要实现的目标,这里是 Samples 宏库中的示例(Alt+F8 -> Samples -> Utilities -> SaveView())

Sub SaveView()
    Dim name As String

    name = InputBox("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

而不是 MsgBox( “...”)警报我想将错误放入VS错误列表中。

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("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.

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

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

发布评论

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

评论(3

我很坚强 2024-10-28 00:28:32

您可以通过宏轻松在任务列表中添加项目。只需使用该文章中的 AddTaskToList 方法并将 m_objDTE 更改为 DTE。我已经尝试过并且有效。

但是,将项目添加到错误列表中可能是不可能的。您需要调用 VS 服务,请参阅如何在加载项中添加错误。我用这段代码创建了一个宏,但它不起作用。一般来说,VS 服务在宏中不起作用。我能够成功创建 ErrorListProvider。我可以访问它的方法和属性。但是调用ErrorListProvider.Task.Add导致COM异常。如果你想玩它,请注意以下几点:
如本文所述,您需要
从 GAC 中获取 4 个程序集,例如到 c:\dlls\ 目录。由于添加引用时 Macros IDE 不允许浏览,因此需要将这些 dll 复制到 ...\Microsoft Visual Studio 10.0\Common7\IDE\PublicAssemblies 目录中(将 10.0 更改为你的 VS 版本)。然后,当您在宏 IDE 中添加引用时,您应该会看到程序集。

GetService 函数始终返回Nothing。将以下字段添加到类中:

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

并在 GetService 函数中将行:更改

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

objService = serviceProvider.GetService(serviceType)

正如我所写,一切似乎都正常,但 ErrorListProvider.Task.Add 失败。

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.

感悟人生的甜 2024-10-28 00:28:32

我认为对于您的情况,将某些内容输出到您自己的输出窗格会更合适。错误列表通常用于用户正在处理的项目中的错误,而不是用于运行宏引起的错误。尤其是当有人说这是不可能的时候。 :)

输出到您自己的输出窗格非常简单:

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)

希望这会有所帮助。

干杯,

塞巴斯蒂安

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

メ斷腸人バ 2024-10-28 00:28:32

这不是你想要的吗?

如何:通过从 Visual Studio 加载项导航到错误列表来添加错误

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

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

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