Archive for Visual-Studio tag

Colour schemes for Visual Studio

October 2007 – April 2010 .NET (, ) • 87,029 views • 25 responses

The default syntax colour/color scheme in Visual Studio seems to be stuck in the 16-colour era so once you’ve found your perfect font you are going to need a great theme to go with it.

Here is the theme I’m currently using at home (currently on a 42″ 1900×1200 LCD TV until I can find space for my monitor) that a couple of people have asked for.

To to take full advantage of this theme you will need to download:

  • Envy Code R for the syntax font with the italics hack
  • PalmOS for the output window’s tiny text

Alternatively you could remap it to your coding font of choice (but you won’t get italics because of limitations within the Visual Studio IDE).

Screen shot of Envy Code R PR7 with HumaneStudio theme.

Download Humane Studio theme (2KB, 14 Oct 2007)

Head to Humane Studio at Studio Styles for VS 2010

To use simply unpack the zip file and go to Tools > Import and Export Settings from Visual Studio (2005 and later).

Humane is now available for TextMate & Xcode 3.

If this scheme doesn’t appeal to you then why not try:

[)amien

Refactoring shared libraries and public APIs

October 2007 .NET (, , ) • 848 views • no response

Refactoring is an essential process to keep code clean and elegant while it evolves. IDE’s offer common refactorings (although somewhat short of those prescribed in Fowler’s excellent Refactoring book and way short of the overall goals explained in Kerievsky’s Refactoring).

One limitation of existing tools is that they can only update references within your solution. When you are refactoring a shared library this is a problem, especially if it is your public API to the outside world.

We need to introduce metadata to document how the API has evolved and extend the tools to generate and understand this metadata.

Let’s take a look at a few of the refactoring in Visual Studio and see how they could be documented using the .NET metadata mechanism of choice, attributes.

Rename

Starting simple lets we had a property named Reference:

public string Reference {
  get { return id; }
}

We are going to rename Reference to StockCode for the 1.1.0.0 release. The tool could introduce a stub for backward compatibility whilst also marking it with metadata giving us:

[DeprecatedRefactorRename("StockCode", "1.1.0.0")]
public string Reference {
  get { return StockCode; }
}

public string StockCode {
  get { return id; }
}

The library is both binary and source compatible but with a little IDE work they could get a warning that Reference is now StockCode and given the choice of updating all the references in their project.

Nice. Let’s try a few more:

Remove Parameters

public bool AddStock(int quantity, DateTime arrival, StorageBin location) {
   ...
}

We are switching to a managed warehouse and so we no longer need to know where items are stored so we refactor and remove the StorageBin.

[DeprecatedParameterRemoved("location", "1.1.0.0.")]
public bool AddStock(int quantity, DateTime arrival, StorageBin location) {
   return AddStock(quantity, arrival);
}

public bool AddStock(int quantity, DateTime arrival) {
   ...
}

Reorder Parameters

[DeprecatedParametersReordered("arrival, quantity", "1.1.0.0.")]
public bool AddStock(int quantity, DateTime arrival) {
   return AddStock(arrival, quantity);
}

public bool AddStock(DateTime arrival, int quantity) {
   ...
}

Move Method

Existing tools offer little support for MoveMethod because they haven’t considered how to refactor the references. It is difficult to retain binary compatibility unless the class has a reference to class that now has the method we are interested in.

[DeprecatedMethodMoved("StockController", "Add", "1.1.0.0")]
public bool AddStock(DateTime arrival, int quantity) {
  return stockController.Add(this, arrival, quantity);
}

Let’s say the current calling code looks something like:

stockController.DoSomething();
selectedProduct.AddStock(DateTime.Now, input.Value);

However with a little ingenuity the IDE could examine the new method and map existing parameters based on name and type. If it still doesn’t have enough information consider local variables and properties of the objects it does have to present choices. This works especially well if your parameters are not primitives. Our code becomes:

stockController.DoSomething();
stockController.Add(selectedProduct, DateTime.Now, input.Value);

Keeping it clean

We don’t want our classes being cluttered with deprecated code indefinitely so the solution should contain two extra revision numbers, one detailing the oldest revision of attributes to keep in the source, the other for the oldest revision to compile into the binary. All the [Deprecated] marked methods and properties can slip into another file, perhaps Product.deprecated.cs so they stay out of sight until needed.

For .NET it would need somebody at Microsoft to take this on board and move us forward from ObsoleteAttribute as the facility should be cross-tool and so adding it solely to SharpDevelop would be of limited gain.

[)amien

Italic syntax highlighting in Visual Studio 2005

July 2007 – March 2008 .NET (, , , , ) • 4,573 views • 7 responses

I came across a posting by Thomas Restrepo about a theme for Vim he likes called Wombat and how it wouldn’t be worth porting to Visual Studio as it doesn’t support italic syntax highlighting – as we all know.

This got me thinking and I was able to port it with italics although the process is a bit of a hack.

If I can figure out a way of making this hack re-distributable without infringing on copyrights I’ll follow this one up.

In the meantime here’s a screen-shot of it in action using Consolas.

Visual Studio 2005 with italics

I can’t stand using vim for .NET – I’ve got better things to do than commit the entire .NET Framework to memory. I remember watching a WPF screen-cast where the guy was using “his trusty editor” (vim or emacs – I forget ;-) and going on about the great keyboard short-cuts whilst constantly trying different method names, compiling yet again and finally looking up help in the absence of IntelliSense.

I did however check out the latest trunk of SharpDevelop this weekend and was quite impressed with both the product and the source code. There was a bit of flickering with the solution explorer and the icons seem to be a bit of a steal-and-mash but otherwise looks first class.

[)amien

AnkhSVN and Visual Studio 2007/2008/Orcas

June 2007 – October 2009 .NET (, , ) • 7,664 views • 13 responses

A newer registry file is available to provide AnkhSVN with Visual Studio 2008 and Vista support in one.

If you are using Visual Studio 2007/2008/Orcas/9.0 you will have found that AnkhSVN 1.01 doesn’t appear in the IDE.

Like many Visual Studio add-ins AnkhSVN should work just fine but won’t appear because the installer does not write an entry for it in the 9.0 section of the registry.

In this case the specific branches are:

32-bit HKEY_LOCAL_MACHINE\SOFTWARE\Microsoft\VisualStudio\8.0\AddIns\Ankh
64-bit HKEY_LOCAL_MACHINE\SOFTWARE\Wow6432Node\Microsoft\VisualStudio\8.0\AddIns\Ankh

All we need to do is export that section out, change the 8.0 to 9.0 and then run it back into the registry.

This technique should work for any other add-in’s you have that are only appearing in 2005.

If you installed AnkhSVN into the default folder try these registry files I have prepared for 32-bit or 64-bit machines.

[)amien