views:

508

answers:

1

{rant}First I'd like to say that this IS NOT A DUPLICATE. I've asked this question previously but it got closed as a duplicate when it isn't. This question is SPECIFIC to VS 2010 and the answers to the so-called duplicate work in VS 2008 but not in VS 2010 (at least not for me or anyone I know). So before you go closing something as a duplicate how about you read the question carefully and try the answer for yourself and see if it actually works. Apologies for the rant but there is no obvious way to contact the SO police that closed the issue or get it reopened. {/rant}


At work we have a C# solution with over 80 projects. In VS 2008 we use a macro to stop the compile as soon as a project in the solution fails to build (see this question for several options for VS 2005 & VS 2008: http://stackoverflow.com/questions/134796/how-to-automatically-stop-visual-c-build-at-first-compile-error).

Is it possible to do the same in VS 2010? What we have found is that in VS 2010 the macros don't work (at least I couldn't get them to work) as it appears that the environment events don't fire in VS 2010.

The default behaviour is to continue as far as possible and display a list of errors in the error window. I'm happy for it to stop either as soon as an error is encountered (file-level) or as soon as a project fails to build (project-level).

Answers for VS 2010 only please. If the macros do work then a detailed explanation of how to configure them for VS 2010 would be appreciated.

Thanks.

+12  A: 

(You can now download this as an extension, if you don't want to build it yourself)

This answer only works in VS2010 (seems fair :]). I've put the source up on my github page. Before you can build it, you'll need to install the SDK. Once you've done that, just grab the complete source from github (includes project files) and build that. You can install the output into your normal VS instances by finding the VSIX in your build output and opening it.

The important part is:

public void TextViewCreated(IWpfTextView textView)
{
    var dte = GlobalServiceProvider.GetService(typeof(DTE)) as DTE;
    textView.TextBuffer.Changed += (sender, args) =>
    {
        //Output window is friendly and writes full lines at a time, so we only need to look at the changed text.
        foreach (var change in args.Changes)
        {
            string text = args.After.GetText(change.NewSpan);
            if (BuildError.IsMatch(text))
                dte.ExecuteCommand("Build.Cancel");
        };
    }
}

... where BuildError is a regex defined above that you can tweak. If you have any questions about modifying the code, let me know.

Noah Richards
Works perfectly! Thanks Noah.
Ben Robbins
WTF? Is this really the best VS2010 can do? I'm beyond disappointed!
David Schmitt
Sorry, what was it you wanted it to do instead?
Noah Richards
@David VS2010 does about everything you need it to do, except wipe your <strike>ass</strike>chin. What it doesn't do is usually handled by an extension. [VSCommands also does this.](http://visualstudiogallery.msdn.microsoft.com/en-us/d491911d-97f3-4cf6-87b0-6a2882120acf)
Will
@Will, thanks, I deserved that. To answer your question: Being able to set http://msdn.microsoft.com/en-us/library/microsoft.build.tasks.msbuild.stoponfirstfailure.aspx on the solution?
David Schmitt
Gotcha. I've never actually tried setting properties like that on the build tasks, and I wouldn't expect it to work very well (from the warning on MSDN that it is internal only). Sorry :(
Noah Richards