locked
IL Rewriter - IntelliSense and Debugging RRS feed

  • Question

  • Hi everyone,

    I'm considering developing an executable that rewrites IL at build time probably using CCI, similar to the Code Contracts rewriter, though mine has nothing to do with contracts.  It has to do with something that is commonly solved by T4, though I need a solution that is language agnostic and requires little to no changes in the source in order to take advantage of its features, which is why I'm avoiding T4 in this scenario.  I guess you could say it's a very narrowly-focused usage of AOP, though I don't want to use any existing AOP frameworks or depend on any third-party software (for good reasons).

    1. My first concern is getting the post-processed IL to be shown in IntelliSense, within the same project being rewritten and all dependent projects.

    For example, let's assume the rewriter injects a field into an existing class.  In the code editor (e.g., C#), I should be able to place the text cursor in any method of the class and type this. to get a completion list that includes the injected field.

    I'm planning to extend the VS build system by introducing my own .targets file in Microsoft.Common.targets.  I'm doubtful whether that's enough for IntelliSense to reflect the rewritten assembly, because I assume that VS generates IntelliSense in the background by running its own internal build, which won't include my rewriter.

    2. My other concern is debug symbols.  I'm going to have to rewrite the .pdb file as well, which I believe CCI can do.  But I'm wondering how Visual Studio's debugging experience will be affected, if at all.

    Questions:

    1. Will introducing my own .targets file into the VS build process automatically give me up-to-date IntelliSense?
      If not, then can I fix it with a custom VS editor extension?
      If so, then where do I start gathering information on how to write a custom VS editor extension that extends IntelliSense?
      Must I develop distinct VS editor extensions for each language that I want to support?  (Defeats most of the purpose of IL rewriting though.  In that case, I may actually resort to T4 and only target C#.)
    2. Will pressing F5 to build, run and attach to the current process cause Visual Studio to automatically use the rewritten .pdb file in the project's output directory?
      If not, then can I fix it with a custom VS editor extension?
      If so, then where should I start researching?
    3. Are there any examples of how to do something like this on MSDN?

    Thanks,
    Dave


    http://davesexton.com/blog


    • Edited by Dave Sexton Thursday, September 26, 2013 2:42 PM Formatting
    Thursday, September 26, 2013 2:39 PM

All replies

  • Hi Dave,

    Frankly speaking,I am really astonished at such a distinctive idea!

    Now,I am trying to involve some experts with rich experience to solve this issue.And they would put forward some suggestions later.

    Thanks for your patience.

    Best Regards,

    Jane.


    <THE CONTENT IS PROVIDED "AS IS" WITHOUT WARRANTY OF ANY KIND, WHETHER EXPRESS OR IMPLIED>
    Thanks
    MSDN Community Support

    Please remember to "Mark as Answer" the responses that resolved your issue. It is a common way to recognize those who have helped you, and makes it easier for other visitors to find the resolution later.

    Friday, September 27, 2013 10:26 AM
  • Hi Jane,

    Great, thanks for the update.

    - Dave


    http://davesexton.com/blog

    Friday, September 27, 2013 10:38 AM
  • Hi,

    I was just thinking about this some more and I realized there's a problem.  The C# compiler just gets a string of text, so if for example IntelliSense allows me to reference a field that hasn't been injected by my rewriter yet, the compiler's going to fail because the field isn't defined until the rewriter receives the compiler's output.

    I see two possibilities:

    1. The C# compiler must be involved in the rewrite, though I still want a language-agnostic solution; e.g., Roslyn.
      -OR-
    2. Forget about IntelliSense on this. and just worry about IntelliSense in dependent projects.

    So my first question still stands, though slightly modified:

    Will introducing my own .targets file into the VS build process automatically give me up-to-date IntelliSense in dependent projects?

    Thanks,
    Dave


    http://davesexton.com/blog

    • Edited by Dave Sexton Friday, September 27, 2013 11:43 AM Formatting
    Friday, September 27, 2013 11:39 AM