VS2010 - How to automatically stop compilation on the first compilation error

{rant} First, I would like to say that it is NOT DUPLICATE . I asked this question before, but it closed as a duplicate when it is not. This question is SPECIFIC for VS 2010 and answers to the so-called duplicate work in VS 2008, but not on VS 2010 (at least not for me or for anyone I know). Therefore, before you close something as a duplicate, how about you carefully read the question and try to answer yourself and see if it really works. Apologies for the pomp, but there is no obvious way to contact the SO police, who closed the problem or resumed it. {/} Loud words




At work, we have a C # solution with over 80 projects. In VS 2008, we use a macro to stop compilation as soon as a project in the solution is created (see this question for several options for VS 2005 and VS 2008: Automatically stop Visual C ++ 2008 to build a compilation error first? ).

Is it possible to do the same in VS 2010? We found that macros do not work in VS 2010 (at least I couldn’t get them to work), because it seems that environmental events do not fire in VS 2010.

The default behavior is to continue as far as possible and display a list of errors in the error window. I am glad that it will stop as soon as an error occurs (file level), or as soon as the project is not created (project level).

Responses to VS 2010 only please. If macros really work, then a detailed explanation of how to configure them for VS 2010 will be appreciated.

Thank.

+41
c # visual-studio visual-studio-2010
Jun 15 '10 at 1:12
source share
2 answers

(Now you can download it as an extension if you do not want to create it yourself)

This answer only works in VS2010 (seems fair:]). I put the source on my github page . Before you can build it, you need to install the SDK . Once you have done this, just take the full source from github (including the project files) and create it. You can set the output to your regular VS instances by finding VSIX in your build release and opening it.

Main part:

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 the regular expression defined above that you can customize. If you have questions about changing the code, let me know.

+28
Jun 15 '10 at 2:25
source share

Edit: Now you will see that they will beat me on this. There is an add-on available for VS2010 that can do this, and more. VSCommands 2010, via http://vscommands.com/features/

+6
Jan 27 '11 at
source share



All Articles