Imports System.CodeDom.Compiler Imports System.IO Imports System.Text Public Class Form1 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click 'ソースコード生成 Dim code As New StringBuilder() code.AppendLine("Imports System.Windows.Forms") code.AppendLine("Module StartUp") code.AppendLine("Sub Main()") code.AppendLine("Application.Run(New Form())") code.AppendLine("End Sub") code.AppendLine("End Module") 'コンパイルに必要なオブジェクト生成 Dim compiler As New VBCodeProvider() Dim param As New CompilerParameters() 'コンパイルに必要なパラメータ設定 param.OutputAssembly = Path.Combine(Environment.GetFolderPath(Environment.SpecialFolder.Desktop), "test.exe") param.ReferencedAssemblies.Add("System.Windows.Forms.dll") param.CompilerOptions &= "/target:winexe" param.GenerateExecutable = True 'コンパイル、出力取得 Dim res As CompilerResults = compiler.CompileAssemblyFromSource(param, code.ToString()) For Each row As String In res.Output Me.Label1.Text &= row & Environment.NewLine Next End Sub End Class