Tuesday, September 04, 2012 3:34 PM
Is it possible to inject code to existing CLR assemblies using Roslyn? Apologies for asking this high level question because going through the Roslyn CTP Overview document I could not find answer to this question. I can't afford to spend hours and days into this just to find out whether it is possible. If it is possible, I dont mind spending days to learn it and then build code injection framework.
I understand it is possible to inject code during the compilation process and I could create a VS add-in for the purpose but I am really after injecting code to an assembly already generated. Any pointers would help. Thanks.
Tuesday, September 04, 2012 4:27 PM
Roslyn isn't a decompiler - it's a source code compilation framework. In order to do this via Roslyn, you'd need to decompile the assembly into C# or VB, then recompile that with Roslyn while doing your injection.
You might want to look at something like Mono's Cecil, as it's intended to modify assemblies which have already been compiled.
Reed Copsey, Jr. - http://reedcopsey.com
If a post answers your question, please click "Mark As Answer" on that post and "Mark as Helpful".
- Marked As Answer by Girish Jain Tuesday, September 11, 2012 2:25 PM
Tuesday, September 11, 2012 2:28 PM
Thanks a lot Reed, you saved me many hours. I might come back to Roslyn in future, may be for some other purpose. In between, I am currently using Mono.Cecil for code injection, please read my blog post on same:
Thanks a lot!