.NETGURU
C# Compile command line generator
Messages   Related Types
This message was discovered on ASPFriends.com 'aspngcodegiveawayswap' list.
Responses highlighted in red are from those people who are likely to be able to contribute good, authoratitive information to this discussion. They include Microsoft employees, MVP's and others who IMHO contribute well to these kinds of discussions.

Andy Smith (VIP)
For those of you who don't have Visual Studio .net, but want to be able
to compile c# projects you download and whatnot, here a little vbScript
which examines a .proj file, and tries to build the command line for it.

I know that it doesn't support all of the options, but I've found it
usefull for compiling simple libraries.

have fun, and if you expand it, just drop me a line with the changes
please?

===============================
Option Explicit

Dim p: Set p = New VStudioProjFile
p.Open WScript.Arguments(0)
p.Config = "Debug"
Dim cmdLine: cmdLine = p.GenerateCommandLine
Set p = Nothing

Call InputBox( "The Command Line", "The Command Line", cmdLine )

Class VStudioProjFile

Private Proj
Private ProjUser

Private compilerExe
Private compilerLanguage
Private commandLine
Private mConfig
Private mprojectFilePath

Private Sub Class_Initialize()
Set Proj = CreateObject("MSXML2.DOMDocument.4.0")
Proj.async = False
Call Proj.setProperty("SelectionLanguage", "XPath")

Set ProjUser = CreateObject("MSXML2.DOMDocument.4.0")
ProjUser.async = False
Call ProjUser.setProperty("SelectionLanguage", "XPath")

compilerExe = "csc.exe "
compilerLanguage = "CSHARP"
commandLine = ""
mConfig = ""
End Sub

Public Sub Open( projectFilePath )
mprojectFilePath = projectFilePath
If( projectFilePath <> "" ) Then
Call Proj.load( projectFilePath )
Call ProjUser.load( projectFilePath & ".user" )
If ( ProjUser.parseError.errorCode <> 0 ) Then
Set ProjUser = Nothing
End If
Else
MsgBox( "File Path was empty" )
End If

End Sub

Public Property Get Config()
Config = mConfig
End Property
Public Property Let Config( value )
mConfig = value
End Property

Public Function GenerateCommandLine()

Call AppendOption( compilerExe )
Call AppendOption( "/nologo" )

Dim outputExtension
Select Case GetSettingsAttribute( "OutputType" )
Case "Library"
AppendOption( "/target:library" )
outputExtension = "dll"
''TODO: Add More Cases
End Select

Call AppendOption( "/out:" & GetConfigAttribute( "OutputPath" )
& GetSettingsAttribute( "AssemblyName" ) & "." & outputExtension )

If ( InStr( GetConfigAttribute( "DefineConstants" ), "DEBUG" ) >
0 ) Then
Call AppendOption( "/debug" )
End If

If ( GetConfigAttribute( "DocumentationFile" ) <> "" ) Then
Call AppendOption( "/doc:" & GetConfigAttribute(
"DocumentationFile" ) )
End If

Call SpecifyLibrary()
Call SpecifyReferences()
Call SpecifyInputFiles()

GenerateCommandLine = commandLine

End Function

Private Sub SpecifyLibrary()
If TypeName( Projuser ) = "Nothing" Then Exit Sub

Dim settingsSection
Set settingsSection = ProjUser.selectSingleNode(
"/VisualStudioProject/" & compilerLanguage & "/Build/Settings" )
Dim libs: libs = settingsSection.getAttribute( "ReferencePath" )
Set settingsSection = Nothing

If libs <> "" Then
libs = Split( libs, ";" )
Dim lib, shortLib
For Each lib in libs
shortLib = GetShortName( lib )
If ( shortLib <> "" ) Then
MsgBox "Adding " & shortLib
Call AppendOption( "/lib:" & GetShortName( lib ) )
Else
MsgBox "Not Adding " & lib
End If
Next
End If
End Sub

Private Function GetShortName( path )
Dim fso: Set fso = CreateObject("Scripting.FileSystemObject")
On Error Resume Next
Dim folder: Set folder = fso.GetFolder( path )
If Err Then
GetShortName = ""
Else
GetShortName = folder.ShortPath
End If
Set folder = Nothing
Set fso = Nothing
End Function

Private Sub SpecifyReferences()
Dim referencesSection
Set referencesSection = Proj.selectNodes(
"/VisualStudioProject/" & compilerLanguage &
"/Build/References/Reference" )

Dim refList, i
If referencesSection.length > 0 Then
refList = "/r:"

refList = refList & referencesSection.item(0).getAttribute(
"AssemblyName" ) & ".dll"

For i = 1 To referencesSection.length - 1
refList = refList & ";" &
referencesSection.item(i).getAttribute( "AssemblyName" ) & ".dll"
Next
End If
Set referencesSection = Nothing

Call AppendOption( refList )
End Sub

Private Sub SpecifyInputFiles()
Dim filesSection
Set filesSection = Proj.selectNodes( "/VisualStudioProject/" &
compilerLanguage & "/Files/Include/File[@SubType=""Code"" and
@BuildAction = ""Compile""]" )

Dim fileRef
For Each fileRef In filesSection
Call AppendOption( fileRef.getAttribute( "RelPath" ) )
Next
End Sub

Private Sub AppendOption( text )
commandLine = commandLine & text & " "
End Sub

Private Function GetConfigAttribute( key )
Dim configSection
Dim path: path = "/VisualStudioProject/" & compilerLanguage &
"/Build/Settings/Config[@Name = """ & Config & """]"
Set configSection = Proj.selectSingleNode( path )
GetConfigAttribute = configSection.getAttribute( key )
Set configSection = Nothing
End Function

Private Function GetSettingsAttribute( key )
Dim settingsSection
Set settingsSection = Proj.selectSingleNode(
"/VisualStudioProject/" & compilerLanguage & "/Build/Settings" )
GetSettingsAttribute = settingsSection.getAttribute( key )
Set settingsSection = Nothing
End Function

End Class

__
Andy Smith
Chief Code Monkey

Reply to this message...
 
    
Steven A Smith (VIP)
Hmm... I've been looking for a way to compile custom controls on the server
(using an ASP.NET page to kick off the compile) -- do you think we could make
this do that?

Steve

----- Original Message -----
From: "Andy Smith" <Click here to reveal e-mail address>
To: "aspngcodegiveawayswap" <Click here to reveal e-mail address>
Sent: Wednesday, January 16, 2002 4:34 AM
Subject: [aspngcodegiveawayswap] C# Compile command line generator

[Original message clipped]

Reply to this message...
 
    
Steven A Smith (VIP)
Well, I was thinking something like a web form that you upload a component to,
which then on submit calls your handy script on the component (via a .NET call
to run a command line program) and dump the resulting DLL into the /bin folder.
What do you think?

Steve

Steven Smith, ASP.NET MVP, MCSE+Internet
Click here to reveal e-mail address
President, ASPAlliance.com
http://aspalliance.com The #1 ASP.NET Community
http://aspsmith.com ASP.NET Training for ASP Developers

Learning ASP.NET? Get My Book: ASP.NET By Example
http://www.amazon.com/exec/obidos/ASIN/0789725622/stevenatorasp/
----- Original Message -----
From: "Andy Smith" <Click here to reveal e-mail address>
To: "aspngcodegiveawayswap" <Click here to reveal e-mail address>
Sent: Wednesday, January 16, 2002 9:51 PM
Subject: [aspngcodegiveawayswap] Re: C# Compile command line generator

[Original message clipped]

Reply to this message...
 
 
System.Reflection.AssemblyName




ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
Ad


Need Dot Net Interview Questions?
Ask ExamGuru, Inc. for advice and help on Passing .Net Interviews
.Net Projects
Best-of-breed application framework for .NET projects, developed by ExamGuru, Inc. and ExamGuru IT
Free .net Help
Commission ExamGuru, Inc. and his team for your next bespoke software project
FogBUGZ
The only bug tracking system carefully crafted with one goal in mind: helping teams create great software.
Awesome Tools
If you don't know about these, you're missing out... IT Certification Questions
IT Interview Questions
Free Oracle 10g Training
MCSE Boortcamp
Cisco Study Guides
Cheap Study Guides
Exact Questions
Dot Net Interview Questions
Oracle OCP
Cheap Travel
Designer Perfumes - Wholesale Prices
Free Programming Tutorials
 
ExamGuru IT Solutions - .Net Guru is owned and operated by ExamGuru, Inc., the man behind .Net Guru. If you're in the market for bespoke software or software consultancy, why not get him and his highly trained team to help? - www.examguru.net/ITCertification
 Copyright © ExamGuru, Inc. 2001-2006
Contact Us - Terms of Use - Privacy Policy - www.dot-net-guru.com - www.examguru.net - www.oraclesource.net - www.itinterviews.net - www.examguru.net/ITCertification