-
Notifications
You must be signed in to change notification settings - Fork 10.3k
How to debug a compiler preprocessor? #295
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I tried the same thing too, I got the debugger to work by the following public class MVCRouteCompilation : MVCRouteCompilerModule {
public MVCRouteCompilation(IServiceProvider provider)
: base(provider)
{
}
}
public class MVCRouteCompilerModule : ICompileModule
{
private readonly IServiceProvider _appProvider;
public MVCRouteCompilerModule(IServiceProvider provider)
{
Debugger.Launch();
_appProvider = provider;
}
public void BeforeCompile(IBeforeCompileContext context)
{
var applicationEnvironment = _appProvider.GetRequiredService<IApplicationEnvironment>();
var projectResolver = _appProvider.GetRequiredService<IProjectResolver>();
// 1. How to find all public types inheriting from Controller
// change class to partial and add {ControllerName}.Generated.cs nested class
// if no default constructor, add one to generated class
// CodeAnalysis should run for public classes and methods to trigger above
// 2. Get all public methods returning types inheriting from actionresult
}
public void AfterCompile(IAfterCompileContext context)
{
}
} [Edit] Should add that this can leave your project permanently building but you just have to kill msbuild process. Also I ended up grabbed files like the ICompileModule out of the asp.net vnext repo and copying directly into my project, Had no luck setting up a vsix project from the Roslyn Templates though as I couldn't reference the library containing the precompilation class as it in turn had references to system.web vnext (in order find the controller types). Also struggling with finding any decent examples of rosyln codegen to mark controller classes as partial and generate action method stubs ala t4mvc. Plenty of examples of diagnostics and refactoring which could look for action link strings in razor views and suggest refactoring to the stubs but to me that seems like 'nice to have' rather than core functionality. |
Preprocessors aren't first class in tooling yet so this will be a bit painful for now as it runs in the tooling process, not in the runtime process (when running in visual studio). |
so I'm learning.. :) On point 2 of Kevin's post, is it possible to invalidate whatever caching is going on for the preprocessor between running builds? Getting RSI killing the klr.exe process! |
Make a change to project.json to recompile the preprocessor itself. |
Thanks both. @davidfowl - can you advise what change to put in the @wwwlicious - I am trying to build a replacement for T4MVC using Roslyn. It looks like we are trying to solve similar problems. When I have some working code I'll push it here |
@kevinkuszyk i"ve commited some code to a repo fork and would be interested in your thoughts on direction. it doesnt do much beyond creating controller partial classes but as ive no exp with roslyn im a bit like a gorilla with a gun at the moment, but you have to start somewhere right? |
@wwwlicious - it looks like you are taking a similar approach to me. I'm by no means an expert on Roslyn though so I could't comment on whether this is the correct approach. I have lots of red underlines and namespace collisions at the moment which I will try to fix this afternoon, so I can push an update. |
A possible suggestion for compile modules would be to implement them as abstract class in a reference class library, and add a subclass of it in your |
Thanks @Antaris, but the problem is that I wanted to hit a breakpoint in my compile module. The issue is because the compile module is run in the framework, Visual Studio doesn't hit the breakpoint. |
@kevinkuszyk You can add a Debugger.Launch() in your compile module and this will be triggered at compile time. |
As suggested by @davidfowl in issue #272:
I now have a preprocessor running in a proof of concept app, and have some questions:
The text was updated successfully, but these errors were encountered: