VS2010 - 如何在第一次编译错误时自动停止编译 [英] VS2010 - How to automatically stop compile on first compile error

查看:21
本文介绍了VS2010 - 如何在第一次编译错误时自动停止编译的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

在工作中,我们有一个包含 80 多个项目的 C# 解决方案.在 VS 2008 中,一旦解决方案中的项目无法构建,我们就会使用宏来停止编译(有关 VS 2005 和 VS 2008 的几个选项,请参阅此问题:在第一次编译错误时自动停止 Visual C++ 2008 构建?).

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: Automatically stop Visual C++ 2008 build at first compile error?).

是否可以在 VS 2010 中做同样的事情?我们发现,在 VS 2010 中,宏不起作用(至少我无法让它们起作用),因为在 VS 2010 中似乎不会触发环境事件.

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).

请只回答 VS 2010.如果宏确实有效,那么我们将不胜感激有关如何为 VS 2010 配置它们的详细说明.

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.

推荐答案

(您现在可以下载这个作为扩展,如果你不想自己构建它)

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

此答案仅适用于 VS2010(似乎很公平:]).我已将源代码放在我的 github 页面.在构建它之前,您需要 安装 SDK.完成后,只需从 github 获取完整源代码(包括项目文件)并构建它.您可以通过在构建输出中找到 VSIX 并将其打开来将输出安装到普通 VS 实例中.

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.

重要的部分是:

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");
        };
    }
}

... 其中 BuildError 是上面定义的正则表达式,您可以对其进行调整.如果您对修改代码有任何疑问,请告诉我.

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

这篇关于VS2010 - 如何在第一次编译错误时自动停止编译的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆