After you compile your code, you can check to see if there were any compilation errors. This method takes the parameters object and the source code, which is a string. The call to CompileAssemblyFromSource is where the assembly gets compiled. The code above uses the CompilerParameters object to tell the compiler that you want to generate an executable file (as opposed to a DLL) and that you want to output the resulting assembly to disk. Here is an example: parameters = new CompilerParameters() ĬompilerResults results = icc.CompileAssemblyFromSource(parameters,SourceString) You'll pass parameters to the compiler by using the CompilerParameters class. Once you have a reference to an ICodeCompiler interface, you can use it to compile your source code. ICodeCompiler icc = codeProvider.CreateCompiler() CSharpCodeProvider codeProvider = new CSharpCodeProvider() The following sample code creates an instance of CSharpCodeProvider and uses it to get a reference to a ICodeCompiler interface. The CSharpCodeProvider class implements this interface and provides access to instances of the C# code generator and code compiler. NET Framework provides the ICodeCompiler compiler execution interface. Any errors that occur during the compilation process are displayed on the form. The application allows you to either just build the executable or build the executable and run it. This article provides sample code that enables you to compile code from a text source. This might be useful if you want to write your own code-compiling utilities. NET Framework exposes classes that allow you to programmatically access the C# language compiler. NET Framework Original KB number: 304655 Summary This article describes how to compile code from a text source by using C# compiler.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |