I recently had a request from a client for an application that could be distributed and run from a USB memory stick. I wrote it in .NET of course, but some of the target machines don’t have the .NET framework installed (it’s getting more common, but it’s not ubiquitous yet).
This wouldn’t have been a problem if we were installing the application because the installer would have taken care of that for me, but because it was designed to run from the USB memory stick I needed to write a bootstrap that could detect if .NET was installed; if it was installed go straight into the program, if not ask the user if they want to install it (from the installer on the USB memory stick).
Not having the skills to write a C++ bootstrap I had to look elsewhere for a solution, and what I came up with was an HTML application. Basically, a HTML Application is a web page that has its extension changed to .hta, but because it is running from the local machine it has a higher security level that a web page would, meaning I can write a JavaScript function like this:
function launchApp(app)
{
var wsh = new ActiveXObject("WScript.Shell");
wsh.run(app);
}
Add to that the fact that the version numbers of installed .NET frameworks are included in the user agent string, and I can write code like this to detect if the correct version of .NET is installed:
if (navigator.userAgent.indexOf(".NET CLR 3.5.") > -1)
And as I final bonus, it’s a web page so I can layout an information page about the product, with images, that is displayed if .NET isn’t installed.
I’ve never used HTML applications before, but even thought it’s an old technology I think it has some life in it yet. I’ll certainly think about it in future if I need a small app but can’t rely on the .NET framework being installed.
The Bluffer's Guide to C# 3.0 is an article that highlights most of the important new features in C# 3.0 with some key information about them. If you're a C# 2.0 dev this guide will allow you to fake it if you're ever quized about C# 3.0, although I think it is probably more useful as a list of things you should off and find out more about!
One of the many new features Microsoft is planning to bring to .NET 4.0 is Code Contracts. In a nutshell, this is a feature that allow a developer to formally specify the requirements of a function, and the state of the system when the function completes (e.g. A parameter will be non-null, or a property of the object will be greater than 0 at the end of the function). The initial work for this came from the Spec# project, a Microsoft Research project that extended the C# language to include keywords for specifying the contracts, but it looks like .NET 4.0 will include the features in the form of framework methods, for example:
void DoSomething(int parameter)
{
CodeContract.Requires(parameter >= 0);
}
I think this will be a great feature, but it seems to me that it would be better expressed as metadata using attributes rather than in the function body itself. I guess we will just have to wait and see what the community reaction is to this feature, and how it ends up being implemented in the release version!
I'm also interested to see how this will work with Dynamic Data, an ASP.NET feature that already uses metadata on LINQ classes to specify constrains which are used to generate validators in the UI. This seems like a perfect way to specify those constrains.