0

Given a single c# source file, I'd like to output IL (not assembled) of that single file such that later I can feed each '.il' file to ilasm to produce assemblies, is this possible?

IanNorton
  • 7,145
  • 2
  • 25
  • 28
  • Maybe if you give a bit more background people will be able to give you better answers. What are you hoping to achieve exactly and why? – Marnix van Valen Jun 04 '11 at 14:22

2 Answers2

0

This isn't directly answering your question, but why not compile, then use ildasm and retrieve the relevant sections?

dpington
  • 1,844
  • 3
  • 17
  • 29
  • Because I want an intermediate stage, I'm looking into some ideas for a distributed compiler for c# – IanNorton Jun 04 '11 at 14:02
  • why would you need distributed compilation for c# – David Heffernan Jun 04 '11 at 14:07
  • @IanNorton: If your C# code is taking more than 2 to 3 minutes to compile, you need to buy a new computer. Anything from the last 10 years compiles code fast enough that distributed compilation should not be necessary. At any rate, you need a compiler to convert C# code to IL. The one that comes with the .NET SDK is pretty good... – Cody Gray - on strike Jun 04 '11 at 14:09
  • 1
    Generating IL as an intermediate step would be slower than just compiling in the first place. IL-as-text is not a particularly compact representation, so you'd spend lots of extra time writing big .il files (much bigger than the original .cs files), reading them back in, parsing them, and re-building the same symbol tables that the C# compiler built once already. You'd be better off with a custom binary intermediate format, like Delphi's .dcu files. – Joe White Jun 04 '11 at 14:20
0

So, you probably can't do this well and in most cases you won't want to. However it is possible to cut compilation and assembly linking into two stages by building all sources to modules and then linking modules and resources into the final assemblies.

Short answer, getting textual IL out of a C# compiler is not feasible on .Net and in any case, there isn't much benefit from doing so.

IanNorton
  • 7,145
  • 2
  • 25
  • 28