Macros, Automated Builds, & Visual Studio 2003

by Jake Watkins





     

Listing One



Dim projectCollection as EnvDTE.Projects

Dim counter as integer

projectCollection = DTE.Solution.Projects

For counter = 1 to projectCollection.count

    Dim aProject as Project

    aProject = projectCollection.Item(counter)

    if aProject.Kind = prjKind.prjKindCSharpProject then

        GenerateCSharpProjectBuild(aProject)

    end if

next





Listing Two

<csc ...>

    <references>

        ....

    </references>

    <resources>

        ...

    </resources>

    <sources>

        ...

    </sources>

</csc>





Listing Three

Dim outputFileName As String

outputFileName = theProject.Properties.Item("FullPath").Value & "\" & 

                                             theProject.Name & ".build"

Dim xmlWriter As New XmlTextWriter(outputFileName,  _ 

                                      System.Text.ASCIIEncoding.ASCII)

xmlWriter.Formatting = Formatting.Indented



Listing Four



<property name="outputAssembly" value="C:\work\keep\sample\${outputSubDirectory}\sample.exe"/>



Listing Five



'Write a NANT property element

Private Sub WritePropertyElement(ByVal writer As XmlTextWriter, 

         ByVal propertyName As String, ByVal propertyValue As String)

    writer.WriteStartElement("property")



    writer.WriteAttributeString("name", propertyName)

    writer.WriteAttributeString("value", propertyValue)

    writer.WriteEndElement()

End Sub



Private Function GetOutputPath(ByVal theProject As Project)

    GetOutputPath = theProject.Properties.Item("FullPath").Value & 

               "${outputSubDirectory}\" & 

                theProject.Properties.Item("OutputFileName").Value

End Function



Listing Six



'Determine the project's type (exe, dll, etc)

Private Function GetProjectType(ByVal theProject As Project) As String

    Select Case CType(theProject.Properties.Item("OutputType").Value, Integer)

        Case 1

            GetProjectType = "exe"

        Case 2

            GetProjectType = "library"

        Case 0

            GetProjectType = "winexe"

        Case 4

            GetProjectType = "module"

    End Select

End Function



Listing Seven



'Returns the path to the references project's output

Private Function GetReferencedProjectOutput(ByVal refProject As Project) As String

  GetReferencedProjectOutput = refProject.Properties.Item("FullPath").Value & 

           "${outputSubDirectory}\" & _

            refProject.Properties.Item("OutputFileName").Value

End Function



Listing Eight



'Write the sources needed to compile the project

Private Sub WriteSourcesElement(ByVal theProject As Project, ByVal writer As XmlTextWriter)

    Dim counter As Integer

    writer.WriteStartElement("sources")

    writer.WriteAttributeString("basedir", theProject.Properties.Item("FullPath").Value)

    counter = 1

    For counter = 1 To theProject.ProjectItems.Count

        Dim projectFile As ProjectItem

        Dim filePath As String

        projectFile = theProject.ProjectItems.Item(counter)

        If "cs" = Right(projectFile.Name, 2) Then

            WriteIncludeElement(projectFile.Name, writer)

        End If

    Next

    writer.WriteEndElement()

End Sub



















6





