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
| Private Sub butExecuter_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butExecuter.Click
ExecuteCommand1()
End Sub
Private Sub ExecuteCommand1()
Dim vbCodeProv As VBCodeProvider = New VBCodeProvider
Dim cParam As CodeDom.Compiler.CompilerParameters = New CodeDom.Compiler.CompilerParameters
' Ajout des références
cParam.ReferencedAssemblies.Add("System.dll")
' Options du compilateur
cParam.CompilerOptions = "/t:library" 'L'assembly est une bibliothèque de classe,
cParam.GenerateInMemory = True 'générée uniquement en mémoire.
' Résultat de la compilation
Dim cResult As CodeDom.Compiler.CompilerResults = vbCodeProv.CompileAssemblyFromSource(cParam, txbScript.Text)
If cResult.Errors.Count > 0 Then
Dim Errors As String = "Erreur(s) : "
For Each ce As CodeDom.Compiler.CompilerError In cResult.Errors
Errors &= vbCrLf & ce.ErrorText
Next ce
MsgBox(Errors)
End If
' Récupération de l'assembly généré
Dim myAssembly As System.Reflection.Assembly = cResult.CompiledAssembly
End Sub |
Partager