' VBProjBuilder - Build .vsproj without Visual Studio .NET ' ' Tested with Visual Studio .NET 2003, Web Application project. Imports Microsoft.VisualBasic Imports System Imports System.Collections Imports System.Diagnostics Imports System.Text Imports System.Xml Public Class VBProjBuilder Public Shared Function Main(cmdArgs() As String) As Integer If Not cmdArgs.Length = 2 Then Console.WriteLine("Usage: " + ControlChars.NewLine + _ "VBProjBuilder.exe YourProjectFile.vbproj ConfigName") Return 1 End If Dim projFile As String = cmdArgs(0) Dim projConfig As String = cmdArgs(1) Dim projDom As XmlDocument Dim eRoot, eVB, eBuild, eSet, eConf, eRefs, eIms, eFiles, eInc As XmlElement Dim eConfList, eRefList, eImList, eFileList As XmlNodeList Dim comArgs As StringBuilder = New StringBuilder() projDom = New XmlDocument() projDom.Load(projFile) comArgs.Append("/nologo") eRoot = projDom.DocumentElement eVB = CType(eRoot.GetElementsByTagName("VisualBasic")(0), XmlElement) eBuild = CType(eVB.GetElementsByTagName("Build")(0), XmlElement) eSet = CType(eBuild.GetElementsByTagName("Settings")(0), XmlElement) If eSet.GetAttribute("ApplicationIcon") <> "" Then comArgs.Append(" /win32icon:" + eSet.GetAttribute("ApplicationIcon")) End If comArgs.Append(" /out:bin\" + eSet.GetAttribute("AssemblyName") + ".dll") comArgs.Append(" /target:" + eSet.GetAttribute("OutputType")) comArgs.Append(" /rootnamespace:" + eSet.GetAttribute("RootNamespace")) comArgs.Append(" /optioncompare:" + eSet.GetAttribute("OptionCompare")) If eSet.GetAttribute("OptionExplicit") = "On" Then comArgs.Append(" /optionexplicit+") Else comArgs.Append(" /optionexplicit-") End If If eSet.GetAttribute("OptionStrict") = "On" Then comArgs.Append(" /optionstrict+") Else comArgs.Append(" /optionstrict-") End If eConfList = eSet.GetElementsByTagName("Config") Dim confN As XmlNode Dim findConf As Boolean = False For Each confN In eConfList eConf = CType(confN, XmlElement) If eConf.GetAttribute("Name") = projConfig Then findConf = True Exit For End If Next If findConf = False Then Console.WriteLine("The config '" + projConfig + "' doesn't exist.") Return 1 End If If eConf.GetAttribute("DebugSymbols") = "true" Then comArgs.Append(" /debug+") Else comArgs.Append(" /debug-") End If If eConf.GetAttribute("TreatWarningsAsErrors") = "true" Then comArgs.Append(" /warnaserror+") Else comArgs.Append(" /warnaserror-") End If If eConf.GetAttribute("Optimize") = "true" Then comArgs.Append(" /optimize+") Else comArgs.Append(" /optimize-") End If If eConf.GetAttribute("RemoveIntegerChecks") = "true" Then comArgs.Append(" /removeintchecks+") Else comArgs.Append(" /removeintchecks-") End If comArgs.Append(" /out:" + eConf.GetAttribute("OutputPath") + _ eSet.GetAttribute("AssemblyName") + ".dll") comArgs.Append(" /libpath:" + eConf.GetAttribute("OutputPath")) eRefs = CType(eBuild.GetElementsByTagName("References")(0), XmlElement) eRefList = eRefs.GetElementsByTagName("Reference") Dim refN As XmlNode Dim ref As XmlElement For Each refN In eRefList ref = CType(refN, XmlElement) comArgs.Append(" /r:" + ref.GetAttribute("AssemblyName") + ".dll") Next eIms = CType(eBuild.GetElementsByTagName("Imports")(0), XmlElement) eImList = eIms.GetElementsByTagName("Import") Dim imN As XmlNode Dim im As XmlElement For Each imN In eImList im = CType(imN, XmlElement) comArgs.Append(" /imports:" + im.GetAttribute("Namespace")) Next eFiles = CType(eVB.GetElementsByTagName("Files")(0), XmlElement) eInc = CType(eFiles.GetElementsByTagName("Include")(0), XmlElement) eFileList = eInc.GetElementsByTagName("File") Dim fileN As XmlNode Dim file As XmlElement Dim comArgsFiles As StringBuilder = New StringBuilder() Dim comArgsRes As StringBuilder = New StringBuilder() For Each fileN In eFileList file = CType(fileN, XmlElement) Dim act As String = file.GetAttribute("BuildAction") Dim path As String = file.GetAttribute("RelPath") If act = "Compile" Then comArgsFiles.Append(" " + path) ElseIf act = "EmbeddedResource" comArgsRes.Append(" /res:" + path) End If Next comArgs.Append(" " + comArgsRes.ToString()) comArgs.Append(" " + comArgsFiles.ToString()) Console.WriteLine(comArgs.ToString()) Dim proc As Process = new Process() proc.StartInfo.Arguments = comArgs.ToString() proc.StartInfo.FileName = "vbc.exe" proc.StartInfo.UseShellExecute = False proc.Start() proc.WaitForExit() Return 0 End Function End Class