【问题标题】:How can I get Visual Studio to beep at me if a build succeeds?如果构建成功,如何让 Visual Studio 向我发出哔哔声?
【发布时间】:2010-09-02 16:27:19
【问题描述】:

通常,我需要重新编译,这需要一两分钟,所以我倾向于切换到网络浏览器来打发时间。有时我忘记回头看,在我注意到之前几分钟构建成功。

如果构建(用于项目或解决方案)在没有警告的情况下成功完成,是否有可能以某种方式让 Visual Studio(只是 UI 版本,而不是命令行)向我发出哔哔声?

调试时遇到第一个断点时发出哔哔声也很有帮助,因为有时我也必须等待一两分钟才能发生这种情况。

也许我需要为它写一个宏吗?是否有隐藏设置?

【问题讨论】:

标签: visual-studio


【解决方案1】:

我在我的系统声音中看到一个名为“Microsoft Visual Studio 宏”的类别,其中包含三种声音:构建取消、构建失败和构建成功。我猜他们是从默认安装的示例宏中到达那里的。可能会尝试在 VS 中按 Alt-F8 并在宏中四处寻找。

我最喜欢的解决方案是这个:VSBuildStatus。如果您有 Windows 7,它将在任务栏中显示构建进度(就像资源管理器对文件复制所做的那样)。构建失败时变为红色。必备。

http://visualstudiogallery.msdn.microsoft.com/en-us/2A2293B4-1808-44AA-B030-661F6803D8A1

【讨论】:

  • 哇,这很整洁(系统声音,没想到看那里)。不幸的是,我使用的是 Win2k8 VM,并且没有安装声音设备(用于播放 .wav 文件),并且任务栏在没有安装 Aero 的情况下看起来不那么漂亮:/
  • 在 Windows 10 上:CTRL+ESC 然后输入“机会系统声音”。在声音选项卡上,找到“Microsoft Visual Studio”并为每个子动作选择您喜欢的声音
  • 您的网址后面没有“VSBuildStatus”(还有吗?)。
【解决方案2】:

这是一个宏,位于:http://elegantdevelopment.blogspot.com/2009/09/visual-studio-2008-macro-fun.html

Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildDone
   If (Not failed) Then
      ' System.Windows.Forms.MessageBox.Show("Build is complete!")
      Beep()
      Threading.Thread.Sleep(250)
      Beep()
   End If
End Sub

祝你好运!

【讨论】:

    【解决方案3】:
    1. 打开宏资源管理器 (Alt + F8)。
    2. 如果您还没有宏项目,请创建一个新的宏项目。
    3. 打开 Microsoft Visual Studio 宏 (Alt + F11)
    4. 如果您还没有标题为 EnvironmentEvents 的宏,请创建它。
    5. 确保宏包含以下代码(注意底部的sn-p!)

    代码:

    Option Strict Off
    Option Explicit Off
    Imports System
    Imports EnvDTE
    Imports EnvDTE80
    Imports EnvDTE90
    Imports EnvDTE90a
    Imports EnvDTE100
    Imports System.Diagnostics
    
    Public Module EnvironmentEvents
    
        #Region "Automatically generated code, do not modify"
    
        'Automatically generated code, do not modify
        'Event Sources Begin
        <System.ContextStaticAttribute()> Public WithEvents DTEEvents As EnvDTE.DTEEvents
        <System.ContextStaticAttribute()> Public WithEvents DocumentEvents As EnvDTE.DocumentEvents
        <System.ContextStaticAttribute()> Public WithEvents WindowEvents As EnvDTE.WindowEvents
        <System.ContextStaticAttribute()> Public WithEvents TaskListEvents As EnvDTE.TaskListEvents
        <System.ContextStaticAttribute()> Public WithEvents FindEvents As EnvDTE.FindEvents
        <System.ContextStaticAttribute()> Public WithEvents OutputWindowEvents As EnvDTE.OutputWindowEvents
        <System.ContextStaticAttribute()> Public WithEvents SelectionEvents As EnvDTE.SelectionEvents
        <System.ContextStaticAttribute()> Public WithEvents BuildEvents As EnvDTE.BuildEvents
        <System.ContextStaticAttribute()> Public WithEvents SolutionEvents As EnvDTE.SolutionEvents
        <System.ContextStaticAttribute()> Public WithEvents SolutionItemsEvents As EnvDTE.ProjectItemsEvents
        <System.ContextStaticAttribute()> Public WithEvents MiscFilesEvents As EnvDTE.ProjectItemsEvents
        <System.ContextStaticAttribute()> Public WithEvents DebuggerEvents As EnvDTE.DebuggerEvents
        <System.ContextStaticAttribute()> Public WithEvents ProjectsEvents As EnvDTE.ProjectsEvents
        <System.ContextStaticAttribute()> Public WithEvents TextDocumentKeyPressEvents As EnvDTE80.TextDocumentKeyPressEvents
        <System.ContextStaticAttribute()> Public WithEvents CodeModelEvents As EnvDTE80.CodeModelEvents
        <System.ContextStaticAttribute()> Public WithEvents DebuggerProcessEvents As EnvDTE80.DebuggerProcessEvents
        <System.ContextStaticAttribute()> Public WithEvents DebuggerExpressionEvaluationEvents As EnvDTE80.DebuggerExpressionEvaluationEvents
        'Event Sources End
        'End of automatically generated code
    
        #End Region
    
    
        Private Sub BuildEvents_OnBuildDone(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction) Handles BuildEvents.OnBuildDone
            'Beep to notify that we finished building
            Console.Beep()
            Threading.Thread.Sleep(250)
            'Beep again just for fun
            Console.Beep()
            ' Alternatively, or in Addition to the motherboard beeps, you can 
            ' play a sound from your hard drive via your audio card like so:
            My.Computer.Audio.Play("C:\WINDOWS\Media\Windows XP Startup.wav", _
                AudioPlayMode.Background)
        End Sub
    
    
    End Module
    

    仅供参考:我发现 Windows 7 的 Console.Beep() 不是主板哔声。另外,在 Windows 7 上,我非常喜欢音频剪辑的“C:\Windows\Media\Windows Shutdown.wav”。

    【讨论】:

      【解决方案4】:

      Microsoft windows 中已经为此内置功能。转到控制面板 > 管理音频设备 > 声音选项卡。然后滚动到底部以配置 Build Canceled、Failed 或 Succeeded。

      Visual Studio IDE: I want it to make a sound after it compiles so I can get back to work

      【讨论】:

        【解决方案5】:

        我认为最简单的方法是执行以下操作

        • 创建一个调用Win32 Beep 函数的简单命令行应用程序
        • 设置构建后事件以在构建成功时运行
        • 调用那个应用程序

        【讨论】:

        • +1 甚至只是一个批处理文件而不是应用程序:forums.whirlpool.net.au/archive/564510
        • 我真的不想修改每个项目的构建后属性来实现这一点 - 有时我正在构建不同的项目,这些项目对其他项目有先决条件 - 这可能会触发各种如果我必须让每个都包含一个调用 win32 蜂鸣器应用程序的构建后事件,则过早的蜂鸣声。
        【解决方案6】:

        我曾经在 Visual Studio 中使用事件烤面包机,它在系统托盘中显示事件,我将它用于构建,因为我也厌倦了等待构建:) 虽然有一段时间没有使用它。

        【讨论】:

        • 我用它来满足我的需要,因为我的机器是一个带有 Win2k8 服务器的虚拟机,不幸的是没有可用的声音设备(系统哔声是唯一让它回到我的物理盒子的东西)。跨度>
        【解决方案7】:

        有一个名为 Ding 的扩展程序似乎可以满足您的需求:

        “当发生以下事件时,这个小扩展将播放通知声音: - 构建完成 - 进入调试器模式(断点命中等) - 单元测试完成以运行在使用大型解决方案或构建/测试运行/命中时很有用断点需要很多时间……”

        https://visualstudiogallery.msdn.microsoft.com/941d0ed0-1218-452e-8585-d3ac693cda17

        【讨论】:

        • 感谢您提供新的答案和潜在的解决方案。在我问这个问题的时候,你提到的 Ding 扩展并不存在(2010),我使用的是 Visual Studio 2005 和 2008(虽然我没有在问题中指定哪个 VS 版本)。
        猜你喜欢
        • 2018-08-30
        • 1970-01-01
        • 2010-10-05
        • 1970-01-01
        • 1970-01-01
        • 2014-10-26
        • 1970-01-01
        • 1970-01-01
        • 2020-09-03
        相关资源
        最近更新 更多