Programmatically Compiling

Woofer

Newcomer
Joined
Nov 15, 2002
Messages
5
Please help!!!

I want to programmatically compile a project that has a number of different forms that link together i.e. clicking on a button on one form closes that form and opens another form.

I have tried using the ICodeCompiler but errors have occured which I think are becuase the forms to be displayed have import statements.

Also, the only examples of programmatically compiling code I have seen have only had one source file, and I have several, so how do I deal with this?

Thanks
 
Please post all the relevant code you have so far, and exactly what requirements you have with regards to referencing assemblies and imports statements in the compiled assembly. Also what language you are targetting.
 
I am using VB.Net. and I need to import System.io

I attach the project that I wish to programmatically compile. The reason that I wish to programmatically compile the project is that my program will be changing some of the code in the 'pages' then compiling and running that program (increment 2d).

Thanks for you help
 

Attachments

Here's a code example for something that compiles a file on disk, adding references, to a Windows exe file.

Visual Basic:
        Dim c As CodeDom.Compiler.ICodeCompiler
        Dim p As New CodeDom.Compiler.CompilerParameters()
        Dim r As CodeDom.Compiler.CompilerResults
        Dim err As CodeDom.Compiler.CompilerError

        c = New Microsoft.VisualBasic.VBCodeProvider().CreateCompiler()

        'Set up compiler parameters here
        p.ReferencedAssemblies.Add("System.dll")
        p.ReferencedAssemblies.Add("System.Drawing.dll")
        p.ReferencedAssemblies.Add("System.Windows.Forms.dll")
        p.GenerateExecutable = True
        p.OutputAssembly = "c:\out.exe"
        p.CompilerOptions &= "/t:winexe"
        p.MainClass = "form1"

        'Compile
        r = c.CompileAssemblyFromFile(p, "c:\file.vb")

        'Analyse results
        If r.Errors.Count <> 0 Then
            'Show errors
            For Each err In r.Errors

            Next
        End If

        'Do something with compiled assembly (r.PathToAssembly)
 
Back
Top