繁体   English   中英

快速输入命令行参数进行 Visual Studio 调试?

[英]Quickly enter command-line parameters for Visual Studio debugging?

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

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

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

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

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

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

ALT+F5 ...输入参数... 回车

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

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

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

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

下面的宏应该会有所帮助。 打开“工具->宏->宏资源管理器”,然后创建新模块,编辑它,然后复制粘贴下面的代码。 所需的命令是 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 2012 中,您可以使用Alt+F7快捷方式直接访问项目属性。

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

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM