Lately I’ve been speaking at local user groups about many of the exciting new features in Visual Studio 2012. Since there is so much to know and learn about VS 2012, I decided to create a collection of blog posts with many of the tips. This collection of posts will include features that are new to VS 2012 as well as some existing features as well. To view all of the VS 2012 tips posted so far, click here.

Visual Studio 2012 has got a lot of great features. Some of them are really innovative and interesting. I don’t think of the Add Reference Dialog improvements as anything but “why in the world did this work so poorly before?”. I’m guessing the Visual Studio team had some reason but let’s face it, the old Add Reference Dialog just plain sucked. One of the biggest problems with it was that it was very slow to load. I’m happy to report that the new Dialog loads really fast! Try it out, I am sure you will be please with the results.

Access it as you did before, right click a project and then click “add reference”:

image

Like I said, it loads up really fast. As you can see, in the middle section is the complete list of assemblies from the .net framework. Note that the items with checkmarks have already been added to my project. Just as you’d expect, you can add references to installed.net assemblies, other projects in your solution and COM Libraries. And of course, you can browse your system for other .dlls.

When you use this the first few times I expect your get bit by the same snag that I did (and still do sometimes). See the screenshot below… Notice that I clicked on Microsoft.Build to add the reference. You can see it highlighted in blue. If I click the OK button I’ll be disappointed with the results as my reference will not be added. What is needed is either to double click the item in the list or click the checkbox itself. Either way you’ll see the checkbox is then checked. Now you can hit OK. By the way, unchecking an item in the list will remove it from your project.

image

 

I hope you find this tip helpful. To see more VS 2012 Tips, just click here.

Lately I’ve been speaking at local user groups about many of the exciting new features in Visual Studio 2012. Since there is so much to know and learn about VS 2012, I decided to create a collection of blog posts with many of the tips. This collection of posts will include features that are new to VS 2012 as well as some existing features as well. To view all of the VS 2012 tips posted so far, click here.

I think (I hope) it is a well-known fact that Visual Studio will automatically complete your event handlers for you. The problem is, I’ve never liked the way it did this and I always went in and cleaned them up. Not any more!

What am I talking about? Here’s a sample. In this case, I have a class Foo that has an event SomethingHappened.

    public class Foo
    {
        public event EventHandler SomethingHappened;

        public void OnSomethingHappened(EventArgs e)
        {
            EventHandler handler = SomethingHappened;
            if (handler != null) handler(this, e);
        }
    }

In another class, I have an instance of Foo named foo. To wire up that event, all I need to do is type:

foo.SomethingHappened += [TAB][TAB]    (I hope you know that I mean hit the “tab” key twice Smile)

When you do that in Visual Studio 2010 (and prior), you will get the following results:

public class SomeService
{
    private Foo foo = new Foo();
    public SomeService()
    {
        foo.SomethingHappened +=new EventHandler(foo_SomethingHappened);
    }

    void foo_SomethingHappened(object sender, EventArgs e)
    {
        throw new NotImplementedException();
    }
}

What happened here? Visual studio added a method (foo_SomethingHappened) and attached it to my handler for me. Thanks!

But this gets even better when you use Visual Studio 2012! Doing the same thing will get you this:

    public class SomeService
    {
        private Foo foo = new Foo();
        public SomeService()
        {
            foo.SomethingHappened += foo_SomethingHappened;
        }

        void foo_SomethingHappened(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
    }

 

OK, it isn’t thatdifferent. But the “new EventHandler” text is not there. It isn’t needed, of course so it rightfully isn’t there. I try to remove as much extra text from my code to make it more readable and I’m glad the Visual Studio team is thinking along the same lines. Actually, a lot of the time I clean this up even more by removing the object name from the event handler, in this case “foo_”. It might be needed sometimes, for clarity or, of course, if you need to specify which object the event is for. But in this case, I think it is just overly verbose. I prefer this:

    public class SomeService
    {
        private Foo foo = new Foo();
        public SomeService()
        {
            foo.SomethingHappened += SomethingHappened;
        }

        void SomethingHappened(object sender, EventArgs e)
        {
            throw new NotImplementedException();
        }
    }

I hope you find this tip helpful. To see more VS 2012 Tips, just click here.

Lately I’ve been speaking at local user groups about many of the exciting new features in Visual Studio 2012. Since there is so much to know and learn about VS 2012, I decided to create a collection of blog posts with many of the tips. This collection of posts will include features that are new to VS 2012 as well as some existing features as well. To view all of the VS 2012 tips posted so far, click here.

A lot has been made over the colors (or lack thereof) within Visual Studio 2012. I wrote a blog post about it back in May, 2012. While many parts of VS don’t have color, there is one item that had color added. Did you notice the status bar at the bottom of Visual Studio? Is it purple? Is it blue? Or is it orange? The answer is yes, yes and yes. It simply depends on what you are doing.

When you first open VS, the bar is purple. This indicated that you have no solution open.

image

After opening a solution, the bar will be blue.

image

And if you are in debug mode, the bar is orange.

image

If you are like me and often have multiple instances of VS open at once, you may find this useful!

 

I hope you find this tip helpful. To see more VS 2012 Tips, just click here.

ASP.Net Developers, it is time to change your attitude towards JavaScript. I know you hate it. I used to hate it too. But I’ve come to terms with JavaScript and now actually quite like it! It isn’t my favorite language but I’ve been working hard to understand this important client side technology.

Please don’t be offended by this post. I know I have lumped all ASP.Net developers into one category here. I know many of you are in the same place as I am, moving quickly towards understanding Javascript. I am, however, speaking to a large group of .Net web developers who have not yet started their journey. You know who you are.

I’m a C# MVP and, prior to this past summer, I spent 3 years doing Silverlight development. I truly believe that Microsoft was on to something with the concept of Silverlight. Like many developers, with regard to client side web development, I knew there had to be a better way to do things than JavaScript. Silverlight was a great attempt. It wasn’t perfect but the concept was good. Heck, I thought that anything that saved me from JavaScript was a good thing. I don’t care what anyone says, JavaScript is not the best solution to client side programing. I think we could have had better. Silverlight was a good try but people didn’t embrace it for various reasons (I won’t get into that in this post). Well here we are now and Silverlight is pretty much toast. It seems like Microsoft has thrown in the towel and isn’t trying to replace JavaScript and I doubt anyone else will pick up that fight.

For the past 8 months or so, I’ve been back doing “traditional” web development. I’m quite happy to be in the world of asp.net MVC with HTML, JavaScript, and CSS. In the past few years, a lot has changed. Three and a half years go, when I last did this sort of work as the main part of my job, jQuery was gaining a lot of traction and was becoming widely accepted. But not like it is today. Today, many developers incorrectly use the words JavaScript and jQuery interchangeably (which is actually quite annoying). And as great as jQuery is, there are a ton of other great JavaScript libraries to help us developers. Patterns like MVVM and SPA have gotten quite popular. And I’ve learned that there are some other great patterns that can be applied to JavaScript development that can make the experience much better, especially for a pattern-happy OO developer like me. So I have been reading up on and practicing using closures, the revealing module pattern, prototypes, MVVM, dependency injection, and more. And I haven’t even started with TypeScript which looks very interesting, to say the least. And I should also mention that products like Visual Studio (and many plugins too) have come a long way to finally embrace JavaScript and have started to treat it like a first class citizen.

In addition to the fact that doing client side development is much better these days thanks to frameworks and tooling, our users have come to expect a richer experience from web sites and applications. Users want web pages to be useable and responsive and, dare I say, “nice to use”. And so, fellow ASP.Net developers, the time for faking our way through JavaScript is over. I have put a lot of effort into learning more about JavaScript. I’ve started treating that part of my job as seriously as I do C#. I don’t expect that I’ll become some kind of JavaScript Ninja anytime soon, but I’ve realized that JavaScript enhanced UIs are an important part of my work. I’m giving JavaScript respect and I’ll expect other developers to do the same. No longer will I accept a job candidate’s dismissive answers about their knowledge of JavaScript. “Yeah, I can do a little JavaScript but I don’t like it” is no longer a valid answer to an interview question. JavaScript is an important aspect of our jobs as web developers and it isn’t going anywhere, at least not for a while.

I talk about this story a lot… few years ago in a team meeting the developers were complaining about their struggles in writing JavaScript which was becoming an important aspect of our web solution. Our manager, who is a really smart guy and still a friend of mine, asked a few questions that made a big impact on me. First he asked, “How many books have you guys read about C#?” The response varied across the team but we had all read a bunch of them. He followed that up with the knockout punch… “how many JavaScript books have you read?” The room was pretty quiet. Most of the group had read none. At least I had read one, but I was wasn’t much different than the group. JavaScript programming was part of our job but yet we didn’t take the time to learn it. And through my career I have found that most ASP.Net developer’s (myself included) experience with and towards JavaScript was pretty similar.

The age of treating JavaScript with disrespect is over. It’s a necessary part of our web solutions. And as I said earlier, the frameworks and tooling have gotten much better. So now is the time to learn it, embrace it, use it, and succeed with it.

 

Lately I’ve been speaking at local user groups about many of the exciting new features in Visual Studio 2012. Since there is so much to know and learn about VS 2012, I decided to create a collection of blog posts with many of the tips. This collection of posts will include features that are new to VS 2012 as well as some existing features as well. To view all of the VS 2012 tips posted so far, click here.

I love the little things that were added to VS 2012. The Image Preview is one of them. It’s one of those things that makes you wonder “That seems so simple, why wasn’t it there before.” But I’m not judging, I’m just glad it is here now. The feature is simple. When looking at a list of images that are included in your solution (in Solution Explorer, of course), just hover an image to get a preview of it. This can be a big time saver when you have a big set of icons that all have similar names.

image

I hope you find this tip helpful. To see more VS 2012 Tips, just click here.