开发者

How can I get Visual Studio to beep at me if a build succeeds?

Often, I need to recompile and it takes a minute or two, so I tend to switch to a web browser to kill that time. Sometimes I forget to look back and the build succeeded a few minutes before I noticed.

Is it possible to somehow get Visual Studio开发者_开发百科 (just UI version, not command line) to beep at me if the build (for the project or solution) completes successfully without warning?

Also helpful would be a beep when the first breakpoint is hit while debugging, since sometimes I have to wait a minute or two for this to happen as well.

Do I need to write a macro for it, perhaps? Are there hidden settings somewhere?


I'm seeing in my System Sounds a category called "Microsoft Visual Studio Macros" that contains three sounds: Build Canceled, Build Failed, and Build Succeeded. I'm guessing they got there from the sample macros that get installed by default. Might try hitting Alt-F8 in VS and poking around in the macros.

My favorite solution is this one though: VSBuildStatus. If you've got Windows 7, it will show the build progress in the taskbar (like Explorer does with file copying). Turns red on a build failure. Must-have.

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


Here is a macro found at: 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

Good luck!


  1. Open Up a Macro Explorer (Alt + F8).
  2. Create a new Macro Project if you don't have one already.
  3. Open up Microsoft Visual Studio Macros (Alt + F11)
  4. If you don't already have a macro titled EnvironmentEvents create it.
  5. Make sure the macro contains the following code (pay attention to the snippet at the bottom!)

The code:

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

FYI: I've found that Windows 7's Console.Beep() is not a motherboard beep. Also, I quite like "C:\Windows\Media\Windows Shutdown.wav" for the audio clip when on Windows 7.


There is already a build in function in Microsoft windows for this. Go to Control Panel > Manage audio Devices > Sounds tab. Then scroll to the bottom to configure Build Canceled, Failed, or Succeeded.

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


I think the easiest way is to do the following

  • Create a simple command line app that calls the Win32 Beep function
  • Setup a post build event to run on build success
  • Call that App


I used to use the event toaster for visual studio which display events in the system tray, I used it for builds because I too got bored waiting for builds :) Not used it in a while though.

  • For VS2005: Download Microsoft Visual Studio 2005 IDE Enhancements.
  • For VS2008 and VS2010: You need to use Growl instead.


There is an extension called Ding that seems to do what you are looking for:

"This small extension will play notification sounds when following events occur: - Build Complete - Entering debugger mode (breakpoint hit, etc) - Unit tests finished to run Useful when working with big solutions or when build/test run/hitting a breakpoint takes a lot of time ..."

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

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜