O'Reilly logo

Microsoft® Visual Basic® .NET Programmer's Cookbook by Matthew MacDonald

Stay ahead with the world's most comprehensive technology and business learning platform.

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, tutorials, and more.

Start Free Trial

No credit card required

Compile Source Code Programmatically

Problem

You want to compile code from a string or a source file using a custom .NET program.

Solution

Use the Microsoft.VisualBasic.VBCodeProvider to create an ICodeCompiler object.

Discussion

The .NET Framework allows you to access the Microsoft Visual Basic, Visual C#, Visual J#, and JScript language compilers. To compile code using one of these engines, you call the CreateCompiler method of the appropriate code provider class. (In the case of Visual Basic .NET, this class is Microsoft.VisualBasic.VBCodeProvider.) The CreateCompiler method returns an ICodeCompiler object that allows you to create assemblies in memory or on disk.

Compiling code can be a painstaking task. You need to ensure that you supply all the ...

With Safari, you learn the way you learn best. Get unlimited access to videos, live online training, learning paths, books, interactive tutorials, and more.

Start Free Trial

No credit card required