Files
2026-08-27 11:04:21 -06:00

97 lines
3.3 KiB
VB.net

Imports System.CodeDom.Compiler
Imports System.Text
Public Class rCompiler
' Public Shared Sub Compile(ByVal Source As String, ByVal Output As String, Optional ByVal Icon As String = "") 'ByVal Res As String, Optional ByVal Icon As String)
Public Shared Sub Compile(ByVal Source As String, ByVal Output As String, ByVal Res As String, Optional ByVal Icon As String = "")
Dim success As Boolean = True
Dim ProviderOptions As New Dictionary(Of String, String)()
ProviderOptions.Add("CompilerVersion", "v2.0")
Dim CP As New Microsoft.VisualBasic.VBCodeProvider(ProviderOptions)
Dim P As New CodeDom.Compiler.CompilerParameters
Dim s As New StringBuilder()
s.Append(" /target:winexe")
s.Append(" /platform:x86")
s.Append(" /optimize+")
s.Append(" /utf8output")
P.ReferencedAssemblies.Add("System.dll")
P.ReferencedAssemblies.Add("System.Data.dll")
P.ReferencedAssemblies.Add("System.Windows.Forms.dll")
P.GenerateExecutable = True
P.OutputAssembly = Output
'----- ADD VIRUS RESOURCE -----
P.EmbeddedResources.Add(Res)
'----- ADD VIRUS RESOURCE -----
If Icon <> "" Then
s.Append(" /win32icon:" & Icon)
End If
P.CompilerOptions += s.ToString()
P.IncludeDebugInformation = False
P.ReferencedAssemblies.Add("System.Dll")
P.ReferencedAssemblies.Add("System.Windows.Forms.Dll")
Dim Results1 = CP.CompileAssemblyFromSource(P, Source)
For Each uii As CodeDom.Compiler.CompilerError In Results1.Errors
MsgBox(uii.ToString)
success = False
Next
If success Then : MsgBox("Success!", MsgBoxStyle.OkOnly + MsgBoxStyle.Information) : End If
End Sub
'Public Shared Sub GenerateExecutable(ByVal Output As String, ByVal Source As String, ByVal Resource 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.CompilerOptions &= "/target:winexe"
' 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"
' Parameters.EmbeddedResources.Add(Resource)
' Dim Version = New Dictionary(Of String, String)
' Version.Add("CompilerVersion", "v2.0")
' If Icon <> "" Then
' Parameters.CompilerOptions &= " /win32icon:" & Icon
' 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
'End Sub
End Class