Saturday, February 25, 2012

Starting LINQPad 4 from Visual Studio Express

As I am writing this year’s Code Camp presentation about Entity Framework, I’ve come across a problem: I want to use Visual Studio Express 2010 AND I want to demonstrate Linq to Entities using LINQPad 4. If I were using a commercial version of Visual Studio, I could use Start Action = Start external program. I can’t just launch LINQPad and edit my project because LINQPad would lock my assembly and Visual Studio would refuse to build a new one.

So, to work around this limitation, I added a console project that would launch LINQPad and wait for it to return.

C#:

using System.Diagnostics; namespace LaunchLinqPad { class Program { private const string LINQPAD_EXE = @"C:\Program Files (x86)\LINQPad4\LINQPad.exe"; static void Main(string[] args) { var process = new Process(); process.StartInfo = new ProcessStartInfo(LINQPAD_EXE);> process.Start(); // Without this, the program will exit immediately process.WaitForExit(); } } }

VB:
Module Module1
    Const LINQPAD_EXE = "C:\Program Files (x86)\LINQPad4\LINQPad.exe"
    Sub Main()
        Dim process As New Process()
        process.StartInfo = New ProcessStartInfo(LINQPAD_EXE)
        process.Start()
        ' Without this, the program will exit immediately
        process.WaitForExit()
    End Sub
End Module

A couple of issues:

  • This doesn’t work with LINQPad 4 (and newer)
  • I can’t step into my code.

Even with these limitations, I find this helpful because doing this endures that LINQPad is closed before I recompile, therefore preventing me from locking up the file that I am building.

No comments: