Posts Tagged ‘vstudio’

VSMDI Normalizer

Thursday, February 11th, 2010

Have you noticed that your Visual Studio test lists always seem to get re-ordered? Make sense of this randomness with the VSMDI Normalizer.

It works by sorting your test lists and tests by name, creating a consistent ordering, allowing better merging and comparison of test lists. It’s a command line tool so it can integrate with automated processes really well.

It works in two modes:

  1. Target Mode: Specify the VSMDI file as the first argument and the target output file as the second. If the target exists it will be overwritten. This is ideal if not everyone is using VSMDI Normalizer. Some file comparison tools accept external converter tools (such as Beyond Compare).
  2. In Place Mode: The VSMDI file will be normalized in place. This would be a good operation to run prior to check in. Just specify the VSMDI file as the first and only argument at the command line.

Download VSMDI Normalizer Now (~13K)

For support, visit http://www.i-think22.net/support/

VSMDI Normalizer is free for personal and commercial use. It comes with no warranty, explicit or implicit.

To use VSMDI Normalizer with Beyond Compare:

  1. Open Beyond Compare
  2. Select Tools > File Formats
  3. Click New
  4. Enter *.vsmdi as the mask
  5. In the Conversion Tab, select “External program (Unicode filenames)”.
  6. Browse for the VSMDI Normalizer tool (for the Loading field).
  7. Append the following to the Loading path: ” %s %t” (without the quotes).
  8. Check Disable editing
  9. Click Save and Close

Visual Studio, .NET and Developer Productivity

Sunday, February 22nd, 2009

Recently I’ve had to work on porting a .NET app to Ruby. The .NET version consumed WCF web services, exposed WCF web services, parsed XML and relied on multiple threads. The experience reminded me of one thing: the awesomeness of .NET and Visual Studio.

.NET’s documentation is pervasive

.NET seems to have been designed from the start to encourage excellent documentation. With XML documentation all the important parts of a method and a class are able to be encapsulated. Using a tool like GhostDoc (which is free) a skeleton for the documentation can be written for you.

In Visual Studio as you code you are constantly presented with relevant documentation as you code. If you need more help you can press F1 to be taken to the relevant page from the MSDN library.

The .NET Framework is generally well laid out

I’m sure someone can come up with an exception, but generally the .NET framework is well laid out. IO functions can be found in System.IO, Windows form controls sit in System.Windows.Forms. Knowing where to look for things goes a long way to improving the discovery of methods and types leading to a less steep learning curve.

It also serves well for discussions. If you want to working with XML you can be told to check the classes in System.Xml. Want to check out the new LINQ to XML classes, they are sitting in System.Xml.Linq, right under the System.Xml namespace.

The .NET Framework has consistent naming

Classes and method names have consistent case rules that make it easy to work in a case-sensitive environment. Consistent use of prefixes (like ‘I’ for Interface) and suffixes (like ‘Exception’ for exceptions) helps developers identify the purpose of a class without looking deeper. Fortunately Visual Studio makes looking deeper easy. Design guidelines for developing class libraries encourage developers to stick with this consistent approach. Furthermore, tools like StyleCop and FxCop can help make sure your code is consistent.

Even the basic documentation is good

The class documentation on MSDN is generally excellent, but even at its core, just listing the members, constructor overloads and object hierarchy goes a long way to understanding a complex framework. It is well organised (using the namespaces we’ve already discussed) and easy to navigate.

Working with Ruby’s documentation really made this apparent. Whilst the ruby docs can have this information I have seen members not listed in documentation, and the three top panes are almost impossible to navigate (from left to right, a list of source files, a list of all classes and modules, and then a list of all members). These lists get so long that it is difficult to scroll to the right spot and even then it can be hard to pick the item you want.

Visual Studio makes it easy to navigate your code

Enterprise applications are large, so being able to navigate through your own code needs to be as quick and easy as possible. In Visual Studio it is easy to navigate to the declaration of a type or a method. In addition to Visual Studio’s navigation features I also make use of ReSharper (not free, but so worth it) to navigate to a member, a particular file, references, etc. This ease of navigation improves my productivity greatly.

Did I mention how much I love IntelliSense?

Seriously, IntelliSense is the greatest IDE feature ever. It improves the discoverability of classes and methods and reduces errors in code. ReSharper has a handy feature which let’s me take advantage of camel casing too. I can type ‘ArgN’ and still be presented with the option of an ArgumentNullException. This has saved me a lot of time I would normally spend using the dreaded cursor keys to select the type I want.

Simple refactoring made easy

Changing the name of a method or type in Visual Studio is simple. References can be updated to reflect the change. Making a change like this by hand is time consuming and prone to error. Again, tools like ReSharper can take this further.

The joy of compilation

Compilers are awesome. Not only do they now do a lot of type inference magic, but they can help identify many of the common little problems that arise in code such as minor typos, invalid syntax and undeclared variables. The C# compiler generally returns good error messages that help identify problems quickly. Some of the errors I saw while running my Ruby port were reasonable and certainly allowed me to solve the problem, but often I would need to go deep into the code before these problems become evident. I needed to make thorough use of unit tests just to be confident that the code was syntactically valid.

Too much hand holding?

My experience with Ruby has certainly highlighted my reliance on tools like Visual Studio to help me write my code. At the same time I recognised that I was making fewer errors over time writing all my code in a text editor. Perhaps it is beneficial to code in a text editor from time to time, but for anything with more than a few methods or classes you won’t see me giving up Visual Studio (and ReSharper) any time soon.

Getting Started with LINQ

Saturday, February 14th, 2009

I really like LINQ. It’s one of my favourite .NET features. When I first heard about it I was doing most of my programming in Visual Basic 6 (or worse, Visual Basic for Applications). Working now with C# and the .NET Framework has blessed me with full O-O, strong types, an excellent base class library, Visual Studio 2008 (and IntelliSense), Generics (I love generics) and LINQ.

So what is LINQ and why is it so important to add to your arsenal of .NET skills?

LINQ is so many things

At its core LINQ is exactly what its acronym suggests: Language Integrated Query. But what does this actually mean? Is it just some marketing hype designed to confuse the masses and look good on your resume. Probably. But the value of expressing a query concisely in the language of your choice becomes more apparent with each LINQ query you write. (Yes, I know LINQ Query would stand for Language Integrated Query query. Just go with it, it reads better.)

Importantly a LINQ query separates defining what you are looking for from how to find it. This means that a LINQ query could potentially be executed across multiple CPU cores and in the case of LINQ to SQL can be turned into an efficient SQL query so the hard work can be done by your database server.

But when are you going to actually use LINQ? Chances are good that you already have some code that could benefit from a bit of LINQ.

Take this example:

var itemsUnderOneDollar = new List<Item>();
foreach (var item in items)
{
   if (item.Price < 1)
   {
      itemsUnderOneDollar.Add(item);
   }
}

In this case we want to find all items that are under one dollar. The same in LINQ would be:

var itemsUnderOneDollar = (from item in items
                           where item.Price < 1
                           select item).ToList();

We can ignore the variable declaration for now (and the call to ToList()) so let’s break it down to just the core LINQ query.

from item in items
where item.Price < 1
select item

The LINQ query describes exactly what you want and nothing more. When we used the foreach construct we were resigned to the fact that we had to look at each and every item. We are also doing all this in a single thread. In fact, we spend more time describing how we want to find the items than saying what it is that we want. By describing what we want using LINQ we don’t bother with the implementation details resulting in cleaner code and improved flexibility for how the query should be implemented. In the case of a database query, the ideal implementation would be to generate a SQL query, execute the SQL query against the database and return the results. LINQ to SQL does just that with essentially the same code (I’ll be discussing LINQ to SQL in depth in another post).

From Where Select vs. Select From Where

If you are already familiar with SQL you may be a little confused by the syntax of a LINQ query. Indeed this is a major stumbling block most people encounter when they start to use LINQ. In SQL we have the ‘select’ statement upfront but in LINQ we save it for the end. Why? The primary reason for this choice was to enable great IntelliSense support in Visual Studio.

I’d like to argue that the syntax in LINQ actually makes more sense. Rather than starting with what we want at the end we start with the subject of our query. The reason this seems so foreign is that we are so used to it because of SQL. When you write code you typically say where you want to look before you say what you want to do when you’ve found it. In natural language it is like saying “From the store find a computer with 2GiB RAM and get me the price of the computer”. In SQL speak that would be “Get the price of the computer in the store where that computer has 2GiB RAM”. You tell me which form you’d be more likely to use.

The magic of type inference

Another convenient way to remember that from comes first is to think of the old foreach implementation. You’ll find that they have a lot in common. The biggest difference is that in the foreach loop we have to explicitly specify a type. In the example above I’ve used var to let the compiler infer the type. In the LINQ query the type is inferred automatically unless you specify it explicitly.

Type inference is used throughout most LINQ usage to simplify code and to improve maintainability. Queries return an object that implements the IEnumerable<T> interface. More advanced queries can return objects that implement a more complex interface (which is also an IEnumerable<T>). By using var to let the compiler infer the type of object returned by the query it saves the programmer from having to explicitly work out what type of object is returned. The full significance of this will become apparent in future posts.

How to get started

The best way to get started working with LINQ is to read up about it on MSDN. Then download the great tool LINQPad. LINQPad has some great sample LINQ queries and lets you play with LINQ outside of Visual Studio. It’s great for writing short snippets of code and is an ideal sandbox to try out bits of code. LINQPad is free, but Auto Completion is a paid feature (but well worth it). It also lets you run LINQ to SQL queries on a SQL database (and now SQL Compact Edition).

Once you have started familiarising yourself with LINQ you should start using it in your projects. There are two key requirements to using LINQ:

  1. Your project must target version 3.5 of the .NET Framework.
  2. You must include using System.Linq; to reference the LINQ namespace in all code files where you want to use LINQ.

If you don’t have Visual Studio 2008 you can download one of the free express editions from http://www.microsoft.com/express/. Once installed you might also want to turn on line numbers in Visual C# Express.

More to come

There’s plenty of stuff to talk about with LINQ. In my next few posts I’ll cover Extensions methods, Lambda expressions, LINQ over objects and much more.

Vista’s point of maturity

Sunday, November 30th, 2008

There’s been a lot of bad press about Windows Vista. Some of it warranted, but a lot of it seems to be just jumping on the Anti-Vista bandwagon. Let’s face it, there is a large (or perhaps just vocal) community out there that automatically dislikes anything coming out of Microsoft. Within this community it is “cool”.

I admit that I’ve been drawn to Linux in the past and I believe Linux does indeed have its place, but in the current form (and all the directions I’ve seen) I would never recommend it for general use by the community (both technical and non-technical) and would absolutely recommend against it in an enterprise environment (unless of course there were some very specific needs that Linux met better).

Working with the .NET Framework over the past 12 months I have been amazed by its richness and power. I love .NET’s generics implementation, a feature whose need becomes evident very quickly. But most importantly I have been impressed with the tools. Visual Studio 2008, IntelliSense and the MSDN library help bring joy to the activity of development. Perhaps even more importantly, they provide the opportunity to expand knowledge rapidly.

Best of all is that Microsoft is not standing still. They are rapidly advancing the .NET framework and working on new exciting developer and testing tools that will be part of Visual Studio 2010.

Microsoft has recognised its mistakes with Internet Explorer and has done incredible work with Internet Explorer 8. Bringing standards compliance to the Internet’s most dominant web browser is no mean feat and to achieve it with minimal disruption will be an outstanding achievement. I am confident that Microsoft will be able to do this and we will see more innovation in the web browser industry.

Two weeks ago I bought an Xbox 360 of my very own and have been absolutely thrilled with the console, the games and the recent improvements to the Xbox dashboard (including the ability for me to finally run my Xbox at my monitor’s native 1680 x 1050 resolution). The Xbox 360 controller is a huge improvement on the original and far friendlier on the hands than its Playstation counterpart.

Microsoft’s mice are among the most comfortable that I’ve used. Sure, they’ve had a few that don’t quite meet the mark, but I’ve been generally impressed with Microsoft’s mice for over ten years.

Then there is Microsoft Office. The 2007 release was a risky endeavour with the new ribbon UI. An interface that I feel has worked to improve most regular operations. Still, I accept that such a massive shift can be frightening for users, although not having to trawl through menu screens may provide some compensation. The ribbon UI was the most prominent new feature of Office 2007 which unfortunately overshadowed some of the great improvements to the templates which finally made it easy to create great looking documents.

And finally back to Windows Vista. Drivers were always going to be an issue, but by now this has been addressed and those manufacturer’s that haven’t updated their drivers are probably not worth dealing with (ignoring legacy hardware). User Account Control (UAC) is arguably not as big a problem as is suggested. Sure, IT professional’s are constantly tinkering with the innards of Windows, but an extra warning when I install software is perfectly acceptable. Indeed once a computer has been set up, these prompts are rare to non-existant unless you find yourself downloading software often (which is arguably a high level action anyway).

All up I’m quite happy with Windows Vista and have realised that sometime in the past six months I have shifted from being hesitant to recommend it to being confident in making the recommendation. I’m not suggesting that everyone should rush out an upgrade (most people that should probably have), but if you are buying a new computer, go with Windows Vista.

And while we’re on the subject, make sure your new system is ready for Windows 7. I can’t wait.

Adding WPF Windows to an existing Windows Form Project

Tuesday, August 5th, 2008

I’ve been recently reading Essential Windows Presentation Foundation (Chris Anderson) and I have been really looking forward to being able to create some funky WPF apps. I’ve almost finished (except for the sudden scope creep) a utility that I’ve been writing using Windows Forms. Like most good utilities it sits in the system tray just waiting to be used.

While using this tool yesterday I realised that I was being driven crazy by its need for interaction by the mouse. So I decided to create a global shortcut key and that would open a little navigation window to help you select the item you wanted (this is just some of the aforementioned scope creep).

I knew straight away that this was a job perfectly suited for WPF. So, I opened up the Add New Item dialog in Visual Studio 2008, selected WPF and was greeted with one solitary option:
Add New Item (WPF)

Unfortunately when you have a Windows Form project, User Control (WPF) is the only choice you are given. Fortunately, there is a workaround, but let’s first look at some reasons why mixing WPF into a windows form application might not be the best idea:

  • Consistent appearance is the first reason that comes to mind. WPF windows look just a little different to Windows Forms (with default settings) and even more different if you apply all the fancy styling options. Of course, if you are looking to create a window with a distinct look, this doesn’t apply
  • Maintainable code is another reason. Supporting multiple types of windowing increases the complexity of your project

There may be others and hopefully someone will point them out in the comments.

But now back to adding a WPF window into your Windows Forms project. Without the Window option, begrudgingly select User Control (WPF). Visual Studio then adds all the necessary references to your project and create a new XAML file and a corresponding CS file (or VB if you are that way inclined).

It turns out that User controls and Windows are very similar, so in your XAML file, change the “UserControl” tag to “Window” (remember to also update the closing tag). Your XAML should now look something like this:


<window x:Class="MyProject.UserControl1"
   xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
   xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
   Height="300" Width="300">
   <grid>

   </grid>
</window>

Finally update your code file to remove the UserControl inheritance. (It’s already defined in your XAML anyway).

///

/// Interaction logic for UserControl1.xaml
/// 

public partial class UserControl1
{
    public UserControl1()
    {
        InitializeComponent();
    }
}

Then you can play with the WPF window as you would expect.