When we regenerate our DAL and new entities, views, lists, procs are created, the new files are added to the project but those files are not automatically added to source control. We end up having to remove each new file from the project and re-add them manually. This process automatically adds the files to source control...
But how much fun is that?
Behold this VS macro which iterates through all of the files in the selected project (make sure you select a project before running the macro, derrrr) and adds each file to source control that isn't already added.
It basically performs the same steps as mentioned above (remove from project, add back to project).
It's probably not bullet proof and it only works with .cs files (easily fixable).. I hacked it together pretty quickly so use at your discression.
IncludeItemsInTFS is the macro you'll want to run.
Sub IncludeItemsInTFS()
Dim window As Window
Dim target As Object
window = DTE.Windows.Item(Constants.vsWindowKindCommandWindow)
Dim myDTE As DTE2 = CType(DTE, DTE2)
If (DTE.ActiveWindow Is window) Then
target = window.Object
Else
target = GetOutputWindowPane("List Project")
target.Clear()
End If
DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
Dim proj As Project = myDTE.SelectedItems.Item(1).Project
target.OutputString("Starting at:" & DateTime.Now.ToString("G"))
target.OutputString(Microsoft.VisualBasic.Constants.vbCrLf)
ListProjAux(proj.ProjectItems, 0, target)
target.OutputString("Ending at:" & DateTime.Now.ToString("G"))
target.OutputString(Microsoft.VisualBasic.Constants.vbCrLf)
MsgBox("Done")
End Sub
Sub ListProjAux(ByVal projectItems As EnvDTE.ProjectItems, ByVal level As Integer, ByVal outputWinPane As Object)
Dim projectItem As EnvDTE.ProjectItem
For Each projectItem In projectItems
'' Ignore item if it is not rooted in this collection (check for VC project model).
If projectItem.Collection Is projectItems Then
Dim projectItems2 As EnvDTE.ProjectItems
Dim notSubCollection As Boolean
Dim fileName As String = projectItem.FileNames(1)
If fileName.Contains(".cs") And Not DTE.SourceControl.IsItemUnderSCC(projectItem.FileNames(1)) Then
projectItem.Remove()
projectItems.AddFromFile(fileName)
OutputItem(projectItem, level, outputWinPane)
End If
'' Recurse if this item has subitems ...
projectItems2 = projectItem.ProjectItems
notSubCollection = projectItems2 Is Nothing
If Not notSubCollection Then
ListProjAux(projectItems2, level + 1, outputWinPane)
End If
End If
Next
End Sub
Sub OutputItem(ByVal projectItem As EnvDTE.ProjectItem, ByVal level As Integer, ByVal outputWinPane As Object)
Dim i As Integer = 0
While (i < level)
outputWinPane.OutputString(" ")
i = i + 1
End While
outputWinPane.OutputString(projectItem.FileNames(1))
outputWinPane.OutputString(Microsoft.VisualBasic.Constants.vbCrLf)
End Sub
Function GetOutputWindowPane(ByVal Name As String, Optional ByVal show As Boolean = True) As OutputWindowPane
Dim window As Window
Dim outputWindow As OutputWindow
Dim outputWindowPane As OutputWindowPane
window = DTE.Windows.Item(EnvDTE.Constants.vsWindowKindOutput)
If show Then window.Visible = True
outputWindow = window.Object
Try
outputWindowPane = outputWindow.OutputWindowPanes.Item(Name)
Catch e As System.Exception
outputWindowPane = outputWindow.OutputWindowPanes.Add(Name)
End Try
outputWindowPane.Activate()
Return outputWindowPane
End Function
I'm going to get in trouble if I spend any more time on this.