Start a new topic

Is it possible to compile cs code to js at runtime?

I want to transform (compile) c# poco object to js representation at runtime (via JS runtime, and not via msbuild).


Is it possible with DuoCode?


It's similar to your 'http://try.duoco.de/compile', but achieve that with DuoCode's mscorelib.js code.

Or is the only way to do that is to send it to server with msbuild and duocode on it?

1 Comment

I agree, this is the dream of all real compiler, to be able to compile itself.


Unfortunately since DuoCode is 100% Roslyn depended and only Roslyn, it's more question of compiling Roslyn to JS using DuoCode.

As you know our mscorlib is not complete yet and such a task is very difficult yet to compile whole Roslyn to JS, but theoretical doable.


So as of now only the AJAX (client server) way to compile code on server side is possible and very easy to implement.


When DuoCode compiler is loaded, compilation of C# to JS is extremely fast even faster than original csc.exe.


For advanced and very fast use see using ILSpy or Reflector this method:


public static int DuoCode.Compiler.Dcc.Run(

  RunMode runMode, 

  string baseDirectory, // can be null, i.e. current directory

  TextWriter consoleOutput,

  string[] args,

  IDictionaryKV outputs = null)


This method is used by TryDuoCode directly.



Hopes this help.

Login or Signup to post a comment