Viewing Linqpad scripts in VS2013

I use LINQPad all the time at, both for experimenting with C#, and for building and testing Linq queries before I import them in our projects.

As an example, I recently wrote a few scripts for fetching some data from a database, and reformatting it into JSON data which we will use as dummy-data for testing. This will not be a part of our finished project, but it’s still nice to have the script visible in Visual Studio, even if I only run it through LINQPad .

The following are a couple of tips I’ve found useful when working with .linq-files in or from within Visual Studio.

Formatting linq-files as C# code

Scripts from Linqpad like these are typically saved as “someFile.linq”, which is fine, except that they are displayed as plain text files in when opened in Visual Studio. I find it useful to be able to format and read these files as C# code from within VS, and not have to open them in LINQPad  to do that.

Here’s how that can easily be achieved:

UsingLinqInVS2013

Under TOOLS > Options > Text Editor > File Extension you can add the file extension “linq”, and select the default editor to use to display this type of file – as I’ve done in the picture. Now, when you open a linq-file in VS, it will look nicely formatted:

FormattedLinqInVs

 

Using Linqpad to automatically open .linq files

If you prefer to always use LINQPad  to open .linq files, just associate a .linq file with the program as follows: Right click a .linq file, and select open with. In the window shown below, click Add, and browse to where you’ve got LINQPad installed. Once you’ve added it to the list, you can choose whether to set it as the default program to open .linq files. If you do, it  LINQPad will open every time you double click a .linq file from within Visual Studio. If like me, you prefer to be able to browse the file quickly in Visual Studio, you can just leave  LINQPad in the list, and use e.g. “Source Code (Text) Editor)” as the default app for working with .linq files. That will let you see the file in VS, while still letting you open it easily in  LINQPad using the Open With context menu.

OpenLinqInLinqpad

Engage and contribute for the common benefit of mankind!

This site uses Akismet to reduce spam. Learn how your comment data is processed.