I need to create a VB.NET application that takes the source code of a Windows Form Application and compiles it. I used this link as a reference.
Windows Form Application that I want to create
Public Class Form2
Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
MsgBox("test")
End Sub
End Class
My VB.NET application that compiles the code
Imports System.IO
Imports System.Reflection
Imports System.CodeDom
Imports System.CodeDom.Compiler
Imports Microsoft.VisualBasic
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim codeProvider As New VBCodeProvider()
Dim icc As ICodeCompiler = codeProvider.CreateCompiler
Dim Output As String = "Out.exe"
Dim ButtonObject As Button = CType(sender, Button)
textBox2.Text = ""
Dim parameters As New CompilerParameters()
Dim results As CompilerResults
'Make sure we generate an EXE, not a DLL
parameters.GenerateExecutable = True
parameters.OutputAssembly = Output
results = icc.CompileAssemblyFromSource(parameters, textBox1.Text)
If results.Errors.Count > 0 Then
'There were compiler errors
textBox2.ForeColor = Color.Red
Dim CompErr As CompilerError
For Each CompErr In results.Errors
textBox2.Text = textBox2.Text &
"Line number " & CompErr.Line &
", Error Number: " & CompErr.ErrorNumber &
", '" & CompErr.ErrorText & ";" &
Environment.NewLine & Environment.NewLine
Next
Else
'Successful Compile
textBox2.ForeColor = Color.Blue
textBox2.Text = "Success!"
'If we clicked run then launch the EXE
If ButtonObject.Text = "Run" Then Process.Start(Output)
End If
End Sub
Textbox1.text contains the first code i provided. When i run the program it gives me this errors
Line number 0, Error Number: BC30420, ''Sub Main' was not found in 'Out'.;
Line number 2, Error Number: BC30002, 'Type 'EventArgs' is not defined.;
Line number 3, Error Number: BC30451, ''MsgBox' is not declared. It may be inaccessible due to its protection level.;
Line number 3, Error Number: BC32017, 'Comma, ')', or a valid expression continuation expected.;