小規模なコミュニティ ディスカッションとして、使用している重要な Visual Studio マクロは何ですか?
私はそれらについて学び始めたばかりで、あなたの何人かがそれなしでは生きていけないことを聞きたい.
小規模なコミュニティ ディスカッションとして、使用している重要な Visual Studio マクロは何ですか?
私はそれらについて学び始めたばかりで、あなたの何人かがそれなしでは生きていけないことを聞きたい.
次の 3 つのマクロのツールバーにボタンを追加します。それぞれが任意のファイルで現在選択されているテキストを取得し、それをグーグルで検索します(またはMSDN-it、またはスペルチェック-it)。追加のスタイル ポイントとして、ツールバーの気の利いたアイコンを作成します。
Private Const BROWSER_PATH As String = "C:\Program Files\Mozilla Firefox\firefox.exe"
Sub SearchGoogle()
Dim cmd As String
cmd = String.Format("{0} http://www.google.com/search?hl-en&q={1}", BROWSER_PATH, DTE.ActiveDocument.Selection.Text)
Shell(cmd, AppWinStyle.NormalFocus)
End Sub
Sub SearchMSDN()
Dim cmd As String
cmd = String.Format("{0} http://www.google.com/search?hl-en&q={1}+site%3Amsdn.microsoft.com", BROWSER_PATH, DTE.ActiveDocument.Selection.Text)
Shell(cmd, AppWinStyle.NormalFocus)
End Sub
Sub SpellCheck()
Dim cmd As String
cmd = String.Format("{0} http://www.spellcheck.net/cgi-bin/spell.exe?action=CHECKWORD&string={1}", BROWSER_PATH, DTE.ActiveDocument.Selection.Text)
Shell(cmd, AppWinStyle.NormalFocus)
End Sub
出力ウィンドウにビルド期間を表示する
このコードを EnvironmentEvents モジュールに入れます。これにより、ソリューションに対するアクション (ビルド、再構築、クリーン、デプロイ) の期間がビルド ウィンドウに直接書き込まれます。
IsBuild 関数を変更して、この情報を表示するアクションを指定できます。
Dim buildStart As Date
Private Function IsBuild(ByVal scope As EnvDTE.vsBuildScope, ByVal action As EnvDTE.vsBuildAction) As Boolean
Return scope = vsBuildScope.vsBuildScopeSolution
End Function
Private Sub BuildEvents_OnBuildBegin(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildBegin
If (IsBuild(Scope, Action)) Then
buildStart = Date.Now
End If
End Sub
Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildDone
If (IsBuild(Scope, Action)) Then
Dim buildTime = Date.Now - buildStart
WriteToBuildWindow(String.Format("Build time: {0}", buildTime.ToString))
End If
End Sub
Private Sub WriteToBuildWindow(ByVal message As String)
Dim win As Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
Dim ow As OutputWindow = CType(win.Object, OutputWindow)
For Each owPane As OutputWindowPane In ow.OutputWindowPanes
If (owPane.Name.Equals("Build")) Then
owPane.OutputString(message)
Exit For
End If
Next
End Sub
ソリューションを閉じた後にスタート ページを表示する (ただし、Visual Studio は開いたままにする)
このコードを EnvironmentEvents モジュールに入れます。
Private Sub SolutionEvents_AfterClosing() Handles SolutionEvents.AfterClosing
DTE.ExecuteCommand("View.StartPage")
End Sub
ソリューションを開いた後に開始ページを非表示にする
このコードを EnvironmentEvents モジュールに入れます。
Private Sub SolutionEvents_Opened() Handles SolutionEvents.Opened
Dim startPageGuid As String = "{387CB18D-6153-4156-9257-9AC3F9207BBE}"
Dim startPage As EnvDTE.Window = DTE.Windows.Item(startPageGuid)
If startPage IsNot Nothing Then startPage.Close()
End Sub
これら 2 つを一緒に使用すると、ソリューションを開いたときにスタート ページが非表示になります。ソリューションを閉じると、スタート ページが再び表示されます。
私は次のあまり知られていないショートカットを頻繁に使用します。
アウトライン: 定義に折りたたむが、領域を展開する
あなたは、すべての周りにリージョンを主張するショップの 1 つで働いていますか? そのため、定義に折りたたむと、コードが見えなくなりますか?
あなたが本当に必要としているのは、次のような崩壊から定義へ、しかし拡張領域へのマクロです:
Sub CollapseToDefinitionsButExpandAllRegions()
DTE.ExecuteCommand("Edit.CollapsetoDefinitions")
DTE.SuppressUI = True
Dim objSelection As TextSelection = DTE.ActiveDocument.Selection
objSelection.StartOfDocument()
Do While objSelection.FindText("#region",
vsFindOptions.vsFindOptionsMatchInHiddenText)
Loop
objSelection.StartOfDocument()
DTE.SuppressUI = False
End Sub
これを通常のマクロ モジュールに入れ、ホット キーに割り当てると、コードが元に戻ります。
(ただし...メソッド内にリージョンを配置する非常に悪質な個人と協力している場合は、残念ながらそれらのメソッドが拡張されます。それを回避するためにこれを記述する方法を誰かが知っている場合は、自由に編集してください。)
WiX の作業に最適な GUID を挿入し、ボタンまたはキー ショートカットとしてメニューに追加します。
Sub InsertGuid()
Dim objTextSelection As TextSelection
objTextSelection = CType(DTE.ActiveDocument.Selection(), EnvDTE.TextSelection)
objTextSelection.Text = System.Guid.NewGuid.ToString.ToUpper(New System.Globalization.CultureInfo("en", False))
End Sub
ソリューション内のすべての .cs ファイルの usings を整理する -元の作成者: djpark。
Sub OrganizeSolution()
Dim sol As Solution = DTE.Solution
For i As Integer = 1 To sol.Projects.Count
OrganizeProject(sol.Projects.Item(i))
Next
End Sub
Private Sub OrganizeProject(ByVal proj As Project)
For i As Integer = 1 To proj.ProjectItems.Count
OrganizeProjectItem(proj.ProjectItems.Item(i))
Next
End Sub
Private Sub OrganizeProjectItem(ByVal projectItem As ProjectItem)
Dim fileIsOpen As Boolean = False
If projectItem.Kind = Constants.vsProjectItemKindPhysicalFile Then
'If this is a c# file
If projectItem.Name.LastIndexOf(".cs") = projectItem.Name.Length - 3 Then
'Set flag to true if file is already open
fileIsOpen = projectItem.IsOpen
Dim window As Window = projectItem.Open(Constants.vsViewKindCode)
window.Activate()
projectItem.Document.DTE.ExecuteCommand("Edit.RemoveAndSort")
'Only close the file if it was not already open
If Not fileIsOpen Then
window.Close(vsSaveChanges.vsSaveChangesYes)
End If
End If
End If
'Be sure to apply RemoveAndSort on all of the ProjectItems.
If Not projectItem.ProjectItems Is Nothing Then
For i As Integer = 1 To projectItem.ProjectItems.Count
OrganizeProjectItem(projectItem.ProjectItems.Item(i))
Next
End If
'Apply RemoveAndSort on a SubProject if it exists.
If Not projectItem.SubProject Is Nothing Then
OrganizeProject(projectItem.SubProject)
End If
End Sub
ソリューション パネルのすべてのノードを折りたたみます。特に大きなプロジェクトの場合に非常に便利です。
Public Module CollapseAllNodes
Sub RunCollapseAllNodes()
Dim UIHSolutionExplorer As UIHierarchy
UIHSolutionExplorer = DTE.Windows.Item(Constants.vsext_wk_SProjectWindow).Object()
' Check if there is any open solution
If (UIHSolutionExplorer.UIHierarchyItems.Count = 0) Then
Return
End If
' Get the top node (the name of the solution)
Dim UIHSolutionRootNode As UIHierarchyItem
UIHSolutionRootNode = UIHSolutionExplorer.UIHierarchyItems.Item(1)
CloseRecursif(UIHSolutionRootNode)
' Select the solution node, or else when you click
' on the solution windows scrollbar, it will synchronize the open document
' with the tree and pop out the corresponding node which is probably not
' what you want.
UIHSolutionRootNode.Select(vsUISelectionType.vsUISelectionTypeSelect)
End Sub
Function CloseRecursif(ByRef element)
For Each UIHChild In element.UIHierarchyItems()
CloseRecursif(UIHChild)
If (UIHChild.UIHierarchyItems.Expanded = True) Then
UIHChild.UIHierarchyItems.Expanded = False
End If
Next
End Function
End Module
コード例をブログ投稿や電子メールに貼り付ける場合は、JeffのFormatToHtmlマクロを使用します。
私はデュアル モニターで作業していますが、Sharon のレイアウト切り替えマクロ (1 モニターから 2 モニター レイアウトへ) は非常に貴重です。コードを少し入力しているときに Web ページや他のプログラムを参照する必要がある場合は、Ctrl-Alt-1 を押して、Visual Studio ウィンドウの 1 つのモニター レイアウトに切り替えます。完了したら、Ctrl-Alt-2 を押して 2 台のモニター レイアウトに切り替え、すべてのウィンドウを元に戻します。素晴らしい!
http://www.invisible-city.com/sharon/2008/06/workstation-hack-visual-studio-on-2.html
それ自体はマクロではありませんが、便利です:
Public Sub WriteToOutputWindow(ByVal pane as String, ByVal Msg As String)
Dim owPane As OutputWindowPane
Dim win As Window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
Dim ow As OutputWindow = win.Object
Try
owPane = ow.OutputWindowPanes.Item(pane)
Catch
owPane = ow.OutputWindowPanes.Add(pane)
End Try
If Not owPane Is Nothing Then
owPane.Activate()
owPane.OutputString(Msg & vbCrLf)
End If
End Sub
レジストリ形式で GUID を生成するマクロに ctrl-shift-G をマップしました - これは IDL の編集に役立ちます
現在、コーディング標準が異なる 2 つのプロジェクトに取り組んでいます。1 つは行頭にタブを使用し、もう 1 つはスペースを使用します。このマクロは、現在アクティブな環境に基づいて、使用される標準を切り替えます。
Public Sub ToggleTabs()
If DTE.ActiveDocument.Language = "CSharp" Then
Dim currentSetting As Boolean = DTE.Properties("TextEditor", "CSharp").Item("InsertTabs").Value
DTE.Properties("TextEditor", "CSharp").Item("InsertTabs").Value = Not currentSetting
End If
If DTE.ActiveDocument.Language = "SQL" Then
Dim currentSQLSetting As Boolean = DTE.Properties("TextEditor", "SQL").Item("InsertTabs").Value
DTE.Properties("TextEditor", "SQL").Item("InsertTabs").Value = Not currentSQLSetting
End If
If DTE.ActiveDocument.Language = "HTML" Then
Dim currentHTMLSetting As Boolean = DTE.Properties("TextEditor", "HTML").Item("InsertTabs").Value
DTE.Properties("TextEditor", "HTML").Item("InsertTabs").Value = Not currentHTMLSetting
End If
If DTE.ActiveDocument.Language = "JScript" Then
Dim currentJScriptSetting As Boolean = DTE.Properties("TextEditor", "JScript").Item("InsertTabs").Value
DTE.Properties("TextEditor", "JScript").Item("InsertTabs").Value = Not currentJScriptSetting
End If
End Sub
私は VS 2002/2003 で多くのマクロを使用していました。1 つの例は、リージョンの作成です。私は常に、クラスを「プライベート メンバー」、「パブリック プロパティ」、「パブリック メソッド」、および「プライベート メソッド」のリージョンに分割することを好みます。そのため、新しいクラス ファイルにこれらの領域を作成するショートカット キーにマクロをマップしました。
VS 2005/2008 でのリファクタリングのサポート (および一般的なコード スニペットを追加する機能) と、DXCore や SlickEdit などのアドインの使用により、あまり多くのマクロを作成する必要がなくなりました。
この質問に言及せずにこの質問を手放すことはできませんでした。インストール方法と使用方法を示すビデオもあります。このマクロを使用すると、ソリューション エクスプローラーでネストされたファイル (resources.resx など) を作成できます。
編集:リンクを更新しました