Prabir's Blog

open source geek and lover of all tech  

Seeing the tweets around, by now most of you have already downloaded and tried out NuPack either by installing the library or creating your own NuPack package using the nuspec file. So, I’m gonna skip all the intro and jump straight to nuspec intellisense support inside Visual Studio. (will skip compiling nuspec to create the package also).

Every time you want to create a NuSpec file, you would open your favorite browser and navigate to the NuPack documentation and see the nuspec specifications. That could be a lot of hassle especially if you don’t have multi-monitor support and you have to press alt+tab. To solve this, I will show you some tips to work with Visual Studio.

Here is a sample screenshot when you open nuspec file in Visual Studio.

default nuspec editor in VS

(Notice that there is also no syntax highlighting and intellisense support.)

There is a hidden feature in Visual Studio to map certain extensions to a particular editor. Since nuspec is an xml file, we need to tell VS to map it to the xml editor.

  • Open the Tools>Options menu.

Tools>Options

  • Make sure you select “Show all settings”.
  • Then choose Text Editor> FileExtensions.
  • Then add “nuspec” as Extension.
  • Select Xml (Text) Editor with Encoding
  • Click Add
  • Click OK
  • Restart Visual Studio

Now when you open a nuspec file in visual studio you will get syntax highlighting support same as with other xml files.

Syntax Higlighting for nuspec

But you still don’t have any intellisense support.

There is a trick to get the intellisese in VS by using the xmlns and xsd combination.

First of all you need to get the xsd schema for nuspec at http://nupack.codeplex.com/documentation?title=Nuspec Format , save it as xsd and add that xsd to Visual Studio solution (Add Existing Item). (It can be referenced as solution item rather than a project item).

Now modify the <package> tag to add the xmlns attribute.

xmlns for nuspec

Select http://schemas.microsoft.com/packaging/2010/07/nuspec.xsd as the xmlns. That is it. Now you have intellisense support for nuspec files.

intellisense for nuspec

I have also created an issue at codplex to add this support, you can view it at http://nupack.codeplex.com/workitem/207

Incase you want to download the xsd you might want to visit my FacebookSharp library project http://github.com/prabirshrestha/FacebookSharp/blob/nupack/src/nupack/nuspec.xsd(at the moment it is available in ‘nupack’ branch only. There is also a sample on using rake and albacore to create the package using ‘rake nupack’ – will work on an albacore task to create the package later on).

You can also use this same trick to support intellisense support in VS for your custom web.config section. You can check out my previous article Custom web.config Intellisense.

Like my VS theme? download it at http://blog.prabir.me/post/My-Visual-Studio-Theme.aspx

 

(This is a part of my series Visual Studio Tips and Tricks – X)

There at times when we write long nested codes in the same file. To organize our codes we split the logic in different classes and files, and yet we still need to organize it further down. With the introduction of C# region directives, it helped us organize pieces of statements to form a collapsible region as show below.

image

image

This is a pretty good solution to organize the codes. But as we keep adding them, it soon turns out to be more messy than ever before. Sometimes we might even prefer to temporarily collapse a particular block. This is not a problem for classes or methods. But what if we want the same for any arbitrary statements or piece of code? Wouldn’t that be great?

No worries. VS already has a solution for us. Its always been there in front of us and yet we failed to discover.

stop it … and show me how?

Ok. First of all select the the code you want to collapse then right click the editor and click Outlining > Hide Selection.

image

Did you notice something weird? I actually selected only the condition inside the if statement and hid the selection. It would then look as below.

imageIsn’t that cool?

Now try closing that file and reopen. VS is smart enough to remember the old collapsible selection.

image

So, the shortcut of the day would be Ctrl + M, Ctrl + H to hide the current selection.

(This is a part of my series Visual Studio Tips and Tricks – X)

Some of you must have already tried my Dark Visual Studio Theme from http://blog.prabir.me/post/My-Visual-Studio-Theme.aspx as seen below.

dark visual studio theme

But as I upgraded to Visual Studio 2010, some of the colors didn’t seem to go well with the new WPF editor.

image

As you can see above, you cannot read the text at all, and its too bright which breaks the total aim of the theme. I have upgraded the theme to have better support in VS2010. Tweaked a bit of settings to suit VS2010.

Now the fixed one would look like this.

image

There are others changes also especially to the .aspx pages. When you upgrade my VS2008 settings in 2010 it would be displayed as below. The <% %> colors are unreadable. The same with JavaScript keywords (function…) and strings. And for some reasons, the HTML attribute the appears in red which it should not had been as shows below. (for some reason VS2010 didn’t upgrade this particular setting – HTML attribute name color)

image

Now that I have fixed, it is more pleasant as you can see the updated version below.

image

Now its better. I had to make some changes like the keyword to green which is the same as in C#, because the blue as in VS2008 didn’t seem to work at all. It was too blurry. The same with strings – defaulted to C# type coloring. I hope the C# type coloring in JavaScript will help you get familiar more easily.

Any other stuffs I forgot to update, please leave a comment below.

Read my original article on the dark theme on why you should shift @ http://blog.prabir.me/post/My-Visual-Studio-Theme.aspx

Note: The font used is Consolas which comes preinstalled with Windows Vista and up. But incase you want to use it for your Windows XP, Windows Server 2003 or others you can either download from below or from the official Microsoft link over here. 

Click here to download the theme

Prabir.vssettings (209.98 kb) [For VS2010] (Right click and Save Target As ...)

CurrentSettings.vssettings [For VS2008](252.68 kb) (Right Click and Save Target As ...)

Consolas Font Pack for Microsoft Visual Studio 2005 or 2008.exe (4.33 mb)

This same theme for Eclipse IDE can be downloaded from http://blog.prabir.me/post/Dark-Eclipse-Theme.aspx.

[UPDATE]

Due to the popularity. I moved moved the themes to be in source control, which can be found at http://gitorious.org/themes. If any one of you would like to contribute your own theme or extend my dark theme please post it in the comment below. My dark themes for various IDEs and text editors can be download from http://www.ohloh.net/p/themes/download

Visual Studio 2010 has been my default IDE now. It has a bunch of cool features to work with. But unfortunately some of my colleagues are not comfortable in migrating to VS2010 as it is in beta stages or either they don’t want to have 2 instances of VS installation which takes up their storage.

But I couldn’t just leave VS2010. Not only because of its new features but also due to the fact that it has to be the default IDE later on anyways and VS team needs to find as much bugs and errors and fix them all by the time it RTMs. (VSTeam actually really does listen to your feedback. They fixed all my 10 bugs I reported in VS2010 Beta 1. So for the betterment I would like you to try updating to VS2010 and find as much bug as you can and send them feedbacks.)

Now lets get to the real thing of downgrading. I will not be explaining on how to upgrade from VS2008 to VS2010, because it already does automatically. But I will rather be going through on how to do the opposite.

1. Make a backup copy of your .sln file. It will result in two solutions. One for VS2010 and the other for VS2008. The .csproj files doesn’t need to be modified at all.

2. Open one of the .sln file in a text editor (notepad is more than fine).

image

 

You will see somewhat like the above in the selected text, where version is 11.00 and visual studio version is 2010.

3. Edit the version numbers. Now change it 11.00 to 10.00 and 2010 to 2008.

image

 

Then save it. Rename your solution files to solutionname-2008.sln and solutionname-2010.sln or something like that if you want.

Now you can open it in older version’s of Visual Studio.

But since my VS2010 is my default IDE, I didn’t even install VS2008 rather installed only VS2008 C# Express versions. You can open it from VS2008 C# Express Versions, but test projects will not be loaded and solution folders will not work. Besides that everything will most probably work fine.

Note: Any updates like adding new file in VS2010 or VS2008 is also maintained in both solutions, because the file structures are stored in .csproj file which is by nature VS version independent.

And since my projects are at max in .NET v3.5, it all works fine in VS2008. I did land up with some warning errors during compilation under VS2008.

Project file contains ToolsVersion="4.0", which is not supported by this version of MSBuild. Treating the project as if it had ToolsVersion="3.5".

So since it goes back to 3.5 it still works fine. You can just ignore the warning.

(This is a part of my series Visual Studio Tips and Tricks – VIII)

Have you ever been working on a visual studio project with lots of tabs open and find it difficult to navigate around even with ctrl + tab. Well I hope this tip is going to help you.

Let’s say I have a bunch of tabs opened.

image

I could use ctrl + tab (similar to alt + tab for normal windows applications) and get the following result. which would allow me to navigate with live preview.

image

Even though it still gives me a great UI, it still isn’t productive especially when you need to submit your code to boss by evening. So you are telling me there is much better solution?

Yeah and simple one. Just Ctrl + Alt + down arrow key.

image

That instruction would tell Visual Studio to show a list of open tabs. You can then use arrow keys or mouse to click on one of those files. What is more cool is that if you actually know the name of a file, you can also type it and it tries to match up with it. It doesn’t match the file name if you enter it from the middle. It has to be left to right.

If you still want another solution. You can check about my previous visual studio tips and tricks at http://blog.prabir.me/post/Visual-Studio-Tips-and-Tricks-IV.aspx.