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
[powered by WordPress.]
19 queries. 0.185 seconds
December 20th, 2004 at 2:39 pm
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!!!
December 20th, 2004 at 5:51 pm
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.
December 20th, 2004 at 5:52 pm
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!!!!
December 20th, 2004 at 7:41 pm
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!!!
January 17th, 2005 at 11:30 pm
We really liked the website .. Thank you.
March 13th, 2005 at 11:15 pm
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.
March 21st, 2005 at 9:32 am
Because this is one button, whereas your solution would require two buttons…. The macro Rebuilds, and then, on a successful rebuild, runs the solution.
March 25th, 2005 at 2:49 pm
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.
May 13th, 2005 at 12:42 pm
What? You code in a browser? Hmm. That is odd. We do use it quite a bit for our ASP.NET projects as well…..
December 7th, 2006 at 9:27 am
been looking for this for a while, Thank You!.
February 2nd, 2007 at 2:44 am
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
February 2nd, 2007 at 4:27 am
…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.
January 27th, 2009 at 2:30 am
Nice work! I’ll have to do a cross post on this one