【问题标题】:Visual Studio 2008 macro only works from the Macro IDE, not the Macro ExplorerVisual Studio 2008 宏仅适用于宏 IDE,不适用于宏资源管理器
【发布时间】:2010-11-15 04:57:10
【问题描述】:

编辑:在同一个 VSMacros 项目中创建一个新模块解决了这个问题。


仅当我从 Visual Studio 打开宏 IDE 并从那里运行宏时,以下宏才有效。

如果我可以在我的 Visual Studio 实例中右键单击宏资源管理器中的宏,那将更加有用。

我肯定做错了什么,但我以前从未使用过 VS 宏。 MessageBox 在这两种情况下都不会出现。

Option Strict Off
Option Explicit Off
Imports System
Imports EnvDTE
Imports EnvDTE80
Imports EnvDTE90
Imports System.Diagnostics
Imports System.Security.Principal
Imports System.Windows.Forms

Public Module AttachToSdtProcess
    Sub AttachToSdtProcess()
        Try
            'If MessageBox.Show("Attach to SDT.exe", "Caption", _
            '            MessageBoxButtons.OKCancel) = DialogResult.Cancel Then
            'Return
            'End If

            Dim dbg2 As EnvDTE80.Debugger2 = DTE.Debugger
            Dim trans As EnvDTE80.Transport = dbg2.Transports.Item("Default")
            Dim compName As String = WindowsIdentity.GetCurrent().Name
            compName = compName.Substring(0, compName.IndexOf("\"))
            Dim proc2 As EnvDTE80.Process2 = _
                    dbg2.GetProcesses(trans, compName).Item("TheExecutable.exe")
            If proc2 Is Nothing Then
                MessageBox.Show("Could not find TheExecutable.exe")
            End If
            proc2.Attach2(dbgeng)
        Catch ex As System.Exception
            MsgBox(ex.Message)
        End Try
    End Sub
End Module

【问题讨论】:

  • 确实,“在同一个 VSMacros 项目中创建一个新模块解决了这个问题。”拯救了我的一天!它与下面标记为正确的“解决方案”无关。
  • 如果您使用的是 Visual Studio 2010 而不是 VSMacros,您应该在“示例”中创建新模块来解决这个奇怪的问题。

标签: visual-studio visual-studio-2008 macros


【解决方案1】:

来自 MSDN 上的 this 文章,我想我找到了另一个可能的答案。该线程的主要建议是:

在“工具”、“选项”菜单、“加载项/宏”安全部分中,选中“允许宏运行”复选框

【讨论】:

    【解决方案2】:

    宏编辑器中的消息框是:

    MsgBox("Your Text Here") = Resultxx
    

    祝你好运。

    【讨论】:

    猜你喜欢
    • 2017-02-08
    • 2021-12-19
    • 2019-11-03
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多