Home
Help
Register
Log in

Search

 
   Active Threads  

You are here: Home > LLBLGen Pro > LLBLGen Pro Runtime Framework> Code generation and source control helper
 

Pages: 1
LLBLGen Pro Runtime Framework
Code generation and source control helper
Page:1/1 

  Print all messages in this thread  
Poster Message
alexdresko
User



Location:
Greenville, SC
Joined on:
08-Jun-2004 17:30:02
Posted:
336 posts
# Posted on: 08-Feb-2007 23:40:51.  
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. Regular Smiley

IncludeItemsInTFS is the macro you'll want to run.

Code:

    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. Regular Smiley
I'm not a player, I just code a lot.   Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37375 posts
# Posted on: 09-Feb-2007 10:18:10.  
Could you explain to me please why you have to remove a file from the project to get it added to sourcecontrol ? Doesn't team system detect new files and add them automatically or is this 'feature' build into vs.net's add new item, so it otherwise doesn't detect new files? (If so, I really feel sorry for the architect who cooked up that 'feature')

Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
alexdresko
User



Location:
Greenville, SC
Joined on:
08-Jun-2004 17:30:02
Posted:
336 posts
# Posted on: 09-Feb-2007 14:53:24.  
Otis wrote:
Could you explain to me please why you have to remove a file from the project to get it added to sourcecontrol ? Doesn't team system detect new files and add them automatically or is this 'feature' build into vs.net's add new item, so it otherwise doesn't detect new files? (If so, I really feel sorry for the architect who cooked up that 'feature')


Well, if you add a new file to a project under souce control (we're using TFS), it gets added to the repository automatically. However, it appears that if a third party app modifies the project file, TFS (or VS.NET.. don't know) doesn't do anything to the new files. There isn't even an option to right click on the file and select "include in source control". So excluding the file from the project and then re-including it is the only way we've found to get the files into source control.

Our project contains several hundred tables.. some of them containing a hundred or so fields. So you can imagine how long it takes to go through the entire project to do this for all the new entities that might get added.

And that's how we ended up with the macro above. It does everything in about 30 seconds! Regular Smiley
I'm not a player, I just code a lot.   Top
jspanocsi
User



Location:

Joined on:
04-Mar-2005 20:48:51
Posted:
145 posts
# Posted on: 09-Feb-2007 14:56:55.  
Hey Guys, Alex works with me. I posted this problem a long time ago and there wasn't a solution. It's a problem with TFS. I got tired of doing the add and remove and got Alex to create the macro so I didn't have to do it manually.

  Top
alexdresko
User



Location:
Greenville, SC
Joined on:
08-Jun-2004 17:30:02
Posted:
336 posts
# Posted on: 09-Feb-2007 15:37:23.  
jspanocsi wrote:
Hey Guys, Alex works with me. I posted this problem a long time ago and there wasn't a solution. It's a problem with TFS. I got tired of doing the add and remove and got Alex to create the macro so I didn't have to do it manually.

I'm the supreme macro master here at the office. I automate EVERYTHING! Regular Smiley
I'm not a player, I just code a lot.   Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37375 posts
# Posted on: 10-Feb-2007 14:49:57.  
alexdresko wrote:
Otis wrote:
Could you explain to me please why you have to remove a file from the project to get it added to sourcecontrol ? Doesn't team system detect new files and add them automatically or is this 'feature' build into vs.net's add new item, so it otherwise doesn't detect new files? (If so, I really feel sorry for the architect who cooked up that 'feature')


Well, if you add a new file to a project under souce control (we're using TFS), it gets added to the repository automatically. However, it appears that if a third party app modifies the project file, TFS (or VS.NET.. don't know) doesn't do anything to the new files. There isn't even an option to right click on the file and select "include in source control". So excluding the file from the project and then re-including it is the only way we've found to get the files into source control.

Ach... Shocked...

Closing vs.net, and reopening it won't work?. If you look at the XML in the csproj file, do you see any differences in elements for the files which are in sourcecontrol and the ones which aren't?

(we don't use TFS so I can't check that here)

Quote:
Our project contains several hundred tables.. some of them containing a hundred or so fields. So you can imagine how long it takes to go through the entire project to do this for all the new entities that might get added.

And that's how we ended up with the macro above. It does everything in about 30 seconds! Regular Smiley

I can imagine that such a macro is key for even use the stuff. If you can tell me if the XML is different, I could explain to you how to alter the project file task performer so it will get fixed for you automatically.


Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
Otis
LLBLGen Pro Team



Location:
The Hague, The Netherlands
Joined on:
17-Aug-2003 18:00:36
Posted:
37375 posts
# Posted on: 10-Feb-2007 14:50:28.  
jspanocsi wrote:
Hey Guys, Alex works with me. I posted this problem a long time ago and there wasn't a solution. It's a problem with TFS. I got tired of doing the add and remove and got Alex to create the macro so I didn't have to do it manually.

Microsoft acknowledged this as a problem in TFS? Hmm.
Frans Bouma
LLBLGen Pro / ORM Profiler Lead Developer | Blog | Twitter
 
Top
simbient
User



Location:

Joined on:
06-Aug-2009 05:24:54
Posted:
1 posts
# Posted on: 06-Aug-2009 05:33:03.  
I've gotten around this major flaw in TFS (I'm blaming TFS) by using a post-build event.

Code:
"$(DevEnvDir)tf.exe" add "$(ProjectDir)*.cs" /recursive
if %errorlevel% == 1 exit 0


You'll notice the IF statement, I've done this because it appears the "tf add" command returns an exit code of 1 if there are files that already exist in TFS.

I also had a look at the project file in notepad and did not see anything obvious as to why the new files are not automatically added.


  Top
Walaa
Support Team



Location:

Joined on:
21-Aug-2005 16:03:48
Posted:
14464 posts
# Posted on: 06-Aug-2009 09:22:00.  
Thanks for the feedback.
  Top
Pages: 1  


Powered by HnD ©2002-2007 Solutions Design
HnD uses LLBLGen Pro

Version: 2.1.12172008 Final.