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.

 

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.

This features, as well as a lot of the cool features of VS 2012’s Solution Explorer, was carried forward from a tool called the Solution Navigator that was available as an add-on in VS 2010 as part of the VS Productivity Power Tools download. It was a good feature then but it is even better now.

image

You can see the Solution Explorer in the screenshot showing the Controllers folder and the two source files it contains: AccountController.cs and HomeController.cs. But note the icon that indicates you can drill down further.

 

image

Now you can see that the Solution Explorer is capable of displaying quite a bit more information. You can see all of the class level variables (a private field named _foo and a public property named Foo) as well as a bunch of methods. You can also see the details of two nested classes. Of course, clicking on any of the items will bring up the file location on the code editor. These details can be combined with other features within the Solution Navigator. If you want to see how to search through the class level details, please check out my blog post on that topic. If you want, you can also change the scope of Solution Explorer down to these class level details. For details, please read my post on that topic as well.

 

 

 

 

 

 

 

 

 

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 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.