Archive for Visual Studio.Net

Sass for Visual Studio 2010

// January 21st, 2011 // 25 Comments » // .Net, cool tool, Pet projects, Visual Studio.Net

The other day my buddy Nathan was telling me about how he was using Sass on his new project and I was intrigued by the idea. Using variables, nesting etc. in CSS? Sounded weird at first. But then I was thinking “yeah. why don’t we have all that already?”.

So I started reading up on it and I quickly realized that this is big. I don’t know if you guys have heard of it already. But I was surprised I didn’t know about it until now. Apparently, this has been out there for a while.

Anyways, here’s what the website has to say about Sass.

Sass makes CSS fun again. Sass is an extension of CSS3, adding nested rulesvariables,mixinsselector inheritance, and more. It’s translated to well-formatted, standard CSS using the command line tool or a web-framework plugin.

Anyways, long story short, I saw what Sass could do and was impressed. So I wrote a Visual Studio Add-in that compiles scss code into css for you. After you install the add-in, you’ll be able to right click on a project and click on a menu item (“Convert SCSS to CSS”) that will scan every scss file in the project and create respective css files for each of those (in the same folder) and also continuously “watch” the scss files for changes, meaning, as soon as you save a change to an scss file, it’ll immediately update the corresponding css file.

Sound good? Ok, let’s get started.

1. Install Ruby (Windows)

Go to and install the latest version of Ruby (if you don’t already have it). I downloaded the Ruby 1.9.2-p136 package.

Make sure you check “Add Ruby executables to your path” (as shown below) during the installation.

2. Install HAML

If you don’t know what Haml is, don’ t worry. All you need to know is that Sass is bundled with Haml, which means you need to get Haml to get Sass. And that’s what we’ll do next.

Close all command prompts if you have any open. Open a new command prompt window and run the following command.

gem install haml

If things went ok, here’s what it should look like.

3. Install Sass for Visual Studio Add-in

Now it’s time to install Sass for Visual Studio Add-in. Here are setup files – Download

Just do the regular setup. Should be straight forward.

4. Create a test web application

Let’s test the add-in now. Close all instances of Visual Studio 2010. Open a new instance and create an empty web application.

I renamed the project to Test. But it doesn’t make any difference what you name it. I just didn’t want you guys to be confused by the following screenshots in which the project says “Test”.

5. Add new folder called styles and create a new stylesheet in it

Again, name of the CSS file doesn’t matter because we are about to rename it.

6. Rename the stylesheet and add sample code to the file

Change it from stylesheet1.css to base.scss. Note the extra *s* in the file extension. S stands for Sassy (not kidding).

Now add the following code to the file. (Also note that this is not plain css. Look at the nesting.)

#navbar {
width: 80%;
height: 20px;

ul { list-style-type: none; }
li {
float: left;
a { font-weight: bold; }

7. Time to put the add-in to work

Right click on the project and click “Convert SCSS to CSS”

8. Click Show All files in Solution Explorer top bar

9. Verify that a new file called base.css has been created

A new file named base.css should have been created. Include that file in the project and open it to make sure it has the following code.

#navbar {
width: 80%;
height: 30px; }
#navbar ul {
list-style-type: none; }
#navbar li {
float: left; }
#navbar li a {
font-weight: bold; }

The above code is regular css that was rendered from the code in base.scss by the ruby script.

11. Instant updates to css

Make a change to base.scss and watch base.css get updated instantly (No need to click on the add-in menu item again). The red arrows in the image below point to the change made in the scss file and the pop up tells you that base.css got updated.

12. Don’t like it? Uninstall

Do it the old-school way. Go to Control Panel > Programs > Uninstall a program and remove it from there.

Restart Visual Studio.

Open a solution and right click on a project. If the menu item is still there, click on  it and Visual Studio will prompt you to remove it.

16. This is Alpha version.

So please forgive any bugs. And if you really care, send me a tweet @appoosa for quicker response or leave your feedback in the comments below.

UPDATE:: I’ve opened up this project to the open-source community. You can find it here –

SECOND UPDATE::Based on the comments below and email feedback, it looks like SASS is a separate install now. So after Step 2 above, run the following command.

gem install sass

And then proceed with Step 3 and continue the process as mentioned above.

Visual studio custom short cut hot key mapping

// March 1st, 2009 // No Comments » // Sharepoint, Visual Studio.Net

My first post in 2009. Took only 2 months into the year. Sigh! There goes my resolution. On the positive side, it is a technical post. Been a while since I posted one of these.

Anyways, let’s get to the point.

So in the current project I’m working on, I build SharePoint web parts. A lot of them. As with typical SharePoint projects, the web parts need to be deployed to the GAC/assembly. before they can be added to the pages.

The problem with this as you can imagine, is that every change no matter how small or big it is, needs to be built and the assembly copied to the GAC (C:\Windows\assembly). If you are using the WSPBuilder Visual Studio plugin, this is probably a bit less cumbersome than going to the location of the DLL and manually copying it and pasting it in the assembly folder, you know, using good old Windows Explorer.

This is great if you are big fan of the mouse. Just 4 clicks/gestures. One for the build. And 3 for the GAC deployment – Right click on the project, Click on WSPBuilder, Select Copy to GAC.

But for people like me, that prefer keyboard short cuts over mouse clicks, here’s how we can make this much faster – Map custom short cut keys to do the build and deploy.

You may already know that Ctrl + Shift + B builds the project. But it builds not just the current project but every other project related to it (and may be even the independent ones too if I’m right).

Now that is still 3 keys. Let’s see if we can bring it down to 2 keys.

Here we go.

  1. Click on Tools – Customize in Visual studio as shown below.

Click on Tools Then Click on Customize

2. Click on Keyboard

Click on Keyboard

3. We need to find “Build.BuildSelection” command. So start typing that in the “Show commands containing” textbox. It’s autocomplete as you can see below. So just select the item as soon as it shows up.

Type Build.BuildSolution in Show Commands textbox

4. After you select it from the list, move your cursor to the “Press shortcut keys” textbox below and press the short cut keys. I chose Shift + F1 since I just have to use my left hand fingers and the keys aren’t too far apart.

Note that you CANNOT type your shortcut. You HAVE to press the keys on your keyboard as the text above the textbox says.

Select Build.BuildSolution from the list

5. After you select your short cut, the “Assign” button gets enabled as shown below. Click on that to assign the short cut to “Build.BuildSelection”.”Assign” button now becomes “Remove”. It took it. Good.

Assign Short Cut

6. Now click OK.

Click OK

7. Test the short cut now. Open up a file in a project and use your short cut. If everything worked ok, the project that file belonged to, would have been built. Just that project.

8. Wash. Rinse. Repeat. Do the same for “Copy To GAC” feature.

9. Look for “copytogac” in the commands text and you may notice that once you select the command as shown below, there already might exist a short cut for it. In this case it is Ctrl + Shift + Alt + B.

I don’t know about you but that is lot of keys to press for a simple command. It is ok though. You can leave it alone and map yet another short cut to the same command.

Type CopyToGac in the commands textbox

I chose Shift + F2.

Assign ShortCut to GAC

10. Click Assign and then OK. And all done! Now we can easily build and deploy the currrent web part/dll to the GAC with the press of just 2 keys per command.

Shift + F1 to build. Shift + F2 to deploy to GAC.

I suppose it must save some amount of time in the long term. Enjoy! :)

(Really)Quick and Easy SharePoint webpart

// October 29th, 2008 // No Comments » // ASP.Net, Sharepoint, Visual Studio.Net

If you have been in a situation where things are in a big hairy mess, you probably would follow the process of elimination to ensure you are not chasing the wrong items down the rabbit hole.

Now consider you are working with SharePoint and you are in a tight spot as mentioned above. You probably want to ensure that WSS/MOSS has been configured properly and that the problem is not with the webpart you are working on, for example.

Here’s a quick and easy way of writing a “hello world” webpart that doesn’t involve features and layouts and WSPs and stsadm commands and etc.

1. Open up Visual Studio 2008 and create a new class library project (name it something unique, for example, DingDongBellWebPart) and add the following code in Class1.cs

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Web.UI.WebControls.WebParts;

namespace DingDongBellWebPart


public class Class1 : WebPart


protected override void RenderContents(System.Web.UI.HtmlTextWriter writer)


writer.Write(“DingDongBell test”);






2. Check the Sign the assembly checkbox in Project properties Signing tab as shown below

Project properties

(Click on image above for better resolution)

3. Under Choose a strong name key file dropdownlist, select New.

4. Uncheck Protect my key file with a password as shown below

Create Strong Name Key

5. Give it a name and click OK.

6. Build the project.

7. Drag the projects dll from the bin folder and drop it in C:\Windows\assembly folder. This registers the DLL in the GAC.

8. Replace the values for the attributes where necessary in the line below and add this line in the <SafeControls> section in the web.config file of the website you are trying to deploy this webpart to. (You can even try the SharePoints central admins web.config file. should work.)

<SafeControl Assembly=”DingDongBellWebPart, Version=, Culture=neutral, PublicKeyToken=1af588c27b5f26e0″ Namespace=”DingDongBellWebPart” TypeName=”*” Safe=”True” />

**NOTE**: Don’t forget to replace the PublicKeyToken above. There are multiple ways to fetch the PublicKeyToken of your DLL. Here’s one way. Go to C:\Windows\assembly and right click on your assembly and click properties as shown below.

Webpart properties

9. Visit the following URL – http://insert_your_website_url_here/_layouts/NewDwp.aspx [Of course replace "insert_your_website_url_here" with your value]

10. It should show up in that list as shown below. (I know….it says GirishWebpart.Class1 in the screenshot below instead of DingDongBellWebpart.Class1. May be it is because I figured GirishWebpart was a much better name than the ridiculous-sounding DingDongBellWebpart.)

Webpart properties

(Click on image above for better resolution)

11. If it doesn’t work, reset IIS. And try again. Should work.

12. Enjoy.

How to get MOSS 2007 development environment setup in Vista

// August 11th, 2008 // 4 Comments » // ASP.Net, MOSS 2007, Pet projects, Sharepoint, SQL Server, Vista, Visual Studio.Net, Windows 2003

Alright Microsoft. You win. I have officially started working with Sharepoint now. I’m now one of the thousands of .Net developers that have been slowly but steadily and methodically, sucked into dark side of the “portal” world. A bunch of us in my company were hoping and praying that we don’t get placed on a project that would force us to learn this technology especially because of the horror stories we’ve heard. When someone like Rob tells you that sharepoint is the shittiest piece of software he’s ever worked on, that is saying something.

Anyways, enough of bitching. Every Sharepoint developer that i knew, installed VMWare on their machines that ran Windows 2003, SQL Server 2005 and VS 2005/2008 and used that as their development environment. Why? Because WSS 3.0 or MOSS 2007 runs only on server operating systems. Brilliant! Let me get this straight. We are supposed to build applications that would run on “portal” software that are hosted on servers, and so we are supposed to do our development on server operating systems? Of course! Makes perfect sense! Yay Microsoft!

I don’t know man…i just didn’t want to load yet another software on my box and do all the configuration. Luckily for me, Bamboo Solutions had figured out a way to get MOSS 2007 to run on Vista/XP operating systems. As always, i started off my learning process by opening up a brand new word document and taking screenshots of each and everything i did, right from scratch. That includes pictures of installation wizards, “This program has performed an illegal operation” errors (sugar coated for Vista), dashboards, Visual Studio IDE, etc.

The end result of all this pain is a document that has some blurry images but decent content on how to write a “Hello world” web part and successfully deploying it to a sharepoint portal, all starting from scratch. This tutorial would make more sense if you are a .Net developer and have been doing custom application development for a while. It is meant for someone that has no idea where to begin, in their attempt to learn Sharepoint. So if you feel some of the screenshots in the document insult your intelligence, just remember that not all people are as smart as you, wise guy.

Here’s the doc in PDF - How-to-get-MOSS-2007-development-environment-setup-in-Vista


How to use a custom response file with TFS 2008 build

// May 14th, 2008 // 2 Comments » // Team Foundation Server, Visual Studio.Net

A Team Foundation Server 2008 build uses 2 important files – the build file (TFSBuild.proj) of course and the response file (TFSBuild.rsp). A response file is used to pass configuration parameters to MSBuild process. By default, the build uses TFSBuild.rsp as the default response file.

Here’s the content of a sample response file.

# This is a response file for MSBuild
# Add custom MSBuild command line options in this file
/p:BTSPath="E:\Program Files\BizTalk 2006 Runtime"

As you can see above, there are quite a few parameters that you can use in the proj file (which by the way, is by using $<insert_parameter_name_here>.

For example, <BizTalkFiles Include="$(SolutionRoot)\$(BuildBranch)\$(BuildPath)*.dll" />

Now sometimes you might need the build to use a custom response file instead of the default one. For example, if you want to have just one master build file that would use different response files depending on the type of deployment (QA, Development, Testing etc.), you need a way to pass in the response file.

Here’s how you do it using Visual Studio 2008.

1. Right click on the Build Definition you want to use (in my case the build definition is called Interactive as you can see below) under the Builds folder in your Team Explorer window and click Queue New Build.

Queue New Build

2. In the MSBuild command-line arguments (optional) text field, type @ followed by the location of the response file you want the build to use.

Build Definition Properties

3. And click Queue.

I have written a little windows deployment helper that would do all this and much more for you. For example, it would help deploy builds by TFS labels. I’m thinking about putting it on codeplex after cleaning it up a little bit. Will write about it here soon…

“Run tests” option not available in the right click context menu

// March 1st, 2008 // No Comments » // Visual Studio.Net

I’m working on a high-profile project right now that uses some pretty cool advanced frameworks and tools in the business. Can’t reveal too much but here’s a lil’ list.

  • Windsor Container
  • Inversion of Control / Dependency Injection
  • LINQ (to SQL)
  • Continuous Integration (using Team Build)
  • ASP.NET MVC framework
  • Rhino Mocks
  • VS2008 Team Edition for Devs
  • MSTest (unit tests)

Jealous much? ;)

Anyways, so i was working on this unit test case to make some minor changes and after i was done, i tried running it by right clicking in the code window, and hoping to click on the “Run Tests” option in the context menu. Here’s what i was hoping to see.

Context menu with

But i didn’t see that option. Hmm….time for a little investigation.

So how does Visual Studio know when to provide “Run tests” option in the right click menu? How does it know not to display it in a ASPX file or any other normal class file?

There must be some kind of identifier it uses to recognize a file/class as a test class and hence enable the option in such cases.

The test class files are C# files just like any other files in the solution and so you probably are not going to find a lot of differences comparing a test file with a non-test file besides the code it holds, of course.

So the next step is to compare the projects that hold these files. Let’s compare a non-test project and a test project. (I used ExamDiff to compare the .csproj files)

And here’s the result of the comparison. The one on the right is the test project (click on the image below for better resolution).

difference between a test and non-test project files

See where the red arrow points? The test project has a ProjectTypeGuid as shown below.


So that’s what differentiates a test project from a non-test project.

And that’s how Visual studio understands whether or not to show the “Run tests” option in the right click context menu for a class under a project.

Coming back to our oriignal problem, why was it missing in the class i was working on? The developer that created that project did not create it as a “test” project – instead he chose the “class library” option in the create new project dialog.

Fixing the problem was easy. Open the csproj file in some text editor and add the ProjectTypeGuids element where it belongs and you are done!

I feel like Sherlock Holmes sometimes….

What’s wrong with this picture?

// March 5th, 2007 // 3 Comments » // Vista, Visual Studio.Net

Last weekend I installed Virtual PC 2007 on my new Dell XPS M1710 Code Red Special Edition and have been trying to get all my tools installed in there on XP Professional. Why? Because i have Vista Ultimate loaded on the new box and as we all know, Microsoft decided not to support VS.Net 2003 on Vista. My full-time job requires me to build apps on 1.1 framework and i have no choice but to use Visual Studio 2003.

Anyways, so i download Virtual PC 2007 (download free from MS) and install it and i must say, it was pretty fast! And smooth. And then i installed Visual studio and VSS 2005 on it. Visual studio was painless and easy (surprised again).

But Visual Source Safe asked me to install XP Service pack 2 as a prerequisite. No problemo. Installed SP2 followed by VSS 2005 and voila! Here’s the message i get for successful installation.

Check out the pic below and tell me what’s wrong with the picture.

2 Free 7-11 beverage coupons to the correct answer.

VSS Successful installation

Hey Visual studio! We need to talk.

// July 23rd, 2006 // No Comments » // Visual Studio.Net

There are some things you do for me automatically by default assuming that i am an idiot and that i have no clue what i am doing when i’m building an application. It’s like you are indirectly telling me that “Look! i’m smarter than you and i will do things for you that you don’t need and you can go change it if you don’t like it.”

Not cool, babe!

For example, yesterday i was building a custom control and everything seemed fine initially. When i wanted to use the control in another project, it just wouldn’t work. I checked whether i had copied the custom control’s dll to the bin folder of the project i was working with. It was there. I checked if i had in fact added it to the references. I did. Was i using the right syntax? Yes. Then what the hell was the problem? The error message was that you couldn’t find the control in the dll under the given namespace. But the namespace was right. I had specifically set it to “GG” in the control. Here’s how i tried to use it in the test project.

I had no freaking clue what was going on. I tried rebuilding the solution, rebuilding the control and copy-pasting a fresh copy of the dll into the bin folder everytime. Nope. Didn’t work. It was like you were teasing me and i certainly did not appreciate it.

And then finally i remembered what Russ told me about what you do when someone adds a new project to the solution. He said you set the rootnamespace by default to the name of the project and that needs to be removed if i plan to have my own namespace for the project

So i right click on the project in the solution explorer and click on “Properties” as shown below.

Project properties

And this is what i see

Root namespace

You had in fact set the root namespace to the name of the project by default. Sigh!

Now why would you do that, honey? Please don’t be like that. I love you and i’ll do anything for you and you know that. But please don’t act oversmart. Show some respect here. I know you are smart and i totally dig that. In fact, it turns me on sometimes. But please don’t think i’m an idiot when i’m using you. I know how you are structured and how you work. I know almost all of the features you were built with. I also know how to use most of them to unleash your full potential, babe. Trust me! I can do wonders with you.

Now that we are on the topic, i have a couple of other things to discuss with you. Let’s just get it over with. The other day when i was trying to bind you to the solution in visual source safe (VSS – Your cousin), something pissed you off. I don’t what happened and what triggered your madness. But you just went nuts and used 100% of my CPU and 1.4GB of my memory. And then after 15 minutes, you gave me this message.

Catastrophic failure

I mean…seriously! Is that all you got for me? Catastrophic failure? What am i supposed to do with that? Could you be more specific next time, hon? I know sometimes you have your moments. But i wonder what the guy that actually wrote that piece of code when building you, was thinking when he/she was in fact writing that? “Yeah…i’m just gonna tell them something bad happened. The measure of bad being in the magnitude of a catastrophy. The user can figure out what went wrong.”

Last but not least(cliche!), i still wonder how childish you can be sometimes even after growing up to be such a charming young lady. In fact these days, i think you are a super woman. That’s how i look at you. But you still let the kid in you come out and play once in a while especially when i’m in the middle of rebuilding the solution. I understand that it can be a royal pain the butt to rebuild 16 projects in the solution, one at a time. But c’mon now…that doesn’t call for a peek-a-boo game in the middle of the working hours. You just disappeared during the re-build! Right in front of my eyes…whoosh! Vanished into thin air! I quickly pulled up the task manager and there you were – devenv.exe eating up memory and cpu cycles. But nowhere to be found to the naked eye in Windows. Grow up, sweety! Not all guys think that’s cute.

And while i’m at it, let me clear up something. I’m NOT having an affair with nant. She’s just a friend that helps me out with the build, especially when you are playing your little games of hide and seek. I don’t think she can give me what you can(one word – intellisense) and i don’t have any feelings for her anyways. If you play nice with me, i’ll stop going to her for help..ok?

I know you have tons of complaints against me. Especially the way i write inefficient code that drives CLR crazy. But let’s talk about it another day.