Visual Studio Macro: How to Programmatically Execute "File & # 8594; Save All"

I am looking for the equivalent of starting File β†’ Save All before some Rake macros.

What I still have:

Private Sub Pre_Rake()
        Dim i As Integer

        DTE.Documents.SaveAll()

        For i = 1 To DTE.Solution.Projects.Count
            If Not DTE.Solution.Projects.Item(i).Saved Then
                DTE.Solution.Projects.Item(i).Save()
            End If
        Next
End Sub

DTE.Documents.SaveAll works fine, but the for loop does not save the project files as I expected.

If I make a copy of the file in Solution Explorer, this file will not be included in the project file (.CSPROJ) after running Pre_Rake (). I still have to press CTRL-SHIFT-S or File β†’ Save All.

So, how to save everything with a Visual Studio macro?

+5
source share
2 answers

-, DTE.Documents.SaveAll (, , ).

DTE.ExecuteCommand("File.SaveAll")

File β†’ Save All.

+8

, For , , :

Sub SaveAllFiles()
    For i = 1 To DTE.Solution.Projects.Count
        If Not DTE.Solution.Projects.Item(i).Saved Then
            DTE.Solution.Projects.Item(i).Save()
        End If
        For j = 1 To DTE.Solution.Projects.Item(i).ProjectItems.Count
            If Not DTE.Solution.Projects.Item(i).ProjectItems.Item(j).Saved Then
                DTE.Solution.Projects.Item(i).ProjectItems.Item(j).Save()
            End If
        Next
    Next
End Sub
+2

All Articles