SQL Code Highlighting in Visual Studio


This is something I’ve been trying to do for a while and finally found the solution in a forum post (. The post is very succinct so I’ll expand on it a little more here.

I am working with .SqlDataProvider files which are basically T-SQL scripts to create data tables, stored procedures and other db objects. When you open a file like this in Visual Studio, you get no syntax highlighting at all. There is an option to associate file extensions to editors within VS but none of them allow you to match an extension with the SQL editor. The only way to do this is by a little registry hack.

Here is how it’s done so you can repeat it for any other language type:

1. Open the registry editor (regedit.exe)
Note: if you don’t feel comfortable with editing the registry, I’d suggest that you stop right there and deal with the non-highlighted text

2. Go to
HKEY_LOCAL_MACHINE
–SOFTWARE
—-Microsoft
——VisualStudio
——–version
———-Languages
————Language Services
where version is the version number for your Visual Studio (8.0 for VS 2005 and 9.0 for VS 2008)

3. When you expand the Language Services key, you get a list of languages supported by VS. The one we are interested in is T-SQL90. Expand this key and copy the string value called (Default). For T-SQL90, the value is {43AF1158-FED5-432e-8E8F-23B6FD592857}

4. Now, go to
HKEY_LOCAL_MACHINE
–SOFTWARE
—-Microsoft
——VisualStudio
——–version
———-Languages
————File Extensions

5. Create a new key with the name of your extension including the dot. In our example the key name will be .sqldataprovider

6. In the newly created key, paste the value that we previously copied in the (Default) String Value. You can also define a name for the extension by creating a new String Value called Name and setting it to any name you want

You can now close the registry editor, restart your Visual Studio and voila, your SQL code is highlighted

Reference: Thank you Neolithos for this solution – http://social.msdn.microsoft.com/Forums/en-US/vsx/thread/9187dc75-fc05-4872-bfc1-1fdbff590df2/

Visual Studio Gallery


That is just a quick post to share 2 extensions for Visual Studio that I just discovered and already know I won’t be able to live without.

First, I looked at the Visual Studio Gallery before but kind of forgot about it until I read an article (categorized as Vendor-Sponsored Content so not available online) in the October issue of the MSDN Magazine. This article was about a top 10 list of free extensions for Visual Studio.

Anyway, the first extension is called GhostDoc and allows auto-generation of XML comments. I can already hear you say “yeah, but if I put 3 quotes in VB or 3 slashes in C# it already does that for me”. Nope, this extension not only creates the structure of the comment section but also writes the comments depending on what you are trying to comment. Here is an example of comment generated by GhostHost:

   1: /// <summary>
   2: /// 
   3: /// </summary>
   4: public class Person
   5: {
   6:     /// <summary>
   7:     /// Initializes a new instance of the <see cref="Person"/> class.
   8:     /// </summary>
   9:     /// <param name="name">The name.</param>
  10:     /// <param name="age">The age.</param>
  11:     public Person(string name, int age)
  12:     {
  13:     }
  14: }

Of course this is a very simple example but I didn’t type a single line of comment. It was all generated by the tool. It does so much more than that so imagine the potential time saving. It supports C# and claims to be only experimental for VB but so far it seems to be working fine in both cases.

The extension can be downloaded at http://visualstudiogallery.com/ExtensionDetails.aspx?ExtensionID=46a20578-f0d5-4b1e-b55d-f001a6345748

The second extension is called Power Command. This extension adds many function to the context menu within Visual Studio. Some of the new functions are shown in the screenshot below. I think one of the most useful for me right of the bat is the “Collapse Project” one. We have a few solutions with many projects and for some reason, VS always opens the solution with all projects expanded. Just with 2 clicks, you can collapse all projects.

image

The extension can be downloaded at http://visualstudiogallery.com/ExtensionDetails.aspx?ExtensionID=df3f0c30-3d37-4e06-9ef8-3bff3508be31

Update 11/7: Found out that this extension crashes VS when trying to add items to the toolbox or opening Xaml files. I experiences the toolbox issue myself. Still a great extension developed by MSFT so let’s hope this issue will be resolved soon and a new version published.

I may post more of those later if I find any more useful ones (I tend to be a sucker for plug-ins, add-ons and extensions in general…)

Error Adding WebReference in VS2005


Today I was trying to add a Web Reference to an existing project in Visual Studio 2005 and got the following error message:

The web services enumeration components are not available. You need to reinstall Visual Studio to add web references to your application.

I tried several solutions found online (except the one suggesting to uninstall and reinstall Visual Studio) but what finally did the trick was a simple command line:
Open the Visual Studio 2005 Command Prompt and type the following command:

devenv /resetskippkgs

Item Templates not showing up in VS2005


I recently converted the WebPart template provided by Microsoft from C# to VB (At the time I am writing this post, Microsoft hasn’t released a VB version and we are, unfortunately, standardized on VB).
After converting the code and placing it in the appropriate folder (C:\Program Files\Microsoft Visual Studio 8\Common7\IDE\ProjectTemplates\VisualBasic\SharePoint\), the template was still not showing when creating a new project. This was because the templates cache had to be refreshed. I was able to solve this thanks to a post by Eric Hammersley (Missing an item template in Visual Studio 2005? Try this…)

The secret was just to open a VisualStudio Command prompt and run the command

devenv /installvstemplates

Optimizing VS2005 speed


I found 2 interesting blog posts about optimizing the speed of VS2005 both at startup and during regular usage:

.NET Tip of The Day: Optimize the launch of the Visual Studio 2005

.NET Tip of The Day: Speed up Visual Studio 2005