Writing an Online Compiler with ASP. NET 2.0
Have you ever found yourself at your cousin's farm needing to recompile your .NET website over their Linux based 56k modem? Perhaps you don't have Visual Studio.NET? Or maybe, you simply want an easy way to give .NET a try.
Well, your problems are solved. The download accompanied by this article includes an ASP.NET page that will allow you to compile .net code in either C# or VB.NET. The resulting binary file will reside in the web application's root directory where you can download it to your local computer.
The online compiler is written in C# and ASP.NET.
Using The Online Compiler
The .NET Framework is done in such a way that the internal functions of the compilers are exposed programmatically via CodeDom classes. These classes have several uses, including the ability to build up code structure by structure, "if" statement by "if" statement, variable by variable; and also the ability to compile straight from a complete text of a code file.
We will be focusing on the compilation from text. Our application will take the user's input from a textbox, pass it to the compiler, and display any errors should there be any. Below is a screenshot of the interface.

Put some valid C# or VB.NET code into the large textbox, make sure the correct language is chosen in the Compile With dropdown, and click compile. It will report the status of the compilation. Using the following code: using System;
class CMXClass
{
public bool DoesItRock()
{
return true;
}
}
The following results can be seen:

As you can see, the resulting assembly is delivered to the root directory of the web application. Unfortunately, due to web server security restrictions, you will have to use FTP to download the file. If, however, your code does not compile correctly, it will promptly report any and all errors to you. The code below is trying to use a bad construct which will not compile: using System;
class CMXClass
{
public bool DoesItRock()
{
s/0;
return true;
}
}
If you try to compile that, you will see the below screen:

Conclusion
The included application is a quick and easy way to get started with compiling .NET code if you don't already have a fully featured editor/compiler.
积极主动、认真细致、勤俭节约、务实创新、执之以恒。 所有坚韧不拔的努力迟早会取得报酬的。 耐心和持久永远胜过激烈和狂热。
|