April 21, 2008
TFS Build API by Example #1: Queue a build.
As we all know by now - the build system in TFS2008 was substantially improved. Along with the many improvements came an official API for talking to the build system. This is the same API that the Team Foundation Build UI in Visual Studio uses, however there are many additional methods that were added that were not for the UI at all but for potential consumers of the Build API.
In talking with folks at community events, and on the MSDN forums I have realized that there isn't a huge awareness of this API. Having written a parallel implementation of the build API, but in Java for the Teamprise 3.0 release I have spent a great deal of time with the .NET API and have a few examples lying around of how to accomplish certain common tasks - so I thought I would run through a some of them. If you have an example of something you would like to see with the build API then please leave a comment for this post or drop me a line.
So - let's start with a basic one. How to queue a build. This will introduce us to a few concepts with-in the build API that are common across all of the methods.
The Easy Way.
A quick look at the class diagram above will show you that the main interfaces you'll be dealing with in the Build API are the IBuildServer and IBuildDefinition interfaces. To get started with these you'll need to add references to the Microsoft.TeamFoundation.dll, Microsoft.TeamFoundation.Client.dll and Microsoft.TeamFoundation.Build.Client.dll.
C#
TeamFoundationServer tfs = TeamFoundationServerFactory.GetServer("http://tfsserver:8080”); IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer)); IBuildDefinition buildDef = buildServer.GetBuildDefinition("TeamProject", "Build Name"); buildServer.QueueBuild(buildDef);
VB.NET
Dim tfs As TeamFoundationServer = TeamFoundationServerFactory.GetServer("http://tfsserver:8080") Dim buildServer As IBuildServer = DirectCast(tfs.GetService(GetType(IBuildServer)), IBuildServer) Dim buildDef As IBuildDefinition = buildServer.GetBuildDefinition("TeamProject", “Build Name") buildServer.QueueBuild(buildDef)
I'm afraid that's the last example you'll be seeing in VB.NET. Being a Java developer by day I tend to like my semi-colons. However if you are a VB developer then hopefully you'll be able to follow along as the rest of the examples are more or less just method calls with the occasional bit of casting.
So - what's going on here. Well we first get hold of a TeamFoundationServer object. If this was server side code and we wanted to specify some credentials then we would use a slightly difference mechanism but in this case the constructor works well and this will automatically connect using the credentials of the current thread.
Next we get hold of the build service that implements the IBuildServer interface. Finally we get a hold of the build definition by specifying a team project and build definition name (build definitions are unique per team project in TFS). We then queue a build using the defaults for that build definition. This API call is actually shorthand for the following...
The Hard Way
Supposed you want to queue a build, but you don't want to use the default build agent, priority, drop location etc. Well in that case you need to look at the IBuildRequest interface. Here you will find all the options to customize the build request, you can specify a build agent, drop location, priority etc like you can do from the Visual Studio UI. You will also find other options such as being able to queue the build with a maximum acceptable queue position, pass a custom get version for the build or even queue the build in a postponed status.
In the following example, I am going to find a non-default build agent from the server and then queue a build using it.
TeamFoundationServer tfs = new TeamFoundationServer("http://tfsserver:8080");
IBuildServer buildServer = (IBuildServer)tfs.GetService(typeof(IBuildServer));
String teamProject = "TeamProject";
String buildDefinitionName = "MyBuildDefinition";
String buildAgentName = "MyBuildAgent";
// Find our (non default) build agent.
IBuildAgentQueryResult queryResult = buildServer.QueryBuildAgents(buildServer.CreateBuildAgentSpec(teamProject, buildAgentName));
if (queryResult.Failures.Length > 0 || queryResult.Agents.Length != 1)
{
throw new Exception("Invalid Build Agent");
}
IBuildAgent buildAgent = queryResult.Agents[0];
IBuildDefinition buildDefinition = buildServer.GetBuildDefinition(teamProject,buildDefinitionName);
// Create a build request based on our chosen definition.
IBuildRequest buildRequest = buildDefinition.CreateBuildRequest();
// Optionally set command line args, drop location, priority, custom source version etc here
// in this case just overriding default build agent.
buildRequest.BuildAgent = buildAgent;
buildServer.QueueBuild(buildRequest);
Pretty simple really and very powerful. I encourage you to go take a look at the IBuildServer interface to see some of the stuff that you can do. If you have any suggestions as to what you would like to see as a build API example then leave a comment to this post.
March 13, 2008
CodePlex Project Stats
The fantastic team at CodePlex have just rolled out yet another great feature - this time it is statistics for your CodePlex project. I dropped by my TFS Plug-in for CruiseControl.NET to take a look...
The project is currently averaging over 12 downloads a day and has had nearly 5000 downloads since I moved it to CodePlex in August 2006. Not bad for a chunk of code I originally wrote on a plane..
This is incredibly motivating as a maintainer of an Open Source project. I've been knowing that I need to give the CC.NET integration some love as there are a few issues and things that I need to address from the excellent feedback I have been receiving. However - seeing how many people are still interested in the plug-in despite the excellent CI functionality in the 2008 release of TFS has made me realise that I need to get on this ASAP. Thanks CodePlex!
February 21, 2008
DDD is coming to Ireland
Developer Developer Developer is coming to the beautiful west of Ireland in May with GAMTUG hosting the event on Saturday May 3rd. If you are in or around Ireland at that time then I would encourage you sign up. My good friend, and fellow Team System MVP, Mike Azocar will be doing a session on Scrum which should be well worth sitting in on.
There will be no Microsoft speakers presenting, just speakers from the .NET developer community, although I hear our local friendly Platform Evangelists (DPEs) will be on hand to help out and chat to everyone and to take in the atmosphere.
The day promises to be a great learning experience, but also a fantastic way to meet like-minded people - if anything else, you get a trip to the lovely Galway which is never a wasted journey.
October 07, 2007
ASP.NET MVC Framework
Some interesting news seems to be coming out of the Alt.NET Conference in Austin. I'd got a few IM's from folks at the conference talking about Scott Guthrie's talk. According to Jeff Palermo's blog, Scott Guthrie showed off a new ASP.NET MVC Framework. This looks very interesting and might well tempt me back into ASP.NET development. I really like parts of ASP.NET but that whole postback / viewstate thing just confused me. I was used to doing web applications the hard way and having this abstracted away from me into a semi-winform like representation of a web page just got in my way when building sites. It also made them pretty hard to unit test.
Having used (and even written) a few MVC frameworks in the past, I'm really interested to see what it is all about. Looking forward for some more information soon. Jeff's post has a few tantilising details which make me thing this is exactly what I want from ASP.NET.
September 28, 2007
Windows Server 2008 RC0
RC0 of Windows Server 2008 was made available earlier this week. I am currently installing it inside a Virtual PC and I have to say I'm impressed so far. The installation process is much faster and smoother. Also, it is very strange to see how far the "secure as default" mantra of Microsoft has come over the past few years. In Window Server 2008 when you first install even the Sound Service is disabled and you have to enable it before sounds will come out of your soundcard (this is made easy by some nice UI from the standard volume control). How times have changed...
BTW, when installing Windows Server 2008 inside Microsoft Virtual PC 2007 I said that it should use the Windows Vista soundcard when creating the initial VPC configuration and it seems to work great.
August 08, 2007
I Love Resharper
As I've mentioned before, I love Resharper from those crazily clever folks at JetBrains. Today I installed an Early Access version of 3.0.2 into Visual Studio 2008 and all the goodness has returned. No need to write a Using statement again, error highlighting in C# without needing a build, the good old Ctrl-Shift-N keyboard shortcut among others. The 3.0.2 release has come a long way since the 2.5 release that I had been previously using, there are increased coding best practises and some nicer inline static anaylsis. The plug-in is also much more friendly in how it takes over any Visual Studio shortcuts and means that I don't have to re-train the old muscle memory when switching between keyboard shortcuts for actions in Eclipse and Visual Studio.
If you are spending all your day in Visual Studio then I urge you to take a look at Resharper. Personally, I find the increase in productivity well worth it, not to mention the increase in code quality that you get as a result.
May 19, 2007
IMTC Registration Open!
If the recent announcements about Silverlight have your interest and you can get to Dublin on June 7th this year then I would urge you to take a look at this years Irish community conference IMTC. It used to be called INDC but they had to drop the "D" because there is sooo much more to the event than just developer stuff.
Folks who went to the event last year will remember the highlight of the event were the talks and hand-on sessions with Scott Guthrie. This year, I suspect the highlight will be the Silverlight sessions from Tim Sneath - group manager for Silverlight and WPF.
These conferences are ran by the combined Microsoft Techology user groups of Ireland and are a great opportunity to catch up on what it going on, have great talks from world class presenters and chat with your fellow techies - which is always the best bit. The conferences are always very personal. The event is being organised by the community for the community, but they have managed to attract some generous sponsors which means they have managed to keep the costs down to only €50 per person.
If you can make it to Dublin I would strongly encourage you to go. You'd be hard pressed to get such great content in one place along with the chance to interact with the presenters.
When: June 7th, 9am till late (It's an Irish event after all...)
Where: Cineworld complex , Dublin
Cost: 50 euros (to help cover costs).
Website: http://imtc.firstport.ie/
With 18 sessions from amazing speakers, this is one event that you will not want to miss. They are covering everything from the new Silverlight and Expression products (very exciting!) to WCF, Biztalk, SQL Server, Longhorn Server, Security, Mobile technologies, Card Space and even Game Development with the XNA framework with some robotics thrown in as well.
Book now before it is sold out.
January 22, 2007
Getting excited about the next Orcas CTP
I'm getting really excited about the next CTP for the next release of Visual Studio (Codenamed Orcas). Not only will previews of some great new features in Team Foundation Server be coming along, Scott Guthrie just announced a bunch of changes to the web designer editor in Visual Studio. Reading Scotts post it looks like the Visual Studio editor has now got nearly all the features you would want, including ones I was used to from static page and JSP development using Dreamweaver. Orcas is shaping up to be a very exciting release!
December 15, 2006
Jamie Cansdale's Dev Tools Charity Auction
Jamie Cansdale (the brains behind the must-have Visual Studio Extension TestDriven.NET) has set up a charity auction in aid of the charity Wells for Zoë and its work in Malawi. What's better is that he's convinced many of the other must-have .Net development tools folks to donate some licenses into the pot as well. There is now nearly $45,000 worth of software up for grabs - yes you read me right, that is three zeros on the end of the 45. Now I know the US exchange rate is not as good as it used to be, but still - you could end getting yourself software to the value of a decent car and know that you are giving some money to charity. For me the highlights of the auction are:-
- A TestDriven.NET Mug (along with an invite to a years MSDN Subscription worth over $10k)
- A copy of the excellent source control tool, Vault.
- A copy of the mouth-watering CodeRush with Refactor! Pro
Wells for Zoë is an Irish registered Charity set up in 2005 dedicated to the provision of safe drinking water and water storage for irrigation in four remote rural areas of Malawi. The charity's founders cover all administrative overheads. 100% of your donation will be used to help the people in Malawi.
What are you doing still reading this - go and bid now. In case you don't feel like owning some of this awesome software you can also donate here.
November 17, 2006
Windows Vista Available to MSDN Subscribers
I logged into my MSDN subscription account this morning to find the following additions in my Operating Systems section! Obviously, the first thing I did was to start the download of the (single) DVD image for all 32-bit versions of Windows Vista. I tired to request my product key for Windows Vista Ultimate Edition, however there was an error in the MSDN Application - I guess that they are still getting those set up. Anyway, the current estimate is that my download will finish in 20 hours 10 minutes (and that's while the US is asleep), so I'm guessing the keys will be available by the time I finish downloading.
Update: It's 2pm now and my download got to 16% complete before it was interrupted. Now I cannot get a connection at all probably because everyone else in the world is trying to download it. I think I'd better wait until the weekend...
Update: It's now 6pm and my download speed has picked up to 246Kbs (the maximum for my ADSL link), also the product key section of MSDN is now working and I am the proud owner of a Windows Vista Ultimate Edition key!! Hmm, I wonder what I'm going to be doing this weekend :-)
October 31, 2006
TestDriven.NET 2.0 now shipping
In case you missed the excellent news, Jamie Cansdale has announced that TestDriven.NET 2.0 is now shipping. The TestDriven plug-in is essential for anyone wanting to run unit tests from with Visual Studio (any edition). Not only does it allow you to run any flavor of test from the comfort of your right mouse button - it is also lightening fast (much faster than the built in test runner than comes with Visual Studio Team System).
Along side the ability to run all common unit testing frameworks from any version of Visual Studio, Version 2.0 brings many new "power" features that are just fantastic for those of us that spend a lot of time creating plug-ins to Visual Studio.
Jamie is committed to keeping TestDriven.NET available for the community so that the power of unit testing is available to all (not just those of us lucky enough to work for organizations who can provide the upfront investment required for Team System). A fully functional, no nag, version of TestDriven.NET is available if you want - however if you are using this professionally, then I urge you to sign up for a professional or enterprise license.
If you are not unit testing today, then you really have no excuse to go out, download your test framework of choice, install TestDriven.NET and get started. Not only will your tests all be available should you make the wise decision to upgrade to Team System, if you use one of the popular testing frameworks such as NUnit then there is a convertor available to turn them into the MSTest framework used by Team System - meaning that your testing investment is protected for the foreseeable future at least.
September 02, 2006
.NET Framework 3.0 RC1 Released
I've been involved with Indigo for exactly 2 years this week, through the various changes in product name. Anyway RC1 of .NET 3.0 was released yesterday (just under a year since .NET 2.0). I'm currently downloading it and will install over my beta version of WinFX. I'm quite interested to find out if the .NET Framework assemblies get revved at all or if the framework has the same v2.0.50727 libraries that were released with .NET 2.0 last year + the WinFX stuff. I'll soon find out...
Update: Looks like it is .NET 2.0 + WCF, WWF and WPF (which I'm very glad about to be honest). Right then, off to have a play with my TFS Proxy Sync service (which uses WCF to listen to check-in notifications from the Team Foundation Server...)
August 30, 2006
TestDriven.NET 2.0 RC1
Jamie Cansdale has released RC1 of the new version of TestDriven.NET. For those of you that don't know it TestDriven.NET is an excellent unit test integration plug-in for Visual Studio 2005 and 2003. Scott Hanselman recently voted it number 11 in his Big Ten Life and Work-Changing Utilities. Not only does it work with your old NUnit and MBUnit tests it will also work with the new MS Unit Tests in Visual Studio Team System. Also the test runner is lightening fast (must faster than the one that comes with Visual Studio Team System). TestDriven.NET includes some lovely value add features. My favorite is to be able to debug into .NET System calls using the Reflector integration (who needs Symbol servers :-) ). Anyway, if you haven't tried it then I urge you to take it for a spin.
Jamie is now working on TestDriven.NET full time - while you can still download a fully functional free version, you can also get your company to pay for a professional or enterprise version which has more corporate friendly licensing. I'd encourage you to cough up some money for it, the professional version is below the magical $100 mark and will is well worth the investment even if it just so that you can get home earlier and see more of your family.
May 09, 2006
VS 2005 Web Application Project V1.0 Released
OK, so the odds that you read my blog and not Scott Guthrie’s are pretty low, especially if you have any interest in this topic. However, Scott just announced that the VS 2005 Web Application Project has gone V1.0. I had the pleasure of talking with Scott recently and to take a look at this – I have to say that I am incredibly impressed. It’s like all the goodness of a standard Visual Studio 2005 web project with all of the benefits of the old Visual Studio 2003 way and then some. For those of you with complicated automated build processes I would definitely go take a look at this way of doing web projects – if you are using Team Build in VSTS then I would definitely use it.
It’s stuff like this that is blowing me away – just how open Microsoft Developer Division are being at the moment. I have to say I really like the new way of working, I hope that it is sustainable and they don’t have to retreat to their previous ways of working. Being a developer right now is a very exciting time.
May 03, 2006
Live from the INDC in Dublin
Tonight I had the pleasure of listening to Scott Guthrie talk about ASP.NET 2.0, Atlas and IIS 7.0 at the Keynote for the 1st Irish National Developers Conference. I kinda new most of the content before from listening to DotNetRocks and attending the VS2005 launch presentations, however seeing Scott use the stuff for real was awesome. The crowd in Dublin was great as well, asking in depth questions which Scott really seemed to enjoy and was not afraid to just show people how to do things even when it wasn’t something he had ever tried before himself. Tomorrows session from Scott also promises to me a must see talk.
I’ve never really been a huge fan of the ASP.NET 1.1 way of doing things. As a guy that has grown up with the internet I already know how to do the low level stuff and so taking me that one level of abstraction away from the bits and bytes just wasn’t a pleasant experience for me. However, seeing how ASP.NET 2.0 and Atlas does everything and how it works really makes me want to try the stuff in anger again. Even though I’ve always considered myself fairly proficient in Javascript and cross-browser support – developing AJAX applications is just really hard work. Atlas looks like it takes out a lot of the pain.
The INDC is kinda like the “Code Camp” style of conference. The sessions are all very in depth and all of the speakers (including myself) are writing presentations from scratch for this audience. It is one of those conferences where I really wish I was in the audience being able to attend the sessions I wanted to listen to – there are a couple of things on at times were I am “working” that I would to see. Anyway – if you are in the Dublin area tomorrow, I would urge you to come along. Should be well worth it.
March 04, 2006
Make Windows XP Look Shiney
Recently I was looking at some screenshots from my good friend Clark Sell and I spent more time admiring the theme on his copy of Windows than looking at the error he was trying to show me. Anyway, the theme is the one that comes with Windows Tablet PC Edition 2005 or Windows Media Centre 2005 - called "Royale" or "Energy Bliss".
I've seen a few posts around showing you how to hack the Windows Tablet PC download and turn it into a Windows XP theme. However, you can officially download it for Windows XP, along with some irreverent takes on the standard Bliss background, thanks to those lovely folks at Microsoft New Zealand.
March 02, 2006
CruiseControl.NET Source Control Plugin 1.2.0 Released
Tonight, I finally sat down and recompiled the CruiseControl.NET plugin to work with the RC version of the Team Foundation Server API.
Turns out there was only one change – the TeamFoundationServer object now has a public constructor to pass the credentials to rather than using the factory as I has previously been doing. I also put a quick fix in there, but I really want to re-write the whole thing. Looking back at the use of the client API it is very naive, there would be a ton of improvements I would love to do to it to make it faster by actually using some of the great features that Version Control in Team Foundation Server gives you. I also want to talk to the PublishTestResults service. Hey ho – so little time so many projects…
Anyway, cruise on over to the VSTSPlugins project to find out more.
February 09, 2006
Delete Old Files
I was just trying to get some backups configured and I wanted a way of deleting files from a directory stucture that were older than a certain date. I couldn't figure out how to do it easier from a Windows 2003 command script, so I wrote a quick C# console app to do the job. I've included the code and a copy in case you find this useful. WARNING: Use this at your own risk, as I wrote this for myself I haven't spent any time putting in "Are You Sure" prompts or anything. If you were to do something crazy like DeleteOldFiles 5 c:\ it will delete any file on your C:\ drive that has not been written to in 5 days - including things in the Windows directory..
Update: The second I posted this, I noticed the ForFiles command in the Windows Server 2003 resource kit that works a bit like find on unix. Hey ho, at least I wrote some C# code today.
The code is below, as you can see there is not a lot to it - but a nice example of recursion.
using System.Collections.Generic;
using System.Text;
using System.IO;
namespace DeleteOldFiles
{
public class DeleteOldFiles
{
private static double fileCount = 0;
static void Main(string[] args)
{
double daysOld;
if (args.Length != 2
|| !double.TryParse(args[0], out daysOld)
|| !Directory.Exists(args[1]))
{
displayUsage();
return;
}
deleteOldFiles(args[1], daysOld);
}
static private void deleteOldFiles(string path, double daysOld)
{
System.Console.WriteLine(
String.Format("Deleting files older than {0} days",
daysOld)
);
deleteOldFiles(path, DateTime.Now.AddDays(-daysOld));
System.Console.WriteLine(
String.Format("{0} files deleted",
fileCount)
);
}
static private void deleteOldFiles (string path, DateTime olderThanDate)
{
DirectoryInfo dirInfo = new DirectoryInfo(path);
FileInfo[] files = dirInfo.GetFiles();
foreach (FileInfo file in files)
{
if (file.LastWriteTime < olderThanDate)
{
System.Console.WriteLine(
String.Format("Delete {0}.",file.FullName)
);
file.IsReadOnly = false;
file.Delete();
fileCount++;
}
}
// Now recurse down the directories
DirectoryInfo[] dirs = dirInfo.GetDirectories();
foreach (DirectoryInfo dir in dirs)
{
deleteOldFiles(dir.FullName, olderThanDate);
}
}
static private void displayUsage()
{
string message = "DeleteOldFiles.\n\n"
+ "Console utility to recursively search a directory and\n"
+ "delete files older than a certain number of days.\n\n"
+ "Usage: DeleteOldFiles daysOld path\n\n"
+ "\tdaysOld\tnumber of days old the file must be over to be deleted\n\n"
+ "\tpath\tlocation on file system that you want to recursively search\n\n";
System.Console.WriteLine(message);
}
}
}
January 10, 2006
The Guntlet
Buck Hodges recently posted about a problem with locks based on files types and shelving in VSTS Source Control. In the post he mentions a system called Gauntlet that is used internally in some teams at Microsoft.
The Gauntlet system is very interesting to me. I've never seen it in action and have only had snippets of conversations with Microsoft people (and I have to say mostly it is them moaning about it).
From Buck's article, Gauntlet runs by processing a queue of shelvesets. (A Shelveset is a great new feature in VSTS Source Control where you can save your code on the server but outside of the main source tree - you can think of it a bit like a temporary working branch - but see Chris Rathjen's post Is Shelving just a fancy word for branching? for more)
Anyway, each shelveset is processed, and providing the code does not break the build (i.e. compiles, passed static code analysis and unit tests) then it is added to the main source tree.
To me, this is Continuous Integration by another name. Many people are using CruiseControl (and CruiseControl.NET) to acheive the same benefits but the Gauntlet has some additional benefits:-
- The code is not committed to the main branch until it is proven by the server that it will not break the build.
- Main branch build and labels can be reserved for "integration builds" or releases - that way you can very easily provide the users of that build with a list of differences between the builds
The downsides seems to be:-
- More complicated development process, slowing down development
- Increased time before a code change appears in the main branch
- Complicated process discourages small incremental checkin-ins
- When you submit your change, there may be a queue of changes being processed and one of those might break your code, no easy way of preventing this
- Similarly, if you are relying on a change that then doesn't get passed the Gauntlet then odds are additional queued changes by you will also fail
Using an open source toolset, an equivalent process could be done by using patch files. It would be pretty painful with today's toolsets but could be simplified.
Like everything, you have to have a process that meets the needs of your organisation. Development is always a matter of control vs speed of delivery. Personally, I think CI in the traditional sense with CruiseControl strikes a nice balance in most organisations.
But if anyone in Microsoft land fancies describing Gauntlet in a but more detail and perhaps a quick pros / cons of using a similar process versus CI with CruiseControl (or MSBuild for that matter) I for one would love to read it.
January 09, 2006
New web project model for VS 2005.
Scott Guthrie has posted about a new web project type that will be available for VS 2005. I know quite a few people have been running into difficulties with the shipped way that web projects work in VS 2005 (especially when it comes to automating the build process outside of Visual Studio) and this new model sounds like an interesting hybrid.
While the model is interesting in itself, just wanted to say I also am really enjoying the new found agility, responsiveness and transparency at Microsoft - especially from the DevDiv guys.
November 24, 2005
Ready to Launch Ireland Talk
If you had the mis-fortune of hearing me speak at the Belfast launch event for SQL 2005 / Visual Studio 2005 / Biztalk 2006 this morning then the following links may be of interest:-
- Rob Caron's Blog - Best place for VSTS related information
- Visual Studio Team System - Official Microsoft pages
- VSTSPlugins - Open source integrations with VSTS, including the CruiseControl.NET integration demonstrated
- CruiseControl.NET - The Continuous Integration build server
- Teamprise - Access VSTS from inside Eclipse running on Windows, Mac OS X or Linux
Update: If you are after the times I quoted for VSS vs VSTS then see this post.
October 28, 2005
.NET Framework 2.0 Released
Taking me a little by suprise, the official RTM version of the .NET Framework 2.0 is now available. The really good news is that the official version is v2.0.50727 which is exactly the same version of the framework that shipped with Beta 3 of Visual Studio Team System. That makes my VSTSPlugins project a little easier to keep track of. Hopefully the "Beta 3 Refresh" of VSTS only involves server side changes - in which case the CruiseControl plugin should be good for a while and I can start proper work on getting Nant upgraded to .NET 2.0.
October 04, 2005
Snippy the .NET Kangaroo
A new version of Snippy is out. For those of you not familiar - you'll be sorry to hear that Snippy is not a replacement to Clippy in Office 12, nor is it a helpful marsupial that will rescue Timmy from down the well. Snippy is a handy little tool to help you edit code snippets in VS 2005.
After using Live Templates in IntelliJ and then with Resharper in VS 2003, I was very surprised that you had to go out into Notepad when you wanted to edit code snippets in VS 2005. I kept thinking that this was because the software was in beta. As the beta's kept coming the feature was still missing. There are some "code-snippet project" features now, but it is a bit heavyweight to fire up a whole project just to edit one XML file. I couldn't believe a whole episode of DotNetRocks was devoted to the topic when it remained so un-user friendly.
Anyway, go download Snippy - it'll make your code snippet life a happier and more rewarding one. Hopefully it'll be in the next version of VS inside the box...
September 01, 2005
Sourcesafe ss.ini Not Found
Some days I forget how much I hate SourceSafe. If for some reason you start being unable to log into your SourceSafe database and get the error "ss.ini" not found this is because the SourceSafe client has renamed the file to a .tmp file while it was doing something to it and for some reason not finished. To fix the problem, simply navigate in explorer to your users folder ([sourcesafedbpath]\users\[user]) and rename the single temp file in that directory to be ss.ini. If that doesn't work you can try copying another users ss.ini file and manually changing all the setting to make it work for the other user. Good luck.
August 25, 2005
nAnt Tip
I've been struggling with a known issue with nDoc where it tries to generate filenames that are bigger than 256 characters. So instead of generating my documentation within the build folder, which is under the project folder - I'm going to have to create a temp directory at the root of my current drive with a really short directory name and create the documentation within it. The problem I had was figuring out what my current drive was. Answer:
<echo message="${directory::get-directory-root('.')}" />
Probably an easier way, but this'll do for now.
August 09, 2005
Generics
I'm loving the new Generics support in C# 2.0 - may I never use the vanilla System.Collections namespace again. Syntactically, generics in C# and Java are quite smiliar, but there are some important differences under the hood of the VM (or CLR). There is an intersting converstation between Bill Venners and Anders Hejlsberg posted here on the topic of the C# and Java implementations of Generics. Basically, the IL for .NET 2.0 understands generics, but the 1.5 JVM does not.
August 08, 2005
VSTS Extensibility Toolkit
I always have trouble finding this, so I'm adding a link to the VSTS Extensibility toolkit to my blog and my del.icio.us links...
July 28, 2005
Resharper 2.0 EAP is Open
Fantastic, the EAP for Resharper 2.0 is open for public download. Cannot wait to install this as I've really been missing Resharper in Visual Studio 2005 (writing Using statements is soo 2003). I just hope ctrl-shift-n is in there already (remember, ctrl-shift-n is the new ctrl-n). Will post and let you know how I get on.
July 15, 2005
Hatteras Command Line Tips
I couldn't find this with a quick google, so guessed the answer. If you want to pass login credentials to the Hatteras command line client (h.exe or soon to be renamed tf.exe) then you can use the /login command line parameter.
The bit I couldn't find in the helpfile is that the format is /login:username,password. For example, if you want to connect to your team server as a certain user and see what workspaces are set up you do:-
h.exe workspaces /s:vstsserver /login:DOMAIN\username,password
Next in my set of tips is how to pass a date and time as a versionspec when doing a history. This allows you to search for changes between a specific start and end datetime:-
h.exe history $/MyPath /recursive /version:D2005-03-20T10:00:00~D2005-07-15T17:24:45 /s:vstsserver /login:DOMAIN\username,password /noprompt
So the parts they don't tell you in the helpfile are to use "~" to indicate a start and end versionspec for the /version paramater. If you begin the versionspec with D then this get's passed to the regular DateTime.Parse() method. However, we need to find a format that doesn't contain spaces and allows the time component as well so along comes the handy SortableDateTimePattern i.e. "yyyy-MM-ddTHH:mm:ss"
July 13, 2005
Finally I Virtually Understand
Bill Caputo has posted an interesting article discussing inheritance in C#, especially when using interfaces. I learned about OO while learning how to write Java, so I still struggle with the fact that methods in C# are not virtual by default. Bill explains why inheriting a class that implements an interface might not work as you expected.
The key statement here is:-
...the implementation of an interface method is implicitly 'final', just as if the 'sealed' and 'override' modifiers were present.
Anyway, worth reading. I think I might be getting myself a copy of .NET Essentials...
June 29, 2005
Talking to VSTS from Java
Update (Jan 2006): If you would like to use some of the features of VSTS from Eclipse then you might want to take a look at my new employer, Teamprise. They provide an eclipse plugin to access Team Foundation Source Control from Eclipse running on multiple platforms including Windows, Linux and Mac OS X.
Original Post: I have just managed to get a quick test java client talking to VSTS and retrieving a list of projects running on my Team Foundation Server. I know this is a small step towards the goals of the VSTSEclpse project, but I'm really happy I've got this working and wanted to tell everyone. Thanks to Davanum Srinivas, Dexter Wong, Evgeny Beskrovny and the rest of the folks over at the axis-user mailing list for all their help in getting NTLM authentication with a Windows Web Service working from a Java application. I've been trying to get NTLM authentication working for something I needed to do at work recently, so this came in doubly handy (another example of working on Open Source projects in your own time directly benefiting your employer).
The test client uses Axis 1.2.1, Jakarta Commons HTTPClient 3.0rc3, Jakarta Commons Codec 1.3 running in Java 1.4.2_08 on Windows XP SP2. The Commons stuff is needed to allow you to talk to the VSTS Web Services because they are protected with NTLM authentication. To get NTLM working from java, you need to do the following:-
Download a copy of the WDSL to a local directory. This is to allow you to run WSDL2Java over it to generate a starting point for your stubs. You can point WSDL2Java to a URL, but not if that is protected by NTLM ;-)
Run WDSL2Java pointing at your local WSDL file. For more information on WSDL2Java see the axis user documentation.
Edit the createCall method of your stub to include the credentials you would like to use in the call. Currently I have this hard-coded like:-
try {
org.apache.axis.client.Call _call = super._createCall();
super.setUsername("MY_DOMAIN\\myuser");
super.setPassword("mypassword");
...
Obviously, this should be loaded from a configuration property somewhere.
Now, you need to configure Axis to use the Commons HTTPClient class for the HTTP transport. Luckily, the Axis folks have made it very configurable, so all you have to do is include a file called "client-config.wsdd" in the classpath. My client config looks as follows:-
<deployment name="defaultClientConfig"
xmlns="http://xml.apache.org/axis/wsdd/"
xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
<globalConfiguration>
<parameter name="disablePrettyXML" value="true"/>
</globalConfiguration>
<transport name="http" pivot="java:org.apache.axis.transport.http.CommonsHTTPSender"/>
<!-- transport name="http" pivot="java:org.apache.axis.transport.http.HTTPSender"/ -->
<transport name="local" pivot="java:org.apache.axis.transport.local.LocalSender"/>
<transport name="java" pivot="java:org.apache.axis.transport.java.JavaSender"/>
</deployment>
The org.apache.axis.transport.http.CommonsHTTPSender class implements the BasicHandler handler interface and has all the code to make axis use the version of the Commons HTTPClient classes that you have in your classpath.
Now all you need to do is write a client class to use your stub to talk to VSTS. Below is my first class which returns a list of the projects available in the team foundation server by talking to the Common Structure Service running on Team Foundation in the bisserver application.
import java.rmi.RemoteException;
import javax.xml.rpc.ServiceException;
import com.microsoft.VisualStudio.ArrayOfProjectInfo;
import com.microsoft.VisualStudio.ProjectInfo;
import com.microsoft.VisualStudio.ServiceLocator;
import com.microsoft.VisualStudio.ServiceSoap;
/**
* Test client to talk to VSTS from Java.
* @author mwo38
*/
public class TestClient {
public static void main(String[] args) {
ServiceLocator commonStructureServiceLocator = new ServiceLocator();
try {
ServiceSoap commonStructureService = commonStructureServiceLocator.getServiceSoap();
// Iterate over list of projects in team foundation.
ArrayOfProjectInfo arrayOfProjectInfo = commonStructureService.listProjects();
for(int i=0; i < arrayOfProjectInfo.getProjectInfo().length; i++)
{
ProjectInfo info = arrayOfProjectInfo.getProjectInfo(i);
System.out.println("Project: " + info.getName());
}
} catch (ServiceException e) {
e.printStackTrace();
} catch (RemoteException e) {
e.printStackTrace();
}
}
}
Works a treat!! I have had a couple of weird errors when trying NTLM talking to a Windows 2000 workstation and the socket gets closed for no apparent reason, but works fine if I route the request over a proxy. When talking to a VSTS server (running on Windows Server 2003) from a machine that is in a domain trusted by the domain that the VSTS Team Foundation server is running on by a user that has permissions to the VSTS repository I have no problems what-so-ever.
Now the real work starts...
June 23, 2005
State Based Testing vs Interaction Testing
I'm currently thinking a lot about different testing strategies. Martin Fowler has an intesting post entitled Mock Aren't Stubs in which he also discusses the differences between State testing and Interaction testing. In summary state based testing is when you set up your test conditions and say that when you do x the result in the data or from your method is y. Iteraction testing is when you say that when I call the method it should call a, b and c passing the appropriate parameters.
In the days when I first started learning to write code professionally (on an MVS mainframe in PL/1) a test was described as a set of conditions that if your code passes then by definition it is working. This is classic state testing. We didn't do interaction based testing then, possibly becuase we couldn't - we didn't have nMock on the mainframe..
Stepping back into the modern world of TDD in dotnet, by doing state based tests IMHO you are more free to refactor and test all possibly branches of the code by adjusting the inputs to the public interface. With a state based approach you find yourself having to edit the tests much less and just wait for the magic green lights to say you have finished.
Interaction testing allows you a much finer granularity of control in your tests, leading to smaller, discrete sections of code. It also allows you to quickely identifiy which part of the code is broke (by following the single red light in xUnit). However, I've recently run into a few instances where problems have been spotted in the very final stages of programmer testing because assumptions were made about the interaction that turned out to be false.
I'm not saying interaction testing is bad. It is just emitting a slightly bad smell for me at the moment, hence why I am re-evaluating how I test.
April 26, 2005
VSTS Plugin for Eclipse Website
Apologies for the lack of posts recently. We are due a new release of my latest project at work in a couple of weeks and in my spare moments I have been investigating my new play project, a VSTS plugin for Eclipse. Anyway, I have just uploaded the website for the VSTSEclipse project to sourceforge.
It is ages since I have done a static HTML website and not been messing around with some server side functionality or other. There are a couple of features I would like to add but didn't want to delve too deeply back into the world of php that I haven't touched for at least 4 years, possibly longer.
This site is not the most inspirational design I have ever done, but it is all div / css based, tested in IE 6 and Firefox 1.0.3 and I hope to post a handheld version of the stylesheet shortly. As ever there is hardly any content at the moment, but there you go - you would expect nothing less from me, it would all be spelt wrong anyway.
Take a look at let me know what you think. The project itself is really interesting and quite challenging. Looking forward to getting stuck in to it (just need to finish off installing Beta 2 of VSTS at home).
April 01, 2005
VSTS Plugin for Eclipse
In an effort to keep my Java skills up to date while also using some of my new-found dotnet knowledge I've joined the team trying to put together a VSTS SCC plugin for Eclipse that talks to the source control functionality in Visual Studio Team System. It is early days yet but it is an interesting goal and I hope to learn some interesting stuff while putting something together that will be useful for the wider community. If the only thing I accomplish is to get the wonderful Eclipse Diff tool hooked into VSTS then I'll be very happy (the one in VS 2005 is still not as good as the Eclipse one, if a little better than the appalling diff tool that ships with VSS 6).
March 30, 2005
Resharper 2.0 Plan Announced
Jetbrains have announced the plan for Resharper 2.0, including the much awaited support for Visual Studio 2005!. Fantastic news as VS 2005 without resharper is worse than VS 2003 in my humble opinion. (I'd forgotton just how much Resharper does for you!) The full plan is posted here.
EAP for it will start in about a month and complete set of features will be implemented by the middle of summer. The release is planned for the autumn (about the same time as the release of Visual Studio 2005).
March 25, 2005
Nullable DateTime
Found my second thing in .Net that really sucks. In .Net DateTime is a reference type and is therefore not nullable (Unlike the Java.Sql.Date class in java). I am talking to a SQL Server database with a nullable DateTime field and I want to accurately pass this around my application then out of a web service (that is supposed to be interoperable between .Net and Java clients) into a .Net based UI.
Other things that suck about DateTime is that if you create a DateTime and do not initialise it then the object is set to DateTime.MIN_VALUE which happens to be a date lower than SQL Server 2000 can support. I get the feeling that Dates and interoperability really don't mix...
All in all it is a bit smelly. Apparently fixed in .Net 2 - but until then I will have to employ some horrible work-around hack.
January 26, 2005
Jet Brains .NET Profiler
Jet Brains have just announced the opening of the EAP for their new .NET Profiler, available for download. Resharper by Jet Brains and of course IntelliJ are excellent tools, however the future of Resharper and now the .NET Profiler are by no means certain, with Microsoft adopting many of Jetbrain's excellent features in Visual Studio 2005.
From what I have seen on Visual Studio 2005 it is a much better IDE than VS 2003 is, but still a little behind the usability that IntelliJ brought to the Java IDE market. It wil be interesting to see if development of Resharper for VS 2005 can bring anything that makes people who have not allready invested $99 in the product part with their cash. At the moment, Resharper in VS 2003 still makes me smile every time I use it - and I really miss it when I am working from a computer that doesn't have Resharper installed.
I took a look at build 100 of the .NET Profiler and in seems to work for exe file profiling. I managed to sucessfully profile my unit tests by invoking nunit-console.exe passing in the unit test dll as a command line parameter. The ASP.NET profilier just didn't seem to want to work in this build - which is a real shame. I am currently doing a lot of server side stuff and being able to profile my web service of remoting application while is was being driven by my nunit tests would be fanstatsic.
The output of the profiler is fairly easy to read. I've used Java profilers in the past (such as JProbe) but never was actually able to understand what it was telling me (this probably says more about me than the product as I know people who use it all the time and swear by it). 10 minutes with the .NET Profiler has made me realise that the Microsoft XML Serialisation / Deserialisation is pretty slow and so will make me code around this in the future to avoid calls to this when I don't have to.
I will continue to try out the .NET Profiler and see how it goes. My only worry is that code profiling is supposed to be one of the new features in MS Visual Studio Team System. Will Jetbrains compliment or compete against the Microsoft tool?
December 01, 2004
Generating Excel Files in C#
I have been investigating several ways of generating files suitable for use in Excel from a C# application.
As with most problems, there is more than one way to crack a nut. Various examples on the web show how to generate formatted sheets in Excel, either by controlling Excel from a C# application or by transforming XML data. The XML transformation has the disadvantage that is limits your clients to the most recent versions of Excel, whereas dire manipulation of Excel requires that you have it installed on the server. You also have to be very careful not to leave instances of Excel running in the background, eventually grinding your server to a halt.
This article provides a demonstration of a very simple method to generate a file that will load into Excel. It is a bit of a hack that I used from a java platform a few years ago, but it works if all you need is a simple data export (with less than 65536 rows). All you do is set the response stream to the mime type "application/vnd.ms-excel" and then pass a tab delimted set of data with new lines at the end of each row.
Below is a sample code snippet showing a method to generate a simple set of data that will load into Excel (should work with most versions including Excel 95 and above). The version below also highlights how to request that the browser treats the file as a download and forces the user to save to disk rather than load in the browser. This also has the advantage that the filename is easily controlled.
/// Demo class showing how to generate an Excel Attachment
/// </summary>
public class XLWriter
{
public static void Write(HttpResponse response)
{
// make sure nothing is in response stream
response.Clear();
response.Charset = "";
// set MIME type to be Excel file.
response.ContentType = "application/vnd.ms-excel";
// add a header to response to force download (specifying filename)
response.AddHeader("Content-Disposition", "attachment; filename=\"MyFile.xls\"");
// Send the data. Tab delimited, with newlines.
response.Write("Col1\tCol2\tCol3\tCol4\n");
response.Write("Data 1\tData 2\tData 3\tData 4\n");
response.Write("Data 1\tData 2\tData 3\tData 4\n");
response.Write("Data 1\tData 2\tData 3\tData 4\n");
response.Write("Data 1\tData 2\tData 3\tData 4\n");
// Close response stream.
response.End();
}
}
