Created
March 15, 2016 10:35
-
-
Save anonymous/2e07b9c36ac0fbadaf72 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Imports Microsoft.CodeAnalysis | |
| Imports Microsoft.CodeAnalysis.VisualBasic | |
| Imports Microsoft.VisualBasic.CompilerServices | |
| Module Module1 | |
| Sub Main() | |
| Dim code = "Module Module1" + Environment.NewLine + | |
| "Sub Main()" + Environment.NewLine + | |
| "System.Console.WriteLine(My.Application.Info.AssemblyName)" + Environment.NewLine + | |
| "End Sub" + Environment.NewLine + | |
| "End Module" | |
| Dim tree = VisualBasicSyntaxTree.ParseText(code) | |
| Dim compilation = VisualBasicCompilation.Create("test"). | |
| AddSyntaxTrees(tree). | |
| AddReferences(MetadataReference.CreateFromFile(GetType(Object).Assembly.Location)). | |
| AddReferences(MetadataReference.CreateFromFile(GetType(StandardModuleAttribute).Assembly.Location)) | |
| Dim emitResult = compilation.Emit("test.exe") | |
| If Not emitResult.Success Then | |
| Console.Write(String.Join(Environment.NewLine, emitResult.Diagnostics)) | |
| End If | |
| Console.ReadLine() | |
| End Sub | |
| End Module |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment