Hooking into the compiler (csc.exe or vbc.exe) itself
-
Thursday, January 05, 2012 4:21 PM
One of the things I've noticed as I've been playing with Roslyn is that there doesn't seem to be a hook into the actual compiler itself. Here's what I mean...
I've written a couple of Code Issues and they work as expected - i.e. I launch the debugger, I write some code that trips the Code Issue, and I see an error in the Error List. But if I actually compile the code, the compilation says it was successful.
I realize that the Code Issue integration is done with the editor as the developer is changing code, but I'm curious if the compilation process itself will change such that we can hook into it to provide customization at that point as well. That may be coming in a future CTP/release of Roslyn, but I don't want to assume it will, so ... is this something that's coming? Or is it already there and I'm missing it?
Regards,
Jason
All Replies
-
Thursday, January 05, 2012 9:57 PMOwner
Hi Jason - I think the only way to do what you are asking currently would be through a Pre-build task (Project Properties -> Build Events -> Pre-build event). Take a look at pilchieMS's answer on this post for this. You could write a Pre-build task that uses the Roslyn APIs (Workspaces, Compilations, Syntax and Semantics) to analyze and report errors in your projects. Using the same APIs you could also write a Pre-build task that modifies / rewrites the source files in your project according to custom rules as pilchieMS pointed out in the above post...
I am not sure whether there is a way for error messages from your Pre-build task to show up in Visual Studio's 'Error List' (like it would in the case of Code Issues) although they should show up in the 'Output' window. In other words, for tools that analyze and report errors in source files, user experience would likely be nicer with Code Issues than with Pre-build tasks :)
Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team- Edited by Shyam NamboodiripadMicrosoft Employee, Owner Thursday, January 05, 2012 9:58 PM
- Proposed As Answer by billchi_msOwner Monday, January 16, 2012 10:24 PM
-
Friday, January 06, 2012 12:26 AMOwner
Also, regarding "Hooking into the compiler (csc.exe or vbc.exe) itself" / "if the compilation process itself will change such that we can hook into it to provide customization at that point as well", there are no plans around implementing something like this at the moment in Roslyn.
That said, future versions of csc.exe and vbc.exe will in all probablility be thin wrappers on top of the Roslyn APIs. So you could always implement your own version of csc.exe / vbc.exe on top of the same APIs i.e. version of csc.exe / vbc.exe that will perform the extra processing / analysis that you want (as hinted by pilchieMS on this post). You could then modify your build system to use the modified versions of csc.exe / vbc.exe...
Shyam Namboodiripad | Software Development Engineer in Test | Roslyn Compilers Team- Proposed As Answer by billchi_msOwner Monday, January 16, 2012 10:24 PM

