A fully client side c# code editor with blazor and roslyn
Blazor Code Editor is a minimal, client-side web application built with Blazor WebAssembly. It demonstrates a novel approach to dynamically compiling and executing C# code entirely in the browser. This project is a lightweight public version of Apollo, showcasing its core capabilities in a simplified form.
Features include:
- Client-side compilation and execution of C# code.
- Lightweight, browser-based IDE experience.
- Monaco-based code editor with syntax highlighting and support for C#.
- Support for multiple files within a solution.
- Educational value as an example of dynamic code execution in WebAssembly.
- Visual Studio 2022 17.9 or later.
- .NET 9 SDK installed.
- Basic knowledge of C# and Blazor.
Clone the repository and build the project using:
# Clone the repository
git clone https://github.com/thatplatypus/BlazorCodeEditor.git
# Navigate to the project directory
cd BlazorCodeEditor
# Build the project
dotnet build
Blazor Code Editor relies on the following approach to handling WebAssembly with .NET:
- Webcil Integration: This project makes use of the Webcil format, a WebAssembly-compatible representation of .NET assemblies, enabling C# code to compile and execute dynamically within the browser.
- Roslyn in WebAssembly: The project invokes the Roslyn compiler at runtime, resolving metadata references and transpiling assemblies back into a format suitable for execution in the browser.
No server setup is required as the entire application runs within the browser's sandbox.
To run the application locally:
- Build the project as shown in the Installation section.
- Use the following command to launch the application:
dotnet run --project BlazorCodeEditor
- Open the provided URL in your browser (e.g.,
http://localhost:5000
).
- The application leverages Mono's Webcil format to enable native .NET assembly execution in WebAssembly.
- Metadata references are dynamically resolved at runtime, eliminating the need for pre-bundled DLLs.
- The project adopts a reflection-heavy architecture due to browser runtime constraints, supporting only browser-compatible APIs.
Blazor Code Editor is a perfect starting point for:
- Exploring WebAssembly and Blazor capabilities.
- Understanding dynamic code compilation and execution in a browser environment.
- Building educational tools or demos for teaching C#.
Pull requests are welcome. For major changes, please open an issue to discuss what you would like to change.
This project is licensed under the MIT License.