-
Notifications
You must be signed in to change notification settings - Fork 17
/
Compile.vb
38 lines (28 loc) · 1.33 KB
/
Compile.vb
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
Imports System.CodeDom.Compiler
Public Class CS
Public Shared Sub Compile(ByVal Output As String, ByVal Source As String, ByVal Icon As String)
On Error Resume Next
Dim Compiler As ICodeCompiler = (New VBCodeProvider).CreateCompiler()
Dim Parameters As New CompilerParameters()
Dim cResults As CompilerResults
Parameters.GenerateExecutable = True
Parameters.OutputAssembly = Output
Parameters.ReferencedAssemblies.Add("System.dll")
Parameters.ReferencedAssemblies.Add("System.Data.dll")
Parameters.ReferencedAssemblies.Add("System.Windows.Forms.dll")
Parameters.CompilerOptions = "/platform:X86 /target:winexe"
Dim ICO As String = IO.Path.GetTempPath & "\iCompiler.ico"
If Icon <> "" Then
IO.File.Copy(Icon, ICO)
Parameters.CompilerOptions &= " /win32icon:" & ICO
End If
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
If Icon <> "" Then : IO.File.Delete(ICO) : End If
End Sub
End Class