Jump to content
Xtreme .Net Talk

Recommended Posts

Posted

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

Posted

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

code.txt

  • *Gurus*
Posted

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

 

       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)

MVP, Visual Developer - .NET

 

Now you see why evil will always triumph - because good is dumb.

 

My free .NET Windows Forms Controls and Articles

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...