After alot of research online, i have came to the following conclusion which seems to be working just fine.
Thanks to everybody for any input on this subject.
First of all open a new project add the following code to a button.
This code compiles the code that you write in the text file that you will create in the next step.
Private Sub CompilerButton_Click(sender As System.Object, e As System.EventArgs) Handles CompilerButton.Click
Dim objCodeCompiler As System.CodeDom.Compiler.ICodeCompiler = New VBCodeProvider().CreateCompiler() ' We create object of the compiler
Dim objCompilerParameters As New System.CodeDom.Compiler.CompilerParameters()
' Add reference
objCompilerParameters.ReferencedAssemblies.Add("System.dll")
objCompilerParameters.ReferencedAssemblies.Add("System.Windows.Forms.dll")
objCompilerParameters.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll")
'Compile in memory
Dim Output1 As String = "OutputApp"
objCompilerParameters.GenerateExecutable = True
objCompilerParameters.OutputAssembly = Output1
objCompilerParameters.CompilerOptions = "/target:winexe"
Dim strCode As String = My.Resources.TextFile1.ToString
Dim objCompileResults As System.CodeDom.Compiler.CompilerResults = _
objCodeCompiler.CompileAssemblyFromSource(objCompilerParameters, strCode)
If objCompileResults.Errors.HasErrors Then
' If an error occurs
MsgBox("Error: Line>" & objCompileResults.Errors(0).Line.ToString & ", " & _
objCompileResults.Errors(0).ErrorText)
Exit Sub
End If
End Sub
And then in the projects resources add a text file and add the following code to it.
This code is your application that you want to compile to a standalone EXE. And you can change it to the way you want.
Option Strict On
Imports System
Imports System.Windows.Forms
Imports System.Windows.Forms.Form
Imports Microsoft.VisualBasic
Namespace MyApp
Public Class EntryPoint
Public Shared Sub Main(args As [String]())
Dim FrmMain As New Form1
System.Windows.Forms.Application.Run(FrmMain)
End Sub
End Class
Public Class Form1
Inherits System.Windows.Forms.Form
Private WithEvents Button1 As New Button
Sub New()
Application.EnableVisualStyles()
Me.Text = "Form1"
Button1.Text = "Click Me!"
Button1.Top = 100
Button1.Left = 100
Me.Controls.Add(Button1)
End Sub
Private Sub Button1_Click(Sender As Object, E As EventArgs) Handles Button1.Click
MsgBox("You Clicked Me!")
End Sub
End Class
End Namespace
If you have done everything above, after you click compile it should create a standalone EXE in the projects \bin\Debug under the name OutputApp.
Again thanks to everybody.
Hope the code above is useful to anyone who is trying to do the same thing.