Suppose we put code on production box, later we need trace a bug in production environment. Of course there is no Visual Studio installed on production box. How can we do? Sometimes it is too complex to build a testing project and upload to production box. What about building a generic editor with code compilation capability, so that we can put testing code in it and compile the source code dynamically without complex command line typing?
Another example is Application Server. It is a good feature to compile testing code inside the server environment for module's stress test.
Inside the editor, we can define our own format for DLL references. For example:
//@ref "DLL file name"
The editor compiles source code in these steps:
- Create an instance of CodeDomProvider CSharpCodeProvider (VBCodeProvider for Visual Basic)
CompilerParametersfor compiler options, such as adding DLL references
- Compile source code using
CompileAssemblyFromSourcemethod of the CodeDomProvider
- Execute generated application if there were no errors