Let's suppose, you don't want to make your own c# compiler, and you are satisfied by using the one made by Microsoft - they made it available to anyone not only as command line tool, but also as library. Look here:
Compiling code during runtime[
^].
If you want to make compiler for an other platform, that's an other topic... but don't even try that...