Showing posts with label Visual Studio. Show all posts
Showing posts with label Visual Studio. Show all posts

Wednesday, October 21, 2009

Visual Studio 2010 Beta 2

If you have yet heard, Microsoft has release beta 2 of Visual Studio 2010. It’s currently available to MSDN Subscribers and will be available to the general public sometime today. The final release of VS2010 is currently scheduled for March 22nd, 2010. You can get more information and look out for the public download at MSDN:

http://msdn.microsoft.com/en-us/vstudio/dd582936.aspx

Microsoft has also released a Visual Studio 2010 training kit which contains presentations, hands-on labs and demos to get you up to speed with this new release.

Sunday, July 12, 2009

VS 2010 Generate From Usage

Microsoft has been adding more and more features to Visual Studio to encourage Test Driven Development. One of the new features in VS2010 for TDD is “Generate From Usage.”
One of the tenants of true test driven development is that you should write your unit tests before you write your code. One little tricky part of this in Visual Studio is that you loose the help of IntelliSense and sometimes it will even get in your way. To get around this problem, developers will often stub out their classes and methods first, and then write their tests. Generate From Usage in VS2010 provides another way to do this.
To try this out we will create a very simple math class called MyMath that has one method call Add(n1,n2) that will add two numbers together and return the result. First create a solution with a new C# Test Project and C# Class Library Project. In the TestMethod1 method of the UnitTest1 class type the following code (type it instead of cutting and pasting to see the full effect of this feature):
MyMath math = new MyMath();
Assert.AreEqual(3,math.Add(1, 2));
First thing you will notice is that when you type “new” and press the space bar, IntelliSense will popup and you will see the MyMath class on the list even though we haven’t defined it yet. The editor figures out that you are intending to create a class called MyMath so it puts in on the list.
As expected you will get red squiggles under MyMath since it doesn’t exist yet. At this point you would normally go and manually stub out this class, but Generate From Usage makes this easier. If you right click on MyMath and select Generate/Class, Visual Studio will automatically create a new stub for the MyMath class. By default it will put the new class in the test project which is probably not where you want it. To get around this instead of clicking Generate/Class, use Generate/Other…, this will pop-up this dialog box:


This give you more control over the generation of the code. In the location section you can change the project so that the new file goes to the Class Library project. Now if you build the solution the squiggles under MyMath will go away and the Add function will be flagged instead.
Now you can right-click on Add and select Generate/Method Sub and this will generate a method stub in the MyMath class. In this case there is no Other option since there really aren’t any other options for creating the Method since to be usable it must be in the MyMath class, must be public and must be called Add.
There is one tricky thing with this feature that I will demonstrate with another example. Let’s say we want to create a new class called Host. In TestMethod1 type Host and press the space bar. When you do this IntelliSense will try to be helpful. Since there isn’t a class called Host in the default namespaces it will put in something that is there; HostTypeAttribute. This is not what we wanted. To get around this there is a new feature in IntelliSense called Consume-First Mode. When the IntelliSense box pops up press Ctrl+Alt+Space to toggle to consume-first mode. In this mode instead of forcing you into a class that already exists it will just accept what you typed when you press the space bar. Once this mode is turned on it will stay in this mode until you press Ctrl+Alt+Space again while an IntelliSense window is open.

Sunday, June 28, 2009

IntelliSense Transparency

While I was playing with Visual Studio 2010 I ran across a cool little feature that I assumed was new to the VS2010 editor but turns out to also be available in VS2008. When an IntelliSense window opens there are times when you need to quickly see something that is underneath it. To do this all you have to do is press and hold the CTRL key. This will cause the window to become transparent until you release the key again:

clip_image002

Monday, June 1, 2009

Visual Studio 2010 Editor

One of the biggest changes in Visual Studio 2010 is the text editor. When you first fire it up you will definitely notice a lot of small visual changes to it but the biggest changes are under the hood. The editor has been re-written in C# using WPF for the presentation layer, and Microsoft’s new Managed Extensibility Framework (MEF) to make the editor much more extensible.

Here are a couple of the nice new features found in the editor. Visual Studio has always had the little plus and minus boxes on the left side of the editor which allows you to expand and collapse blocks of code. In VS 2010 there is an addition to this. If you hover over one of the minus boxes VS will highlight all the code in that block.

VS2010Editor1

Another similar feature works with identifiers like variable names. If you hover your mouse over a variable in a class or function VS will automatically highlight all the other instances of that identifier. This is a handy way to quickly see where you variable is used.

VS2010Editor2

Finally, VS 2010 has a build in code zooming feature. If you hold the CTRL key and roll the mouse wheel you can increase and decrease the font size in the code window. This is not a feature you are likely to use in your day to day work, but it is very handy when you are doing technical presentations and the audience is having a hard time seeing the code.

None of the features is earth shattering, but I think the real promise of the new editor will come from it’s extensibility model. Once third party developers start taking advantage of this I think we will see a lot of very cool add-ons to the editor.

If you want to learn more about the editor check out the Hanselminutes podcast #147 where Scott interviews Noah Richards who is one of the developers of the new editor.

Saturday, May 23, 2009

Visual Studio 2010 Beta

Microsoft has just released the beta of Visual Studio 2010 to the general public. You can download and get more information here, http://www.microsoft.com/visualstudio/en-us/products/2010/default.mspx. Note that the first install link on this page is for the web installer, but you can click on “See More Download Options” to download the ISO version.

I’ve installed it without any problems on both Windows 7 RC1 and Windows XP. If you install on Windows 7 there is a compatibility problem with the version of SQL Server that installs with Visual Studio, but Microsoft provides a workaround.

So far I have been pretty happy with the beta. The changes from 2008 are not dramatic but there are definitely some nice new features. The biggest changes you will notice are in the code editor which has been completely re-written. There have also been a few small language changes to C# and VB.NET but no where near as many as were introduced in 2008.

2010 provides support out of the box for things like Silverlight, and the F# language. These are available in 2008 but have to be installed separately. You may notice that ASP.NET MVC Framework is NOT included in this beta. According to Phil Haacked the release of MVC was to late to be included in Beta 1 but will be included in the next beta.

As I work with 2010 some more I will be posting about some of the new features.