Monday, February 16, 2009

IronPython and CodeDOM: Dynamically Compiling C# Files

Harry Pierson (DevHawk) has an interesting article on dynamically compiling C# from IronPython using CodeDom. His motivation for this is to allow him to use extension methods without tying himself into a dependency on a specific version of the DLR.
Of course, I could have simply re-compiled the assembly against the new bits, but that would mean every time I moved to a new version of IronPython, I’d have to recompile. Worse, it would limit my ability to run multiple versions of IronPython on my machine at once. I currently have three – count ‘em, *three* – copies of IronPython installed: 2.0 RTM, nightly build version 46242, and an internal version without the mangled namespaces of our public CodePlex releases. Having to manage multiple copies of my extension assembly would get annoying very quickly.

Instead of adding a reference to the compiled assembly, what if I could add a reference to a C# file directly? Kinda like how adding references to Python files works, but for statically compiled C#. That would let me write code like the following, which falls back to adding a reference to the C# file directly if adding a reference to the compiled assembly fails.
If you're interested in this technique, then you may be interested in my article on a similar subject...

No comments:

Post a Comment

Note: only a member of this blog may post a comment.