Search:
Namespaces
Discussions
.NET v1.1
Feedback
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
Ad
MBR BootFX
Best-of-breed application framework for .NET projects, developed by Matthew Baxter-Reynolds and MBR IT
Copyright © Matthew Baxter-Reynolds 2001-2008. '.NET 247 Software Development Services' is a trading style of MBR IT Solutions Ltd.
Contact Us
-
Terms of Use
-
Privacy Policy
-
www.dotnet247.com