Sub Codedom(ByVal Path As String, ByVal Code As String, ByVal MainClass As String)
Dim providerOptions = New Collections.Generic.Dictionary(Of String, String) 'Thanks to Cobac for adding this.
providerOptions.Add("CompilerVersion", "v4.6.1")
Dim CodeProvider As New Microsoft.CSharp.CSharpCodeProvider(providerOptions)
Dim Parameters As New CompilerParameters
With Parameters
.GenerateExecutable = True
.OutputAssembly = Path
.CompilerOptions += "/platform:X86 /unsafe /target:winexe"
.MainClass = MainClass
.IncludeDebugInformation = False
.ReferencedAssemblies.Add("System.Windows.Forms.dll")
.ReferencedAssemblies.Add("System.CodeDom.CodeObject")
.ReferencedAssemblies.Add("System.CodeDom.Compiler.CodeDomProvider")
.ReferencedAssemblies.Add("Microsoft.CSharp.CSharpCodeProvider")
.ReferencedAssemblies.Add("Microsoft.VisualBasic.VBCodeProvider")
.ReferencedAssemblies.Add("Microsoft.VisualBasic.dll")
.ReferencedAssemblies.Add("System.Linq.dll")
.ReferencedAssemblies.Add("System.Core.dll")
.ReferencedAssemblies.Add("System.Data.dll")
.ReferencedAssemblies.Add("System.Deployment.dll")
.ReferencedAssemblies.Add("System.Drawing.dll")
.ReferencedAssemblies.Add("System.Xml.dll")
.ReferencedAssemblies.Add("System.Xml.Linq.dll")
.ReferencedAssemblies.Add("System.dll")
.ReferencedAssemblies.Add(Process.GetCurrentProcess().MainModule.FileName)
.ReferencedAssemblies.Add(Application.ExecutablePath)
End With
Dim Results = CodeProvider.CompileAssemblyFromSource(Parameters, Code)
If Results.Errors.Count > 0 Then
For Each E In Results.Errors
MsgBox(E.ErrorText)
Next
End If
End Sub
它适用于 4.0,但不适用于 4.6.1 任何想法?为什么?
我尝试添加更多引用的程序集我没有太多想法
我一直在搜索这个,我没有找到任何信息,所以这让我很烦。