locked
Add-in VS2008 C# - Errors on the fly - detect compiler errors before building in the same manner as “Remove and Sort Usings” RRS feed

  • Question

  • I'm making a refactoring tool that automates a few of the more trivial code styling things dealing with StyleCop.  One of the things I'd like my add-in to be able to do (as an optional feature the developer can turn on/off) is automatically call the "Organize Usings -> Remove and Sort" functionality.  This is a simple macro call.

    However, my problem is that as I go through and recursively call the macro on every .cs non-designer file in the solution this particular macro checks for errors before execution.  If there's a syntax error and my add-in starts calling that functionality, it throws up a dialog for each and every file.

    What I'd like to do, is use the same method that function uses for checking for errors on the fly and then if there's an error that would cause the dialog to pop up, simply pop up a one-time notification and skip the calls on each file.

    I know my add-in could check the error list, however I've found many times that errors that trigger problems in "Remove and Sort" don't always appear in the list.  I've had the list be empty, then I try "Remove and Sort" and it tells me there's build problems.  I then build the solution and sure enough it fails and the errors are populated.  The only solution I'm seeing is to use the same functionality as "Remove and Sort" to check beforehand.

    Does anybody know how I can detect compiler errors before building in the same manner as "Remove and Sort Usings"?
    Tuesday, February 23, 2010 1:00 AM

Answers

  • I used a workaround.

    I checked the ErrorList for errors.

    I also added a timer around the call and if the call takes more than a second I assume it showed the dialog and ask if the user wants to skip the call.
    • Marked as answer by McAden Tuesday, March 2, 2010 6:54 AM
    Tuesday, March 2, 2010 12:20 AM

All replies

  • Another approach is:

    - Tell the user that the solution will be built (Accept/Cancel)
    - If the user accepts, build the solution
    - Check for errors
    - If there are no errors, run the feature on each file of the solution



    MZ-Tools: Productivity add-ins for Visual Studio: http://www.mztools.com. My blog about developing add-ins: http://msmvps.com/blogs/carlosq/
    Tuesday, February 23, 2010 2:21 PM
  • I hadn't planned on building the project though.
    Tuesday, February 23, 2010 5:43 PM
  • Hello,

    Thanks for using MSDN forum.

    The error check is actually done by language service symantic check.

    I don't find any API to trigger the check programmatically. The check will be done if you open the file in the editor. 

    I agree with Carlos that build the project will be easiest way to workaround the issue.

    Thanks.


    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    See what's happening in MSDN forum? Follow us at Twitter.
    Thursday, February 25, 2010 9:12 AM
  • Hello,

    Is this issue resolved? Thanks.

    Hongye Sun [MSFT]
    MSDN Subscriber Support in Forum
    If you have any feedback on our support, please contact msdnmg @ microsoft.com

    Please remember to mark the replies as answers if they help and unmark them if they provide no help.
    Welcome to the All-In-One Code Framework! If you have any feedback, please tell us.
    See what's happening in MSDN forum? Follow us at Twitter.
    Monday, March 1, 2010 4:50 AM
  • I used a workaround.

    I checked the ErrorList for errors.

    I also added a timer around the call and if the call takes more than a second I assume it showed the dialog and ask if the user wants to skip the call.
    • Marked as answer by McAden Tuesday, March 2, 2010 6:54 AM
    Tuesday, March 2, 2010 12:20 AM