2011-03-28 163 views
20

我想改變我的命令行參數,然後調試我的可執行文件。快速輸入用於Visual Studio調試的命令行參數?

在默認Visual Studio的用戶界面,這需要我幾個曲折的鼠標和鍵盤操作:

項目...右鍵單擊...配置屬性... ...調試命令參數... 型ARGS ... ... ENTER F5

有沒有一種方法,使這項共同行動容易,因爲其他常見的操作,例如,搜索肚裏的模式中的所有文件:

CNTL + SHIFT + F ... 類型的搜索模式 ... ENTER

例如,是否有創建一個自定義編輯框,以便快速進入調試命令行參數的方式?或者有一個鍵綁定的方式彈出一個簡單的「調試對話框」,其中可以輸入參數並直接進行調試?例如

ALT + F5 ... 型ARGS ... ENTER

我使用C++和Visual Studio 2010速成。謝謝!

+1

好像你可以爲此寫一個宏。記錄它,然後編輯它來提示而不是使用鍵入的文本。分配一個熱鍵,你非常接近? – 2011-03-28 15:24:33

+0

@CraigStuntz - 宏記錄器不會記錄您在模態對話框中執行的任何操作。 – voetsjoeba 2012-06-08 19:20:50

+0

它也值得考慮[不同的方法](http://stackoverflow.com/questions/4791140/how-do-i-start-a-program-with-arguments-when-debugging);請參閱使用編譯器指令的Øyvind解決方案。 – 2013-09-21 20:28:16

回答

8

下面的宏應該有所幫助。打開「工具 - >宏 - >宏瀏覽器」,然後創建新模塊,編輯它,然後複製粘貼下面的代碼。所需的命令是SetCommandArgsProperty。用戶界面不好,但它的工作原理(VS 2005,我希望這也可以在VS 2010中工作)。然後添加你喜歡的任何快捷方式來運行這個宏。

這裏還有一些細節:

  • 查找啓動項目
  • 選擇激活它的配置和名稱爲「CommandArguments」
  • 在它的當前值創建編輯框中
  • 更新找物業財產如果確定選擇

    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 
    
+0

不幸的是我只有Visual Studio Express,所以沒有宏。但我喜歡這種飲料。 – paperjam 2011-03-28 17:00:39

11

擴展CLIArgsMadeEasy 2010/2012是一個很棒的小東西,它將項目的調試會話的命令行參數放在Visual Studio工具欄IMO的一個小文本框中,它比使用宏更簡單,更簡單。

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

您只需在擴展管理器,它會發現它很快在畫廊搜索框中鍵入CLIArgsMadeEasy,這就是我如何安裝它,如果你需要知道的。希望這可以幫助!

+1

+1 ATM這個版本只能與VS2010一起工作(不要被名字弄糊塗......)。這裏有一個VS2012版本:http://n0n4m3.codingcorner.net/?p=214。它的工作原理,但仍然有一些問題。 – 2013-07-12 14:27:42

+0

是否有VS2013的版本? – kdmin 2014-06-25 11:54:33

+3

@kdmin:是的,這裏http://n0n4m3.codingcorner.net/?p=1056 – 2014-10-29 16:10:12

4

至少在Visual Studio 2012中,可以使用Alt+F7快捷方式直接訪問項目屬性。

此外,打開的屬性頁面通常會記住最後打開的項目,即Configuration Properties -> Debugging