This weekend I had time to sit down and really look at Visual Studio 2008 Beta 2. This entry will cover how to build a Compact Framework 3.5 application using VS2008. At the same time it will give a brief tour of VS2008.
Tour
When you first open Visual Studio 2008 it looks like previous versions. You have the menu at the top with movable toolbars below it. Then in between the standard tool windows you have a tab with Start Page displayed. There is one thing that is different if you are running Vista. Even with User Account Control turned on, VS no longer prompts to run VS. Yeah!
Next I fired up a new project and got what one would expect the new Project Window. However there are a lot more project types.
- Under C# Projects (my primary language) you have several categories
- Windows contains templates for creating tradition Windows applications, libraries and controls. In addition their are templates for creating Windows Presentation Foundation applications, libraries and controls. Finally there are templates for building report applications and Windows services.
- Web contains templates for creating ASP.Net sites and controls. In addition new templates are included for building AJAX based sites and controls. Finally this category contains templates for building Web Services both the old ASP.Net services and the newer WCF style services.
- Office contains templates for building both Office 2007 and Office 2003 addins and Sharepoint workflows.
- Smart Device contains a new wizard for building Compact Framework applications.
- Database contains templates for building database scripts for MS SQL 2000 and MS SQL 2005.
- Test contains a template for creating unit tests using VS2008 unit test tools. This includes unit tests, code coverage and code analysis
- WCF aka Windows Communication Foundation contains templates for building WCF services and even workflow based services.
- Workflow contains templates for building workflow based applications using Windows Workflow Foundation.
- Database Projects contains templates for creating CLR based stored procedures for MS SQL.
- Other languages has the same project types and classifications as your primary but holds other languages like Visual Basic and C++.
- Distributed System contains project templates for using the visual architect tools introduced in VS2005 to build and deploy distributed systems.
- The Other Project Types contains projects templates that do not fall under the other ones.
- Setup and Deployment contains templates for building setup applications including application, web and smart device installations.
- Database contains a template for building MS SQL scripts.
- Extensibility contains templates for creating Visual Studio addins and Office addins.
- Visual Studio Solution contains the blank solution template.
- Test Projects for creating unit tests using VS2008 unit test tools. This includes unit tests, code coverage and code analysis.
Since my focus is on mobile applications I decide to start by building a device application. So I selected Smart Device Project. This launches a new wizard that helps to setup a project give the numerous combination of target platform, framework and type of project.
I decided to choice building a Windows Mobile 6 Professional application using the new Compact Framework 3.5. I then hit finished and was rewarded with the usual Form1 and project items.
Code Metrics
Poking around on the context menu yields a new menu item "Generate Code Metrics". Clicking "Generate Code Metrics" gives you a new Window on the bottom that contains 5 code metrics, http://blogs.msdn.com/fxcop/archive/2007/02/28/announcing-visual-studio-code-metrics.aspx. The metrics are grouped by project, namespace, class and method or property. This allows you to drill down into the metrics. There is even a button for exporting to Excel. The five metrics are
- Maintainability Index - a derivative of the Halstead Complexity Measure. The metric tries to gauge from code the complexity and thus the maintainability of the code. It is averaged as you move up the hierarchy.
- Cyclomatic Complexity - measures the number of paths through the code.
- Depth of Inheritance - measures how far down a class is in the inheritance tree. It is the maximum level as you go up the hierarchy.
- Class Coupling - the number of types referenced at the method and class level. It is summed up as you go up the hierarchy.
- Lines of Code - this is the number of lines of code. It is summed up as you go up the hierarchy.
Unit Testing
VS2008 is suppose to now allow for creating unit tests for the Compact Framework. So I decided to build a UI that had two edit boxes and a label. Then when the menu item is clicked a method would be called that would add the contents of the two edit boxes. So step one was to write the method for the addition.
public int Calculate(int x, int y) { return x + y; }
Next I right clicked to bring up the context menu within the editor. I then selected "Create Unit Test...". This launched a wizard for creating a unit test project. Yeah now you can unit test CF code!
Clicking OK not only created a test project but also a good start at the actual unit test for the selected method. With very little effort I modified the test and ran the test. I was rewarded with the emulator popping up and the test window displaying. Unfortunately, the test of the method failed with a type load exception. Since I had not deployed the project I was testing the type could not be loaded. I deployed project and ran the tests again. This time it yielded a successful test run!
///<summary> /// A test for Calculate ///</summary> [TestMethod()] public void CalculateTest() { Form1 target = new Form1(); // TODO: Initialize to an appropriate value int x = 0; // TODO: Initialize to an appropriate value int y = 0; // TODO: Initialize to an appropriate value int expected = 0; // TODO: Initialize to an appropriate value int actual; actual = target.Calculate(x, y); Assert.AreEqual(expected, actual); Assert.Inconclusive("Verify the correctness of this test method."); }
Conclusion
VS2008 is worth purchasing when it comes out. It gives developers writing Compact Framework applications a much improved development environment. In addition you do not have to migrate your applications to CF3.5. The one downside is if you maintain CF1.0 applications. Then if you wish to take advantage of the new features you will need to migrate to at least CF2.0.
Comments