1

Does any body know how can I create a C# project at runtime, add classes to it and compile it to generate a dll.

Ghyath Serhal
  • 7,466
  • 6
  • 44
  • 60

2 Answers2

2

If you just want to compile code and generate a dll, see cdhowie's answer.

If you want to have a complete project file at the end, you can create a csproj file through XML or Text output, which points to the code (and other) files you want to include, then execute "msbuild myproject.csproj".

Open a .csproj file for a project you have with notepad, the structure isn't complicated.

TToni
  • 9,145
  • 1
  • 28
  • 42
1

If you are interested in creating dynamic classes for your own use the have a look at System.Reflection.Emit namespace. You can create assembly full of types on the fly.

alpha-mouse
  • 4,953
  • 24
  • 36