【问题标题】:Quickly enter command-line parameters for Visual Studio debugging?快速输入命令行参数进行 Visual Studio 调试?
【发布时间】:2011-03-28 14:14:45
【问题描述】:

我想更改我的命令行参数,然后调试我的可执行文件。

使用默认的 Visual Studio UI,这需要我进行几个曲折的鼠标和键盘操作:

项目...右键单击...配置属性...调试...命令参数...输入参数...ENTER ... F5

有没有办法让这个常见操作像其他常见操作一样简单,例如,在所有文件中搜索以下模式:

CNTL+SHIFT+F ... 键入搜索模式 ... ENTER

例如,有没有一种方法可以创建自定义编辑框以允许快速访问调试命令行参数?或者一种让键绑定弹出一个简单的“调试对话框”的方法,可以在其中输入参数并直接开始调试?例如

ALT+F5 ... 输入参数 ... ENTER

我正在使用 C++ 和 Visual Studio 2010 Express。谢谢!

【问题讨论】:

  • 似乎你可以为此编写一个宏。记录它,然后编辑它以提示而不是使用键入的文本。分配一个热键,你就很接近了吗?
  • @CraigStuntz -- 宏记录器不会记录您在模态对话框中所做的任何事情。
  • different approach 也值得考虑;请参阅 Øyvind 使用编译器指令的解决方案。

标签: c++ visual-studio visual-studio-2010 debugging


【解决方案1】:

扩展 CLIArgsMadeEasy 2010/2012 是一个很棒的小东西,它将项目的调试会话的命令行参数直接放在 Visual Studio 工具栏上的一个小文本框中,IMO,它比使用宏更容易且不那么乏味。

链接
http://visualstudiogallery.msdn.microsoft.com/8159cd7d-2c81-47f3-9794-a347ec1fba09?SRC=VSIDE

您可以在扩展管理器的搜索框中输入 CLIArgsMadeEasy,它会很快在图库中找到它,这就是我安装它的方式,如果您需要知道的话。希望这会有所帮助!

【讨论】:

  • +1 ATM 此版本仅适用于 VS2010(不要被命名混淆...)。不过这里有一个 VS2012 版本:n0n4m3.codingcorner.net/?p=214。它可以工作,但仍然存在一些问题。
  • 有VS2013的版本吗?
【解决方案2】:

下面的宏应该会有所帮助。打开“工具->宏->宏资源管理器”,然后创建新模块,编辑它,然后复制粘贴下面的代码。必需的命令是 SetCommandArgsProperty。 UI 不是很好,但它可以工作(VS 2005,我希望这也能在 VS 2010 中工作)。然后添加任何你喜欢的快捷方式来运行这个宏。

这里有一些细节:

  • 寻找启动项目
  • 选择活动配置并找到名称为“CommandArguments”的属性
  • 创建包含当前值的编辑框
  • 如果选择 OK,则更新属性

    Sub SetCommandArgsProperty()
        Dim newVal As Object
        newVal = InputValue(GetCommandArgsPropertyValue())
        If TypeOf newVal Is String Then
            SetCommandArgsProperty(newVal)
        End If
    End Sub
    
    Function InputValue(ByVal defaultText As String)
        Dim frm As New System.Windows.Forms.Form
        Dim btn As New System.Windows.Forms.Button
        Dim edit As New System.Windows.Forms.TextBox
    
        edit.Text = defaultText
        edit.Width = 100
    
        btn.Text = "OK"
        btn.DialogResult = System.Windows.Forms.DialogResult.OK
    
        frm.Text = "Input command line properties"
    
        frm.Controls.Add(btn)
        btn.Dock = System.Windows.Forms.DockStyle.Bottom
    
        frm.Controls.Add(edit)
        edit.Dock = System.Windows.Forms.DockStyle.Top
    
        frm.Height = 80
        frm.Width = 300
    
        If frm.ShowDialog() = System.Windows.Forms.DialogResult.OK Then
            Return edit.Text
        End If
        Return System.DBNull.Value
    End Function
    
    Function GetCommandArgsProperty() As EnvDTE.Property
        Dim solution As Solution
        Dim project As Project
        Dim sb As SolutionBuild
        Dim str As String
        Dim cm As ConfigurationManager
        Dim config As Configuration
        Dim properties As Properties
        Dim prop As EnvDTE.Property
    
        solution = DTE.Solution
        sb = solution.SolutionBuild
        For Each str In sb.StartupProjects
            project = solution.Item(str)
            cm = project.ConfigurationManager
            config = cm.ActiveConfiguration
            properties = config.Properties
            For Each prop In properties
                If prop.Name = "CommandArguments" Then
                    Return prop
                End If
            Next
        Next
    End Function
    
    Function GetCommandArgsPropertyValue()
        Return GetCommandArgsProperty().Value
    End Function
    
    Sub SetCommandArgsProperty(ByVal value As String)
        GetCommandArgsProperty().Value = value
    End Sub
    

【讨论】:

  • 不幸的是我只有 Visual Studio Express,所以没有宏。但我喜欢这个解决方案。
【解决方案3】:

至少在 Visual Studio 2012 中,您可以使用Alt+F7 快捷方式直接访问项目属性。

此外,打开的属性页通常会记住最后打开的项目,即Configuration Properties -> Debugging

【讨论】:

    猜你喜欢
    • 2010-09-22
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-08-23
    • 2017-08-30
    • 2019-06-08
    • 1970-01-01
    • 2019-05-25
    相关资源
    最近更新 更多