Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- Imports System.CodeDom.Compiler
- Public Class CodeDOM
- Private _Location As String
- Public Property Location() As String
- Get
- Return _Location
- End Get
- Set(ByVal value As String)
- _Location = value
- End Set
- End Property
- Private _Version As Dictionary(Of String, String)
- Public Property Version() As Dictionary(Of String, String)
- Get
- Return _Version
- End Get
- Set(ByVal value As Dictionary(Of String, String))
- _Version = value
- End Set
- End Property
- Private _ICO As String
- Public Property ICO() As String
- Get
- Return _ICO
- End Get
- Set(ByVal value As String)
- _ICO = value
- End Set
- End Property
- Private _References() As String
- Public Property References() As String()
- Get
- Return _References
- End Get
- Set(ByVal value As String())
- _References = value
- End Set
- End Property
- '@param {ParamArray} ReferencesIn: References to be compiled
- Public Sub AddReference(ParamArray ReferencesIn() As String)
- For Each Reference In ReferencesIn
- Array.Resize(References, References.Length + 1)
- References(References.Length - 1) = Reference
- Next
- End Sub
- 'Settings all the default values
- Sub New()
- ICO = IO.Path.GetTempPath & "\iCompiler.ico"
- References = New String() {}
- Version = New Dictionary(Of String, String)
- End Sub
- '@param {string} Output: File location as string
- '@param {string} Source: Source to be compiled
- Public Sub Compile(ByVal Source As String)
- On Error Resume Next
- If Location Is Nothing Then
- Dim result As Integer = MessageBox.Show("Do you want to choose a new location?", "Invalid Location", MessageBoxButtons.YesNo)
- If result = DialogResult.No Then
- Return
- ElseIf result = DialogResult.Yes Then
- NewSaveLocation()
- End If
- End If
- Dim Compiler As ICodeCompiler = (New VBCodeProvider).CreateCompiler()
- Dim Parameters As New CompilerParameters()
- Dim cResults As CompilerResults
- Parameters.GenerateExecutable = True
- Parameters.OutputAssembly = Location
- For Each Reference In References
- Parameters.ReferencedAssemblies.Add(Reference)
- Next
- cResults = Compiler.CompileAssemblyFromSource(Parameters, Source)
- If cResults.Errors.Count > 0 Then
- For Each CompilerError In cResults.Errors
- MessageBox.Show("Error: " & CompilerError.ErrorText, "", MessageBoxButtons.OK, MessageBoxIcon.Error)
- Next
- ElseIf cResults.Errors.Count = 0 Then
- End If
- End Sub
- Public Sub Run()
- If Location Is Nothing Then
- MessageBox.Show("Couldn't find your file", "Invalid File", MessageBoxButtons.OK)
- Return
- End If
- Process.Start(Location)
- End Sub
- Public Sub NewSaveLocation()
- Dim sfd As New SaveFileDialog
- sfd.Filter = "Executable *.exe | *.exe"
- ' sfd.Title = "Choose a fiel!"
- sfd.FileName = "Output.exe"
- If sfd.ShowDialog = DialogResult.OK Then
- Location = sfd.FileName
- End If
- End Sub
- End Class
Add Comment
Please, Sign In to add comment