12/17/2004

ReBuild and Run .NET Macro

by @ 10:37 am. Filed under .NET, ASP, VB

Here’s a useful little re-build and run macro the 4Guys came up with for the .NET IDE.

If you’ve been developing any ASP.NET applications, you may have run into the same frustration that we have with the Application cache. We’ve discovered that the Application cache is not cleared until you rebuild your application (which when you think about it is kind of what you should expect) so often when you are expecting the cache to be empty, it isn’t, leaving you scratching your head until you once again remember, Oh, that’s right I have to rebuild before I run to make sure the Application cache has been cleared.

So since no button exists to rebuild a solution and run in just one single click and we could not find anyone else out there who had already done this work, we created our own Macro in VB.NET and assigned it to a button on our toolbar.

Just add this code to a Macro Module and then add it to a button on the toolbar in .NET and enjoy the one button click to re-build and run a project!


Imports EnvDTE
Imports System.Diagnostics

Public Module UserCreated
    Public Sub ReBuildAndRun()
        ‘Add an event so that we can detect when the solution has completed the rebuild process
        AddHandler DTE.Events.BuildEvents.OnBuildDone, AddressOf AfterBuild
        ‘Rebuild the entire Solution
        DTE.ExecuteCommand(”Build.RebuildSolution”)
    End Sub

        ‘This sub is called once the solution has completed the rebuild process
    Public Sub AfterBuild(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction)
        ‘The Event Handler must be removed to prevent eternal looping since
        ‘the Debugger.Go call causes another build which would then raise the event again and again and again….
        RemoveHandler DTE.Events.BuildEvents.OnBuildDone, AddressOf MyMacros.UserCreated.AfterBuild
        ‘Run the project
        DTE.Debugger.Go(True)
    End Sub
End Module

14 Responses to “ReBuild and Run .NET Macro”

  1. SuperProgrammer64 Says:


    This is the most awesome code snippet I have EVER found online. You 4guys rock!!! Especially George because I think he’s kind of sexxxy!!!


  2. !=1337 Says:


    I’ve been looking all over the web for something like this. You 4 guys must be geniuses or something (i’m voting for something). Thanks again for the helpful macro.


  3. CodeGirl007 Says:


    Where did you guys steal this code from? You couldn’t have thought of it yourself. I’ve seen some of your other blog posts and they are typically just useless. So come on, give credit to whomever you jacked that code from!!!!


  4. Cecilla Says:


    Sean must have come up with this code because Rick and George would have never had the brain trust between them to come up with something so neatly written and commented. Not that they couldn’t have had the idea, we all just know Sean is the one who really makes their ideas fly!!!


  5. Anonymous Says:


    We really liked the website .. Thank you.


  6. Fejjwy Says:


    I don’t see why you’re going to all that trouble when you can just customize your toolbar and add ‘Edit\Rebuild Solution’. That’s one of the first things I did when I started to learn the Visual Studio environment.


  7. Rick Says:


    I don’t see why you’re going to all that trouble when you can just customize your toolbar and add ‘Edit\Rebuild Solution’. That’s one of the first things I did when I started to learn the Visual Studio environment.

    Because this is one button, whereas your solution would require two buttons…. The macro Rebuilds, and then, on a successful rebuild, runs the solution.


  8. Fejjwy Says:


    Yes, ’tis true, O Great One. I missed that, being read late one night when I was wondering what my friend was up to. We can’t use it at GWI because everything is browser-driven, but it’s a cool little tool to keep for Windows apps.


  9. Rick Says:


    What? You code in a browser? Hmm. That is odd. We do use it quite a bit for our ASP.NET projects as well…..


  10. raj Says:


    been looking for this for a while, Thank You!.


  11. Stefano Says:


    Spettacolo!!! Funziona…
    aggiungo anche altre 2 parti di codice
    1) codice per killare aspnet_wp.exe
    - a volte capita che ricompilando parzialmente la soluzione l’esecuzione del progetto da problemi… risolti killando aspnet prima di rigenerare parzialmente il progetto.
    2) seleziona e compilare parzialmente la soluzione

    Public Module Compila_Attach_AspNET

    Sub AspNET()
    Dim findAspNET As Boolean = False
    For Each oProces As System.Diagnostics.Process In System.Diagnostics.Process.GetProcesses
    For Each oProcessModule As ProcessModule In oProces.Modules
    If oProcessModule.ModuleName = “aspnet_wp.exe” Then
    findAspNET = True
    Exit For
    End If
    Next
    If findAspNET Then
    oProces.Kill()
    Exit For
    End If
    Next
    End Sub

    Public Sub ReBuildAndRun()
    ’sego aspenette
    AspNET()
    ‘aggiungo l’evento
    AddHandler DTE.Events.BuildEvents.OnBuildDone, AddressOf AfterBuild
    ‘rigenero le soluzioni che mi interessano webvita e examplevita
    DTE.Windows.Item(Constants.vsWindowKindSolutionExplorer).Activate()
    DTE.ActiveWindow.Object.GetItem(”MyProject\Mymodule1″).Select(vsUISelectionType.vsUISelectionTypeSelect)
    DTE.ActiveWindow.Object.GetItem(”MyProject\Mymodule2″).Select(vsUISelectionType.vsUISelectionTypeToggle)
    DTE.ActiveWindow.Object.GetItem(”MyProject\Mymodule2″).Select(vsUISelectionType.vsUISelectionTypeSetCaret)
    DTE.Windows.Item(Constants.vsWindowKindOutput).Activate()
    DTE.ExecuteCommand(”Build.RebuildSelection”)
    End Sub

    Public Sub AfterBuild(ByVal Scope As EnvDTE.vsBuildScope, ByVal Action As EnvDTE.vsBuildAction)
    RemoveHandler DTE.Events.BuildEvents.OnBuildDone, AddressOf MyMacros.Compila_Attach_AspNET.AfterBuild
    ‘Run the project
    DTE.Debugger.Go(True)
    End Sub

    End Module


  12. Stefano Says:


    …mmmm… si può fare una cosa ancora più ganza…
    per lanciare il debug con firefox o aggiungi un comando tipo
    Shell(”C:\Programmi\Mozilla Firefox\firefox.exe http://stb/webvita“, AppWinStyle.NormalFocus, False)

    oppure configuri visual studio 2003 per far partire firefox una volta avviato il debug…
    per fare questo leggi qui:
    http://codebetter.com/blogs/peter.van.ooijen/archive/2004/10/25/29621.aspx

    bona gente!!! Stefano.


  13. Serjik Says:


    Nice work! I’ll have to do a cross post on this one ;)


Leave a Reply

 
 

This is a captcha-picture. It is used to prevent mass-access by robots. (see: www.captcha.net)

You must read and type the 3 chars within 0..9 and A..F, and submit the form.

  

Oh no, I cannot read this. Please, generate a

[powered by WordPress.]

-->

Search blog:

categories:

archives:

general links:

internal links:

other:

19 queries. 0.185 seconds