Demo: Exec-Inline, an Add-in that executes the currently selected code, immediately
secretGeek .:dot Nuts about dot Net:.
home .: about .: sign up .: sitemap .: secretGeek RSS

Demo: Exec-Inline, an Add-in that executes the currently selected code, immediately

Execute the code immediately under the cursor

You're in Visual Studio (2003 in this case)

  1. Highlight the code you want to run.
  2. Press the 'exec inline' button on the toolbar.
  3. The code is compiled and executed in its own little assembly

All credit goes to these four places:

Code compilation retyped from jconwell's Dot Net Script Project at CodeProject.

Wrapper around compilation retyped from dstang2000's DynamicCompileAndRun project.

Help with writing a VS Add-in: Scott Swigart, PasteAs Visual Basic Add-in

And help with getting the currently selected text from the IDE, retyped from Kevin McFarlane's VS Csharp Macros page.

I deliberately re-typed, rather than copying and pasting their code, so that I'd have to really look at what was going on in every place.

(continues with 'how does it work')

How does it work?

The code you select gets wrapped inside it's own class (unless it contains a class of its own) and then an entry point is added to this class. A bunch of common imports (i.e. include) statements are added, just in case.

It's compiled using System.CodeDom.Compiler which is remarkably easy to do.

If the code doesn't compile -- then I display a mini window, showing the generated code, and what compilation errors there were. This gives you a chance to alter the code and get it to work.

If there's a runtime exception, then I display the same window, along with the exception that occurred.

I don't have enough time to work on this project. So it's on the backburner, alongside ShinyPower Analyzer, WSCG v4, Crank, SimpleTests, and everything that isn't TimeSnapper or Advantech.

Writing this add-in was actual just a detour along the way toward writing a SimpleTests add-in, which I'm still kicking around in the back of my mind.

The steps and decisions involved in getting that puppy to fly are all too many.

Regarding exec immediate: Source code currently is VB only (since the PC i first developed it on didn't have C# installed). Once I've made it work for both languages, I'll post the project up.





'Snippet Compiler' on Thu, 19 Oct 2006 21:34:00 GMT, sez:

Check out Jeff Key's snippet compiler -- 3 years old now!

maybe when errors occur then snippet compiler could be launched with the generated code in there.

and when the snippet is done, it could be pasted over the top of the original selected text in visual studio.



'Dan F' on Thu, 19 Oct 2006 22:24:38 GMT, sez:

Dude! This feels like the old method of banging some code into the immediate window for days when you were having a brain fade, only it's better! I love it. Or, I'm pretty sure I'll love it, haven't actually tried it yet. This is going straight to the pool room though.

I think it's got a definite advantage over snippet compiler for some situations. Sometimes you just want to test a certain behaviour, a small snippet, etc. Being able to do that in mid flow without having to copy, paste into snippet compiler, test, copy, paste back into the IDE, will be ace.



'Dan F' on Thu, 19 Oct 2006 22:35:11 GMT, sez:

Am I having one of the aforementioned brain fade days, or is there no link to try this beast? Help a fellow downunderian out lb :)



'lb' on Thu, 19 Oct 2006 23:04:05 GMT, sez:

@Dan: code is winging its way to you now.



'Joshua Flanagan' on Fri, 20 Oct 2006 03:09:44 GMT, sez:

Neat tool.
Another simliar solution to this and Snippet Compiler is the "Ad-hoc" test runner in the TestDriven.NET Add-in. Requires a little more overhead than yours (you have to make a void Foo() method to wrap the code you want to play with), but has the nice advantage of being able to interact with all of the other objects in your project.



'lb' on Fri, 20 Oct 2006 03:19:22 GMT, sez:

Yeh this tool works by wrapping the void Foo() around your code --

In the case of a simple 'MessageBox.Show("HelloWord")', this is the code that actually gets compiled:


Imports Microsoft.VisualBasic
Imports System
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Data
Imports System.Threading
Imports System.Xml
Imports System.Collections
Imports System.Diagnostics
Public Class Fred
  Public Sub New()
    MessageBox.Show("Hello")
  End Sub
  Private Shared Sub Main()
    Dim f As New Fred()
  End Sub
End Class



'Jim Mc' on Fri, 20 Oct 2006 05:32:12 GMT, sez:

hi,

i'm a long time reader, first time poster. great site!!

is there any chance I Could get a copy of the VB Source? This would be a very useful tool to have :o) (sorry, im impatient and wanted to try this)

i'm at (removed for privacy reasons)@Hotmail.com

thanks,
Jim



'lb' on Thu, 26 Oct 2006 09:02:56 GMT, sez:

** BETA TESTERS NEEDED **

anyone else who's after the code to this one -- just write and ask for it:

leonbambrick at gmail dot com




'JIthendra' on Tue, 31 Oct 2006 03:41:39 GMT, sez:

Hi can I get a copy of this cool stuff.



'Ian' on Fri, 03 Nov 2006 01:28:08 GMT, sez:

could i please get a copy of the code??

(removed for privacy reasons) at hotmail.com

thanks!! great idea btw






name


website (optional)


enter the word:
 

comment (HTML not allowed)


All viewpoints welcome. Incivility is not tolerated, such comments are deleted.

 

I'm the co-author of TimeSnapper, a life analysis system that stores and plays-back your computer use. It makes timesheet recording a breeze, helps you recover lost work and shows you how to sharpen your act.

 

NimbleText - FREE text manipulation and data extraction

NimbleText is a Powerful FREE Tool

I wrote this, and use it every day for:

  • extracting data from text
  • manipulating text
  • generating code

It makes you look awesome. You should use NimbleText, you handsome devil!

 

Articles

The Canine Pyramid The Canine Pyramid
Humans: A Tragedy. Humans: A Tragedy.
ACK! ACK!
OfficeQuest... Gamification for the Office Suite OfficeQuest... Gamification for the Office Suite
New product launch: NimbleSET New product launch: NimbleSET
Programming The Robot from Diary of a Wimpy Kid Programming The Robot from Diary of a Wimpy Kid
Happy new year 2014 Happy new year 2014
Downtime as a service Downtime as a service
The Shape of Your Irrationality The Shape of Your Irrationality
This is why I don't go to nice restaurants any more. This is why I don't go to nice restaurants any more.
A flowchart of what programmers do at work all day A flowchart of what programmers do at work all day
The Telepresent Man. The Telepresent Man.
Interview with an Ex-Microsoftie. Interview with an Ex-Microsoftie.
CRUMBS! Commandline navigation tool for Powershell CRUMBS! Commandline navigation tool for Powershell
Little tool for making Amazon affiliate links Little tool for making Amazon affiliate links
Extracting a Trello board as markdown Extracting a Trello board as markdown
hgs: Manage Lots of Mercurial Projects Simultaneously hgs: Manage Lots of Mercurial Projects Simultaneously
You Must Get It! You Must Get It!
AddDays: A Very Simple Date Calculator AddDays: A Very Simple Date Calculator
Google caught in a lie. Google caught in a lie.
NimbleText 2.0: More Than Twice The Price! NimbleText 2.0: More Than Twice The Price!
A Computer Simulation of Creative Work, or 'How To Get Nothing Done' A Computer Simulation of Creative Work, or 'How To Get Nothing Done'
NimbleText 1.9 -- BoomTown! NimbleText 1.9 -- BoomTown!
Line Endings. Line Endings.
**This** is how you pivot **This** is how you pivot
Art of the command-line helper Art of the command-line helper
Go and read a book. Go and read a book.
Slurp up mega-traffic by writing scalable, timeless search-bait Slurp up mega-traffic by writing scalable, timeless search-bait
Do *NOT* try this Hacking Script at home Do *NOT* try this Hacking Script at home
The 'Should I automate it?' Calculator The 'Should I automate it?' Calculator

Archives Complete secretGeek Archives

TimeSnapper -- Automated Screenshot Journal TimeSnapper: automatic screenshot journal

25 steps for building a Micro-ISV 25 steps for building a Micro-ISV
3 minute guides -- babysteps in new technologies: powershell, JSON, watir, F# 3 Minute Guide Series
Universal Troubleshooting checklist Universal Troubleshooting Checklist
Top 10 SecretGeek articles Top 10 SecretGeek articles
ShinyPower (help with Powershell) ShinyPower
Now at CodePlex

Realtime CSS Editor, in a browser RealTime Online CSS Editor
Gradient Maker -- a tool for making background images that blend from one colour to another. Forget photoshop, this is the bomb. Gradient Maker



[powered by Google] 

How to be depressed How to be depressed
You are not inadequate.



Recommended Reading


the little schemer


The Best Software Writing I
The Business Of Software (Eric Sink)

Recommended blogs

Jeff Atwood
Joseph Cooney
Phil Haack
Scott Hanselman
Julia Lerman
Rhys Parry
Joel Pobar
OJ Reeves
Eric Sink

InfoText - amazing search for SharePoint
LogEnvy - event logs made sexy
Computer, Unlocked. A rapid computer customization resource
Aussie Bushwalking
BrisParks :: best parks for kids in brisbane
PhysioTec, Brisbane Specialist Physiotherapy & Pilates
 
home .: about .: sign up .: sitemap .: secretGeek RSS .: © Leon Bambrick 2006 .: privacy

home .: about .: sign up .: sitemap .: RSS .: © Leon Bambrick 2006 .: privacy