• Shortcuts : 'n' next unread feed - 'p' previous unread feed • Styles : 1 2

» Publishers, Monetize your RSS feeds with FeedShow:  More infos  (Show/Hide Ads)


Date: Friday, 17 Jan 2014 11:02

Over the past couple of weeks I’ve had several people ask me about my dev environment for working with Git on Windows so I decided to write it up here for me to point people to. Of course the first thing that you want is Visual Studio 2013 with the built in Git tooling. While I’m obviously very biased in terms of the Visual Studio tools I’m actually more familiar with the command line workflow – especially coming from the Mac. However the team specifically designed the Visual Studio tools to work well with the command line and compliment them – I find myself swapping more and more between the command line and the UI depending on what’s quickest for me. I NEVER use the command line for merging any more, but I still use if for dealing with multiple remotes (very common in OSS workflows) squashing and rebasing my commits etc. There are some things I actually find myself using Visual Studio for that I never thought I would. For example I quite often find myself swapping my email address around when I’m doing commits for work or if I’m working on a demo or a side project and I’ve noticed I’ve been using the Git settings panel in Team Explorer more and more rather than going to “git config” which surprised me.

So, how do I set up my command line Git experience?

First of all you have to install Git for Windows of course.  I always use the .exe installer from here (ignore the –preview moniker, they are good – at the time of writing the latest is Git-1.8.5.2-preview20131230.exe). Now one of the first mistakes I see people do is go for the default options in the installer which results is people using Git Bash. If you love yourself don’t do that, but make sure Git is added to your path. On the screens that I need to make decisions on, I always follow this path.

For component selection, I generally go for the defaults. I don’t use the shell extensions personally but they don’t hurt.

image

This is the important one being the change to make sure Git is added to your Path. This makes sure that you can go to the command shell or PowerShell and run Git. The Git Bash shell is evil IMHO, I never find myself using it despite using Bash all the time when I’m on *nix.

image

Then I go with the default of setting the CRLF behaviour to normalize as Unix style endings in the commits.  Basically this makes sure a commit generated on Windows is the same as one done on the Mac or on Linux but also that you can still use notepad if you check out a file that was edited in Vim on Linux.

image

 

At this point you now have Git installed. Congratulations!  However, you can do better than that…

Enter PoshGit

The next thing I install is PoshGit. I swear, PoshGit is the main reason to use the PowerShell console (that and also the fact it doesn’t shout at you when you accidentally type “ls” instead of “dir”) Installation of PoshGit can be a bit quirky but Keith’s instructions are pretty good. Basically, after he’s helped you make sure your PowerShell environment is set up correctly, you clone the repo (git clone https://github.com/dahlbyk/posh-git.git), cd into it and then run the install script.

I always use Git over HTTPS rather than SSH so I often don’t have Putty installed with Paegent to handle my keys. Therefore I tend to just comment out the Start-SshAgent -Quiet line in \posh-git\profile.example.ps1. If you are seeing the error “WARNING: Could not find ssh-agent” when you start PowerShell and you don’t need SSH then just open up profile.example.ps1 in notepad, scroll down to the end of the file and make sure it looks like this:

   ...

Enable-GitColors

Pop-Location

# Start-SshAgent -Quiet

 

Remembering Passwords

Next up I install Andrew Nurse’s credential helper, git-credential-winstore. If you are talking to a Git server that requires a username and password, rather than having to type your credentials all the time this nifty little helper will actually store them securely in the Windows Credential Manager.  Note that when installing you’ll see an error if you’ve gone for the middle option when setting your path in Git for Windows because Git.exe isn’t on your path (Git.cmd is).  Therefore you are going to want to:

  1. Download it from CodePlex and save it to your disk
  2. In a command / powershell window, cd into your Downloads folder
  3. Install the credential helper by typing:

git-credential-winstore.exe -I "C:\Program Files (x86)\Git\bin\git.exe"

Combined with with web interface in TFS, Visual Studio 2013 and Eclipse with egit, that’s all I need personally. However if you want a graphical view of your repository then a lot of people use gitk which is installed with Git for Windows (just type “gitk” inside your repo in the command shell / powershell windows).  You can also type “git gui” for the git-gui tools.  Other popular graphical tools you might want to install are GitHub’s free app GitHub for Windows and Atlassian’s free app SourceTree.  GitHub for Windows is very pretty and great for managing your GitHub based repos. Atlassian’s SourceTree is very highly regarded as stand-alone UI for working with Git repos on Windows.

Author: "Martin Woodward" Tags: "Git"
Send by mail Print  Save  Delicious 
Date: Monday, 13 May 2013 13:27

If you want to work with your local Git repositories in some .NET code then LibGit2Sharp is your friend.  It’s the open source library used by the Visual Studio Tools for Git and gives you a very idiomatic way to talk to Git from C# or VB.NET.  I thought it would be worth a quick tutorial post showing how easy it is to get started by querying a repository helping us learn a bit about the library but also learn more about Git itself. As LibGit2Sharp is open source in this example I’m going to point to cloned copy of the repository I have locally already by using the Git tooling in Visual Studio or by typing git clone https://github.com/libgit2/libgit2sharp.git. However you can obviously point to any Git repository you already have locally.

To begin, create a new console project in Visual Studio. We need to add a reference to the Lib2Sharp library and the quickest way to do that is to open the NuGet package manager by right-clicking on your project in Solution Explorer and select Manage NuGet Packages…  Search online for “LibGit2Sharp” and Install.

NPM to install LibGit2Sharp

Then accessing an existing repo is trivial, simply use the LibGit2Sharp.Repository class. A handy way to get a particular commit is by its hash if you know it.

      public static void Main(string[] args)
      {
         
using (var repo = new Repository(@"D:\source\LibGit2Sharp"
))
          {
             
Commit commit = repo.Lookup<Commit>("73b48894238c3e9c37f9f3a696bbd4bffcf45ce5"
);
             
Console.WriteLine("Author: {0}"
, commit.Author.Name);
             
Console.WriteLine("Message: {0}"
, commit.MessageShort);
          }
      }

But what if we just want the commit that’s the latest of the current branch, in Git-speak we want the “Tip” of “Head”. LibGit2Sharp gives you an easy way to get to the Head through the repository object. So we can do the following:

    public static void Main(string[] args)
      {
         
using (var repo = new Repository(@"D:\source\LibGit2Sharp"
))
          {
             
Commit
commit = repo.Head.Tip;
             
Console.WriteLine("Author: {0}"
, commit.Author.Name);
             
Console.WriteLine("Message: {0}"
, commit.MessageShort);
          }
      }

A point in time in the repository is represented by a Commit. Each Commit points to a Tree which you can think of as a directory/folder. A Tree can contain a Blob (i.e. the contents of a file) or another Tree (i.e. a sub-folder).

So if you want to list the contents at the root of the repository then you can do

        foreach(TreeEntry treeEntry in commit.Tree)
        {
           
Console.WriteLine("Path:{0} - Type:{1}"
, treeEntry.Path, treeEntry.TargetType);
        }

That will give you something like the following when against the LibGit2Sharp repository

Path:.gitattributes - Type:Blob
Path:.gitignore - Type:Blob
Path:.gitmodules - Type:Blob
Path:.mailmap - Type:Blob
Path:.travis.yml - Type:Blob
Path:CHANGES.md - Type:Blob
Path:CI-build.msbuild - Type:Blob
Path:LICENSE.md - Type:Blob
Path:Lib - Type:Tree
Path:LibGit2Sharp.Tests - Type:Tree
Path:LibGit2Sharp.sln - Type:Blob
Path:LibGit2Sharp - Type:Tree
Path:README.md - Type:Blob
Path:ResharperSettings.xml - Type:Blob
Path:UpdateLibgit2ToSha.ps1 - Type:Blob
Path:build.libgit2sharp.cmd - Type:Blob
Path:build.libgit2sharp.sh - Type:Blob
Path:build.libgit2sharp.x64.cmd - Type:Blob
Path:libgit2 - Type:GitLink
Path:nuget.package - Type:Tree
Path:square-logo.png - Type:Blob

To see which files changed in a particular commit.  To do that we need to find the diff between the commit and it’s parent. For now let’s just assume that we have a single parent (i.e. we’re not a merge commit). Therefore we can do this

        Tree commitTree = repo.Head.Tip.Tree;
       
Tree
parentCommitTree = repo.Head.Tip.Parents.Single().Tree;

       
TreeChanges
changes = repo.Diff.Compare(parentCommitTree, commitTree);

       
Console.WriteLine("{0} files changed.",changes.Count());

And finally to iterate over the changes to show what files changed in that commit

        foreach(TreeEntryChanges treeEntryChanges in changes)
        {
           
Console.WriteLine("Path:{0} +{1} -{2} "
,
                    treeEntryChanges.Path,
                    treeEntryChanges.LinesAdded,
                    treeEntryChanges.LinesDeleted
                );
        }

That then gives the following output

Author: nulltoken
Message: Release LibGit2Sharp v0.11
3 files changed.
Path:LibGit2Sharp.Tests\DiffTreeToTreeFixture.cs +35 -11
Path:LibGit2Sharp.Tests\LibGit2Sharp.Tests.csproj +1 -0
Path:LibGit2Sharp.Tests\TestHelpers\OdbHelper.cs +17 -0

This post obviously just scratches at the surface of what is possible with LibGit2Sharp. We’re starting the process of trying to flesh out the documentation for the project from the current starting position of none, but it the meantime if you want to see some more examples of using LibGit2Sharp then take a look at the Unit Tests.

Source Code: Commit1.cs
Author: "Martin Woodward" Tags: "Git, LibGit2, git, libgit2, libgit2sharp"
Send by mail Print  Save  Delicious 
Date: Friday, 22 Jun 2012 02:59

I’ve been running Eclipse Juno regularly since the M5 milestone.  One of the things I’ve really noticed is that the default theme for Eclipse Juno on Mac OS X blends in better with other Cocoa applications than Juno looks on my Windows machines. Today I just realised that this is because Eclipse is picking up the Eclipse “Windows XP Blue” theme by default. Below is a picture of Juno RC3 with a Windows Explorer window over it for comparison.

Eclipse Juno RC3 on Windows XP Release Preview

To change the theme, go to Window, Preferences, General, Appearance and select Windows 7.  This looks a lot better on my Windows 8 Release Preview machine as shown below.

Eclipse Juno RC3 on Windows XP Release Preview with Windows 7 theme

Now, one of the great things about e4 is that it is skinnable using CSS.  I thought I’d knock up a quick stylesheet to get rid of the gradient in the toolbar and tidy up a few other little things.  It’s also really easy to define a theme as part of the plugin.xml and only have it apply to people running Windows 8 – simply add the following (note the condition on OS version of 6.2):

<extension
point="org.eclipse.e4.ui.css.swt.theme">
   <theme
         basestylesheeturi="css/e4_default_win8.css"
         id="org.eclipse.e4.ui.css.theme.e4_default"
         label="Windows 8 Desktop"
         os="win32"
         os_version="6.2"
>
   </theme>
</extension>

This is what my Windows 8 theme for Juno currently looks like against explorer:

Eclipse Juno RC3 on Windows XP Release Preview with custom theme

Needs a bit of playing with (for example, I’ve noticed that swapping themes in Eclipse works a lot better if you explicitly override things like the background images that have been used previously in themes in that Eclipse session rather than just leaving them not set).  What do you think?  If you are interested the CSS is below but it’s just a subtly changed version of the default win7 theme.

@import url('e4_basestyle.css');
.MTrimmedWindow {
    background-color: #EFF6FE;
}

.MPartStack {
    font-size: 9;
    font-family: 'Segoe UI';
    swt-simple: true;
    swt-mru-visible: false;
}

.MTrimBar {
    background-color: #EFF6FE;
}

.MToolControl.TrimStack {
    frame-image:  url("./win7TSFrame.png");
    handle-image:  url("./win7Handle.png");
}

.MPartStack.active {
    swt-unselected-tabs-color: #F3F9FF #D0DFEE #CEDDED #CEDDED #D2E1F0 #D2E1F0 #FFFFFF 20% 45% 60% 70% 100% 100%;
    swt-outer-keyline-color: #B6BCCC;
}

#PerspectiveSwitcher  {
    background-color: #E1E6F6 #EFF6FE 100%;
}

#org-eclipse-ui-editorss {
   swt-tab-renderer: url('bundleclass://org.eclipse.e4.ui.workbench.renderers.swt/org.eclipse.e4.ui.workbench.renderers.swt.CTabRendering');
   swt-unselected-tabs-color: #F0F0F0 #F0F0F0 #F0F0F0 100% 100%;
   swt-outer-keyline-color: #B4B4B4;
   swt-inner-keyline-color: #F0F0F0;
   swt-tab-outline: #F0F0F0;
   color: #F0F0F0;
   swt-tab-height: 8px;
   padding: 0px 5px 7px;
}

CTabFolder.MArea .MPartStack, CTabFolder.MArea .MPartStack.active {
   swt-shadow-visible: false;
}

CTabFolder Canvas {
  background-color: #F8F8F8;
}


Anyway, lesson from this is to at least change the theme in Juno on Windows 8 from Windows XP Blue to the Windows 7. The jury is still out on my customized stylesheet above – I’m sure someone with some actual design skills could do better.

Author: "Martin Woodward" Tags: "Java, eclipse, juno, win8"
Send by mail Print  Save  Delicious 
Date: Tuesday, 19 Jun 2012 20:59

I just got delivery of my shiny new Raspberry Pi.  With-in a few minutes I had it all booted and running a stock Debian “squeeze” image, almost too easy and the performance of the diminutive Raspberry Pi was great. Previously my experiences with Embedded Linux has mostly been when running on hacked router firmwares so running on a chip as powerful as the ARM v11 Broadcoam chip in the Raspberry Pi is a real pleasure.  As getting it up and running was so easy, what should be my first project on my latest (and least expensive ever) computer?  I thought I’d see what it took to talk to TFS from the device :-)

Accessing TFS from a Raspberry Pi

First things first, I had to get Java installed.  It sounds like Oracle are working on a version of Java with a proper Hotspot JVM – but I just went with a vanilla OpenJDK build for the device that lacks important features like a JIT etc.  It’s all fully functional, just the performance isn’t great but sticking to the TFS cross-platform command line client (tf) in Team Explorer Everywhere, performance is usable and will only get better as better JVM’s come available for the Raspberry Pi.

To install a JRE you would just do the usual:

sudo apt-get install openjdk-6-jre

However, I needed to do some building on the Raspberry Pi and needed a full JDK so I went with:

sudo apt-get install openjdk-6-jdk

And then set my JAVA_HOME by adding the following to my profile

export JAVA_HOME=/usr/lib/jvm/java-6-openjdk/

Now, I like to say that Team Explorer Everywhere is 99.99% Java.  All the code to talk to the TFS webservices is all Java based, however there is a small but very important set of native code that we also ship with our Cross-platform command line client, the Eclipse plug-in and the TFS SDK for Java.  The native code does things that are hard to do otherwise such as see how many columns are available in the current console session, use Key Ring of Keychain for secure credential storage, interface with the platforms native Kerberos libraries if present to allow for single sign-on with TFS etc.  My next step to get tf working on the Raspberry Pi was to compile our native code for the armv6l based chipset.  As mentioned this native code includes Kerberos support so I first had to add the Kerberos libraries (sudo apt-get install libkrb5-dev - note you wouldn’t have to do this if you didn’t need Kerberos support as we also support NTLMv2 out the box without requiring any additional dependencies)

I ran the native build process, and amazingly all the unit tests passed!  I then checked the Linux/Arm natives back into TFS, waiting for the CI build to finish and then downloaded a new TFS-CLC.zip from the build server.  Unzipped the standard CLC into my users ~/Bin directory and it just worked!

I can now happily talk to my local TFS server from my $25 Raspberry Pi.  With local workspaces and transparent execute bit support in TFS 2012 it’s a really good experience. I just use vim to edit files, do a quick “tf status” to see what's changed and then a “tf checkin” to add the files to source control.

I’ve actually added the Linux on Arm natives into the main build of TEE so they might appear in the RTM version of Team Explorer Everywhere if I don’t find any major bugs.  It definitely wouldn’t be classed as a supported platform or anything, but it certainly “works on my machine”.  Possibly more useful is that if the Arm natives also ship in our TFS SDK for Java it would mean any Java applications coded on the Raspberry Pi in the future would have full access to the same TFS API that we use to create the command line client and the Eclipse plug-ins.

Picture of the Raspberry Pi running TEE against my ID badge for scaleUpdate: I was getting some questions on Twitter, so just to explain how small this device is here is a picture of it against my Microsoft ID Card (which is credit card sized).  The Raspberry PI is almost exactly the same size.  The ARM CPU on it is about the size of a thumbnail – much smaller than the HDMI and Ethernet connection it is attached to.  Really nice piece of kit for $25 if you can get hold of one.

All this was anti-climatically easy. I’m going to have to figure out what to do as my next Raspberry Pi project.  Now that I have an API I can use for TFS, I’m thinking about doing a Wallboard display application to display stats from my TFS server (such as latest build status, latest check-ins and work item assignments etc) from the device onto a cheap HDMI TV set in my office – but if anyone has any other ideas let me know.

Author: "Martin Woodward" Tags: "tfs, tee, tfs"
Send by mail Print  Save  Delicious 
Date: Tuesday, 05 Jul 2011 12:36

If you are looking to extend Team Foundation Build using workflow activities, then the first thing you should do it take a look at the latest stable release of the Community TFS Build Extensions over on CodePlex.  This is a collection of around 100 activities that can provide many commonly requested functions incluing running CodeMetrics and NUnit tests, creating a Zip archive, wrapping RoboCopy for deployment, updating AssemblyInfo files, running StyleCop, merging assemblies with ILMerge etc etc.  Basically most of the building blocks for major common customization already done for you.  Also – as it’s an open source project ran by the MVP community you have access to a bunch of great code that shows you how to create your own activity should you want to do something that has yet to be done (don’t forget to contribute it back if you can)

Great job to the team of folks contributingg to the community build extensions (many of which I am proud to call my friends) – I’m looking forward to seeing the project go from strength to strength now that they have their first stable release out the door.

Author: "Martin Woodward" Tags: "Vsts, tfs, teambuild, tfs, tfs2010"
Send by mail Print  Save  Delicious 
Date: Wednesday, 22 Jun 2011 20:14

As you have probably heard by now, Eclipse 3.7 shipped today.  Congratulations to everyone involved.  From a personal point of view I’m secretly pleased to see that one of my own bug reports manage to sneak it’s way in to this release as well which I think means I have managed to do my bit and contribute a little something to every Eclipse since 3.4

We’ve been tracking the Indigo release internally through the latter milestone builds and so far we’ve yet to discover any issues when using Eclipse 3.7 with Team Explorer Everywhere 2010 SP1 (as many of the team do every day).

Eclipse 3.7 with Team Explorer Everywhere 2010 SP1

Let me know if you think you do find something but as we don’t use any internal Eclipse API’s, we stick to the standard Eclipse contributions and install via the standard update site model - Eclipse 3.7 is looking very good with TEE 2010 SP1.

I’ll be showing off Team Explorer Everywhere 2010 SP1 in Indigo at the following events over the next few days:

Author: "Martin Woodward" Tags: "Vsts, tfs, tee, tfs, tfs2010"
Send by mail Print  Save  Delicious 
Date: Saturday, 18 Jun 2011 08:31

This weekend I thought I would get round to a project that I’ve been meaning to do for a long time – a new website for the Radio TFS podcast that I do with Mickey and Paul.  I haven’t had the chance to play with WebMatrix before so thought that I would give it a try when building the new Radio TFS site.  I’m also behind in my learning's around ASP.NET MVC, WebDeploy and IIS 7 so it’s going to be a good weekend! 

One thing that I wanted to do was make sure that all the old episode links redirect to the new locations.  To do this I’m building a HttpHandler that listens for all the requests ending in *.aspx (which is what the episode links did) and then look up that link in the database to redirect them to the new link.  However it took me a while to figure out how to create a HttpHandler in Webmatrix.  As with everything – once you know the answer it is easy but as it took me a while to figure out I’m documenting it here in case others try searching for the answer with the same keywords I was using.

The first step is to create your HttpHandler class.  In the App_Code directory in your WebMatrix site create a new C# file (mine is called LegacyUrlHandler.cs).  A very simple HttpHandler is below.

using System;
using System.Collections.Generic;
using System.Web;

namespace RadioTFS
{
    public class LegacyURLHttpHandler : IHttpHandler
    {
        public bool IsReusable
        {
            // The same instance of this class can be re-used so we return true.
            get {
                return true;
            }
        }

        public void ProcessRequest(HttpContext context)
        {
            HttpResponse response = context.Response;
            response.Write("<html><body><h1>Hello World!</h1></body></html>");
        }
    }
}

You then have to register this HttpHandler in the web.config.  Assuming this is being deployed to IIS7 you register it as follows:

<?xml version="1.0" encoding="UTF-8"?>
<configuration>
    <system.webServer>
        .....
        <handlers>
            <add name="LegacyUrlHandler" verb="*"
                path="*.aspx"
                type="RadioTFS.LegacyURLHttpHandler"
                resourceType="Unspecified" />
        </handlers> 
    </system.webServer>
    ....
</configuration>

Hope that helps you.  I’ll probably be blogging again over the weekend as I discover more – and I’ll definitely let you know when the new site is live.

Author: "Martin Woodward" Tags: "Dotnet, Programming, webmatrix"
Send by mail Print  Save  Delicious 
Date: Tuesday, 14 Jun 2011 04:53

When you create a new build definition with TFS 2010 by default it does a clean build for you every time.  That is to say that between builds all the source from the previous build is deleted along with the compiled outputs and then the source is downloaded fresh, built and you are good to go.  There is a good reason for this to be the default – it is the safest option.  If your build script messes around with the files in your source directory at all (perhaps baking in a build number into the AssemblyInfo files etc) then you want to get a clean workspace to ensure that you are back to a known good state.

However, if you know what you are doing then there are couple of really good reasons why only building the things that changed between builds would be very useful:

  1. Speed – if you are doing CI builds (which you should be doing if you are not BTW) then the only thing that will have changed between builds to the same build agent are the contents of a single check-in – a single changeset.  If you are checking in regularly (which you should be doing BTW) then these changesets usually contain a small number of changes.  Downloading only the files that have changed between builds speeds things up but also only compiling new versions of assemblies that have been affected saves even more time.
  2. Differential Deployment – For websites it makes a lot of sense to use something like robocopy to deploy the output of a build to a directory used by a test IIS instance.  By using robocopy you can specify that only the files that have changed should be copied over.  When TFS does a get into a clean workspace the files did not previously exist in that location on disk.  Therefore the creation date and modification dates of the source files are taken as the time at which they are downloaded to the machine – i.e. the time of doing a get.  By switching to incremental builds files which haven’t been touched are left alone so older files keep their timestamps.  Only the changes files have a new timestamp.  Utilities such as robocopy can therefore easily identify these and therefore only deploy the changes files over to IIS.  IIS then sees that the file is new and so compiles it first time that page is accessed or a page references an assembly that has been updated.

Traditionally, in the world of build solutions, incremental builds were always treated with a bit of “Here be dragons”.  Many version control systems can leave orphan files around in your local working copy when you update to the latest version from the server (for example in the case that a file was deleted, moved or renamed on the server).  TFS however cleans up your workspace as you go along so that when you do a get deleted files are deleted from your local file system, as are the old versions when you do a rename/move etc.

Enabling Incremental Builds with TFS 2010

To enable incremental builds, edit the build definition in Visual Studio 2010 and set the Clean Workspace property to “None”.

Default Template build process properties shown when editing the build definition in Visual Studio 2010

Note that there are a few options for Clean Workspace, All; Outputs; None – take a look at the handy property help text to learn more about what they mean. For example Outputs is useful if you want the benefit of not downloading all your source every time but are not able or do not trust the ability to incrementally compile your binaries.

Your mileage may vary depending on your build process and what you do during it.  Depending on assumptions made during and build customization work you have done you may indeed need to re-engineer the way that you do your build to be able to reap the benefits of incremental builds.  Also, you may want to do things like incremental builds to a dev test instance but a full clean build for your nightly drop to a QA test environment.  Also remember that even with a CI build set for incremental builds, you can at any time Queue a manual build from Visual Studio by right clicking on the build definition in Team Explorer.  From there you can (if you wanted) set the Clean Workspace property to All for your manual build if something funny was going on and you just wanted to reset everything – and if you are really fancy you might even do it so that a deployment of a clean build to IIS not only copies all the files over fresh but forces an IIS Reset for the true belt and braces approach.

Author: "Martin Woodward" Tags: "Vsts, tfs, teambuild, tfs, tfs2010"
Send by mail Print  Save  Delicious 
Date: Thursday, 26 May 2011 17:19

As you may have read over on Brian Harry’s blog, we recently made available a TFS SDK for Java.  This is the same core code that we use in Team Explorer Everywhere 2010 SP1 to talk to TFS from Eclipse and from our Cross-platform command line client – just packaged up into a single jar file to make it easier to consume and re-distribute in your own applications.

The TFS SDK for Java ships with a bunch of sample applications, check-in policies, custom work item controls and some handy snippets of code.  It also includes an Ant build script to allow you to build the samples that we ship.  However – I thought it would be interesting to walk through how you can consume the SDK in a simple Eclipse project and make use of some of the nice Eclipse features such as inline Javadoc.

To begin, download the TFS SDK for Java 10.1.0 from the download site and unzip it to a handy location. Next create a new blank Java project in Eclipse (File, New, Java Project).

New Java Project dialog in Eclipse

Give the project a name (i.e. com.contoso.tfsplay), then press Finish to create the empty project.  The next thing that we are going to do is browse to the empty project in the file system to copy over the relevant files in the SDK.  Having the SDK as part of your Java project makes it much easier to build and deploy it later.

First of all, browse to your Eclipse workspace folder in the file system (for example mine is at C:\play\tfssdk4j\com.contoso.tfsplay but you can find where yours is by right clicking on the project you just created and selecting properties).  Inside the project folder, create a new folder to hold your TFS SDK bits.  Mine is called tfssdk at the root at the folder.  Inside this copy the redist folder from the TFS SDK ZIP archive.  I also personally ZIP up the Javadoc folder from the TFS and also include it – however if you have a copy of the TFS SDK Javadoc installed on an intranet server somewhere you could just point to it later on.

Now that we have the SDK inside our project, if I press refresh back in Eclipse on the package explorer I get something that looks like the following:

Eclipse with the TFS SDK in a project

Now we want to configure the project to include the SDK in it’s build path. Right click on your project, select Properties, then Java Build Path.  In the Libraries tab press Add JAR… Select the com.microsoft.tfs.sdk-10.1.0.jar file from your tfssdk/redist/lib folder.  Now that the JAR file is included, we want to expand it to let Eclipse know about the Javadoc and the natives.  Double click on the Javadoc location and point it to where the TFS SDK Javadoc is located.  Do the same for the natives for your platform.

Configuring Java build path in Eclipse

Your JAR file definition should then look like the above and you are now up and ready to start talking to TFS via the SDK in your Java project.

For our example, let’s create a quick class with a main method. (Right click on the project, New, Class…)

New Class Dialog

Then inside the main method, I’ll quickly steal the code that Brian used in his TFS SDK for Java announcement blog post. 

Example code in Eclipse

Once the code is included and modified to point at my TFS project collection, I’ll quickly debug the code (Run, Debug As…, Java Application…)

I’ll be posting more samples shortly, but now the code is running let’s step through it.  To begin with we first need to get hold of a project collection. In Brian’s example he uses:

TFSTeamProjectCollection tpc =
            new TFSTeamProjectCollection("http://tfs2010:8080/tfs/DefaultCollection");

The reason this works is that the native code libraries are configured correctly so the SDK can then get the credentials of the logged in user and use those to authenticate with TFS.  However – what if you don’t want to use those credentials but want to pass them in via code?  Well luckily the TFSTeamProjectCollection has lots of overloads including one that allows you to pass username, password and domain.

Javadoc for TFSTeamProjectCollection

TFSTeamProjectCollection tpc =
            new TFSTeamProjectCollection("http://tfs2010:8080/tfs/DefaultCollection",
                    "username","domain","password");

In our example, we now want to query work items – so we get hold of a work item client as follows:

WorkItemClient workItemClient = tpc.getWorkItemClient();

We then create the query that we want to run.  In the example we’re going to execute an ad-hoc query in TFS’s Work Item Query Language (WIQL).

// Define the WIQL query.         
String wiqlQuery =
   
"Select ID, Title from WorkItems where (State = 'Active') order by Title";

// Run the query and get the results.         
WorkItemCollection workItems = workItemClient.query(wiqlQuery);

 

Finally, we then need to loop over the collection of results and display them.  The WorkItemCollection class contains logic to efficiently handle large result sets.  It will page in a set of query results as needed rather than waiting for all the results to be returned before you can start iterating over them.  This makes it much more efficient if you just need a page of data – i.e.

final int maxToPrint = 20;

for (int i = 0; i < workItems.size(); i++)         
{
    if (i >= maxToPrint)             
    {
        System.out.println("[...]");                 
        break;
    }
    WorkItem workItem = workItems.getWorkItem(i);
   
    System.out.println(workItem.getID() + "\t" + workItem.getTitle()); 
}

 

The full code for the QueryWorkItemExample is below.  Hope that is makes a bit more sense now that we’ve walked through it.  

package com.contso.tfsplay;

import com.microsoft.tfs.core.TFSTeamProjectCollection;
import com.microsoft.tfs.core.clients.workitem.WorkItem;
import com.microsoft.tfs.core.clients.workitem.WorkItemClient;
import com.microsoft.tfs.core.clients.workitem.query.WorkItemCollection;

public class QueryWorkitemExample {

    /**
     * @param args
     */
    public static void main(String[] args)
    {
        TFSTeamProjectCollection tpc =
            new TFSTeamProjectCollection("
http://tfs2010:8080/tfs/DefaultCollection",
                    "username","password","domain");
       
        WorkItemClient workItemClient = tpc.getWorkItemClient();
       
        // Define the WIQL query.         
        String wiqlQuery =
            "Select ID, Title from WorkItems where (State = 'Active') order by Title";
       
        // Run the query and get the results.         
        WorkItemCollection workItems = workItemClient.query(wiqlQuery);

        System.out.println("Found " + workItems.size() + " work items.");
        System.out.println();
       
        // Write out the heading.         
        System.out.println("ID\tTitle");
       
        // Output the first 20 results of the query
        final int maxToPrint = 20;
       
        for (int i = 0; i < workItems.size(); i++)         
        {
            if (i >= maxToPrint)             
            {
                System.out.println("[...]");                 
                break;
            }
            WorkItem workItem = workItems.getWorkItem(i);
           
            System.out.println(workItem.getID() + "\t" + workItem.getTitle()); 
        }
       
        System.out.println("Done");
    }

}

In future posts I’ll talk about how to do more advanced things in Java against TFS.  If you have any requests then please drop me a line, but for now take a look at the snippets that we ship in the SDK.  I’ll also be posting walkthrough posts discussing custom check-in policies in Team Explorer Everywhere, custom Work Item Controls as well as other ways of extending Team Explorer Everywhere and using the SDK.  Again – if you have anything in particular that you’d like me to use as an example then let me know.

Author: "Martin Woodward" Tags: "Programming, Vsts, tfs, java, tfs, tfs20..."
Send by mail Print  Save  Delicious 
Date: Wednesday, 18 May 2011 01:49

current_year_plannerA while ago I blogged about my surprising obsession for having a year planner by my desk.  For people that know me this probably comes as a huge shock as I don’t come across as someone who is particularly well organized – but I just find it very useful.  Today I had an email from Roz Aidie asking me if it was possible to make the calendar display the Academic year.   As the spreadsheet is all based on conditional formatting formulas, the answer is happily yes.  Just change the months at the top of the column and you get the days displayed for that month.

I posted a new version of the year planner that shows the current calendar year, alongside the Financial (April – March) and Academic (September – August) year.  You can get a version that shows the current calendar year along with the previous and next year here (which is the version that I use).  Judging by the feedback, other people find this spreadsheet year planner helpful too – do let me know if you find yourself using it.

Author: "Martin Woodward" Tags: "Personal, excel, planning"
Send by mail Print  Save  Delicious 
Date: Friday, 25 Mar 2011 16:18

Professional Team Foundation Server 2010I’ve always wanted to write a technical book and when I started getting involved in Team Foundation Server I thought that this technology area might be my chance.  I was lucky enough to get involved with the Professional Application Lifecycle Management with Visual Studio 2010 book and contributed to the TFS chapters in that one – but I knew I had one more book in me.

Luckily, the ALM book was so popular that the publishers came back for more and so I was able to get involved in the book I’ve been wanting to write for the past 6 years.  Not only that, I got to work with Grant Holliday, Ed Blankenship and Brian Keller who are three of the people I regularly turn to for advice on TFS matters.  Having those guys on board made it hard when looking for technical reviewers but luckily Mickey Gousset and Steve St Jean agreed to help out and so the journey began in creating the TFS 2010 book which is now available on Amazon.com (both in paperback and Kindle versions) and available for pre-order on Amazon.co.uk.  As with the ALM book there is a DRM Free eBook available at the Wrox site if you prefer but I’ll also expect electronic versions to be available in all the popular eBook stores in due time.  One neat thing about buying the electronic version of the TFS Book for devices that have a color screen is that in many versions the diagrams and screenshots are in color (which helped me when talking about Branch Visualization or the build reports :-) )

vs2010alm_bookPeople have asked us what’s the difference between the ALM book and the Pro TFS book.  The ALM book was deliberately written as an overview to the huge amount of functionality available in the entire Visual Studio Application Lifecycle Management suite.  Though there are a couple of chapters, the Team Build one in particular, that get pretty technical – the Pro ALM book tries to keep things approachable by everyone.

The Pro TFS 2010 book is a deep dive on TFS.  We tried to make it so that you can pick up the book having never used TFS before any by the end of it not only know how to use TFS but how to administer a complex TFS instance and even use it to study for the TFS Administration exam.  I’ve learnt something from every single chapter in the Pro TFS book, but I would also hope that someone new to TFS could pick up the book and learn just enough to get going then come back for more over time.

Anyway – while I’ve seen the PDF version of the book and enjoyed reading the chapters contributed by my co-authors, I’m looking forward to getting my physical copy soon from the publisher.  If you happen to get a copy then be sure to let me know what you think.  If you wanted to splash out and get the complete reference set then my personal recommendation would be to get the ALM book, the TFS Book and the excellent Inside the Microsoft Build Engine: Using MSBuild and Team Foundation Build (2nd Edition).

Hope you enjoy it anyway – I’m proud of this one so looking forward with nervousness to see what the reviews are when they start coming in.

Author: "Martin Woodward" Tags: "Vsts, tfs, book, tfs2010, vsts"
Send by mail Print  Save  Delicious 
Date: Thursday, 24 Mar 2011 10:18

Team Explorer Everywhere World TourEd Thomson from the Team Explorer Everywhere team is going to be doing a tour of the mid-west and central United States in early April.  For those of you who don’t know Ed, he is one of the original Teamprise developers that came over to Microsoft after the acquisition and now one of the core developers on Team Explorer Everywhere.  He knows more about the inner workings of our Eclipse integration than anyone else on the planet.

While he’ll be speaking at a lot of user groups and Microsoft events in various cities, places are filling up fast.  However there is still some availability in a few cities.  If you are nearby or know someone who is then I encourage you to register and come along.

Austin TX

Minneapolis

  • Wednesday April 6 (Details soon)

Chicago

  • Thursday April 7 2:00pm – 4.30pm (Register)
  • Thursday April 7 6:30pm - 8:30pm (Register)

Milwaukee

  • Friday April 8 9:00am – 11:30am (Register)
Author: "Martin Woodward" Tags: "Teamprise, Vsts, tfs, tee, tfs, tfs2010,..."
Send by mail Print  Save  Delicious 
Date: Monday, 14 Mar 2011 09:34

One of the key things about your CI build is to ensure that is runs fast so that you have a very quick feedback loop to see if you have a good build or not.  Rob Maher has an interesting blog post up describing how he customized the build process to make use of the test impact analysis feature so that only the impacted tests are run as part of the CI build and then the full test suite run later. 

If your tests take a long time to run, you may wish to only run the tests that have been impacted by code changes checked in with the build (and of course run a full nightly build that executes all tests :) Unfortunately there is no out of the box feature to do this, so we need to edit our build xaml to do it.

TFS 2010 Build - Only run impacted testsRobert Maher

In Rob’s example he uses a nightly build process to baseline the test impact analysis – however this might be a good candidate for a Rolling Build set to run once an hour or so (I personally prefer builds to run when there is someone still at work able to fix a build process should it break).  Anyway, it’s an interesting read not only for the idea but also as a good example of some of the key techniques when customizing a build in TFS 2010.

Author: "Martin Woodward" Tags: "Vsts, tfs, teambuild, tfs, tfs2010, vsts"
Send by mail Print  Save  Delicious 
Date: Wednesday, 09 Mar 2011 06:38

As Brian Harry announced earlier today, it’s been a busy week already here.  Not only was Visual Studio 2010 SP1 released but so was Team Foundation Server 2010 SP1 and also the topic of this post, the Project Server Feature Pack.

For more information, see Brian’s Blog Post:

One thing that I wanted to add is that if you are going to be editing a work item in Eclipse and that work item has been configured to be integrated with the project server using the feature pack then you will need to upgrade your client to Team Explorer Everywhere 2010 SP1.  I’d recommend you upgrade to this release is you haven’t already because there is a lot of goodness there – but you’ll definitely want to do it if you are planning on installing the Project Server feature pack.

Author: "Martin Woodward" Tags: "Vsts, tfs, tee, tfs, tfs2010, vsts"
Send by mail Print  Save  Delicious 
Date: Tuesday, 08 Mar 2011 07:21

In my travels I often run into former Subversion users coming to Team Foundation Server and struggling to come to terms with the differences in the version control model employed by TFS.  Ed Hintz posted a recent blog post that is very good, but as someone who’s used many version control systems in the past (including Subversion) I’ve put together the following deck over the years that I use when giving people advance warning about the differences between the two.  I recently updated my deck based on the latest power tools release and including some of Ed’s points.  Speaking with a few folks at the recent MVP Summit it seemed like this deck might be useful for others so sharing it here:

Note that I’m just a developer who likes TFS so much he got a job working on the team.  I’m not a marketing person or anything so this is very much a pragmatic view as to why it is different and what you should watch out for – it assumes that you are already motived to want to move (i.e. there are no slides saying why TFS is great and why you might want to switch etc).  If you find this useful then feel free to use – if you make any improvements then let me know as I’m always keen to make it better.

Author: "Martin Woodward" Tags: "Vsts, tfs, svn, tfs, tfs2010"
Send by mail Print  Save  Delicious 
Date: Sunday, 06 Mar 2011 20:26

Hopefully you have heard the news by now that in February we shipped Team Explorer Everywhere 2010 SP1.  Brian Harry has a couple of great blog posts (here and here) talking about the headline features of what was added, but I wanted to follow up with some smaller features that I personally use every day that you probably didn’t know about.  Note that the features have been deliberately made somewhat hard to find as we’d currently class them as “power user” functionality, but I figure anyone bothering to read my blog comes into the power user category :-)

1: Links to Shelvesets

We have a lot of remote working in our team across three continents and so we find ourselves passing around shelvesets a lot.  We also use shelvesets for code reviews.  As our team is so geographically spread out that we’re actually in four different domains inside Microsoft (one for Redmond, North Carolina, Europe and Asia).  Therefore we find the best way to share a shelveset name is in the ShelvesetName;DOMAIN\Username syntax as that is fully qualified.  It’s also great to include a link to the shelveset in web access, that way you can quickly review a shelveset without having to pull down the files into your local workspace or even fire up an IDE.

To do this quickly, open the Unshelve dialog (by pressing the Unshelve button in the Pending Changes view), select the shelveset that you want to send a link to and simply use the keyboard shortcut for copy (i.e. Ctrl-C on Windows/Linux or Command-C on Mac).  Paste this into something that accepts HTML and you’ll get a fully qualified shelveset name including the link to web access.  Paste into something that just accepts text and you will just get the fully qualified shelveset name.

Getting a link to the shelveset name from the unshelve dialog

2: Query Results Copy/Paste

In the query results view, you can select a range of work items, right click and from the context menu select Copy Selected Results to Clipboard or Copy All Results to Clipboard.  If you paste them into something that just understands text then you get a tab delimited set of results but if you paste into something that understands HTML (such as Outlook, Word, Excel or things link Mail, Numbers, Pages on the Mac) then you will get a nicely formatted table of results including the column headers and links to web access.  We use this all the time when emailing work items around, especially if reporting process outside of the team where people might not have our project collection set up as a connection in VS or Eclipse but they still have access to our work items via web access (lots of people in Microsoft have read access to our work items).

3: Opening a Work Item in Web Access

We have a fully features work item editor in Eclipse, but some customers have different work item form layouts for Eclipse and for Web Access or perhaps you might want to view a web access version of the work item so that you can share the link with team members etc.  We added an “Open With…” option when you right click on a work item to allow you to pick which work item editor you wanted to use.  This is actually an extension point so people can add other editors that they might want to use instead of the one we ship with (for example, in future releases TaskTop could add an editor here and you could open the work item with their Task editor).  The default work item editor is now a preferrence that the user can adjust in the Eclipse preferences.  If this is changed then opening a work item in all of the places that we show work items in the UI will open it in the preferred editor.

Open With context menu on Work Items

4: Eclipse Project Specific Actions

There are a bunch of “power-user” version control actions that we only make available when you right click on an Eclipse Project in Package Explorer / Resource Navigator. 

  • Detect Local Changes – will examine your local disk for changes that you have not yet created pending changes for with Team Foundation Server.  This is useful if you have been working outside of Eclipse for some reason.  For example if you have edited a file by setting it read/write, if you have added a file etc.  This is functionally the same as going offline and then returning online.
  • Go Offline – sometimes you know that you are going to work offline from TFS (i.e. you’ve picked up your laptop and walked into a meeting room with no corporate wifi connection).  The Go Offline menu option will allow you to tell the Eclipse plug-in not to bother attempting to connect to TFS first but to just assume that you are offline.
  • Go Online – When you get back to your desk you want to reconnect to TFS so select Go Online.  This will connect you back up again.  It will perform a local change detection to try and help you sync up the changes that occurred since you went offline.
  • Disconnect Project Permanently – You may have bound a project to Eclipse but then decided that you don’t want Team Explorer Everywhere managing the files for you.  In this case you can disconnect the project from being bound with TFS for version control.  To reverse this operation (i.e to bind it again with TFS) then you go to Team, Share Project… and select TFS.  We will then automatically detect the working folder mapping is present in TFS and simply add the bindings back into Eclipse so that you see the TFS items in the team menu.

5: Label Decorations

In Team Explorer Everywhere we decorate the labels given to files and folders in package explorer.  However sometimes it is useful to have more information – for example if you use the “Switch to Branch” feature frequently then knowing what the server path a particular project corresponds to us very useful.  Therefore we added a bunch of label decoration preferences to allow you to customize.

Preferences, Team, Team Foundation Server, Label Decorations

 

Hope you find some of these power user features useful.  Remember these are all Eclipse specific – not in the Visual Studio user interface.  There are more to discover as well so take some time to poke around the preferences and the context menus and let me know what features you find invaluable.

Author: "Martin Woodward" Tags: "Vsts, tfs, tee, tfs, tfs2010, vsts"
Send by mail Print  Save  Delicious 
Date: Friday, 03 Dec 2010 12:54

A couple of weeks ago I was in Antwerp for a partner event and I also had the pleasure of meeting with a few customers from the Belgium and Luxembourg region.  One of the customers I spoke with was Network Research Belgium (NRB) who were doing some very interesting work and using Team Foundation Server 2010 for their heterogeneous development efforts.

Tom Mertens has published information on a Case Study just completed with them where they show how they have reduced the development costs by 10% using Team Foundation Server to develop software for .NET, Java, Cobol and PL/1.  For more information and for the English, French or Dutch versions of the case study see:

Author: "Martin Woodward" Tags: "Vsts, tfs, casestudy, tee, tfs2010, vsts"
Send by mail Print  Save  Delicious 
Date: Thursday, 02 Dec 2010 10:09

dnrOn Monday I was a little under the weather suffering from the winter tummy bug that is floating around at the moment, but my day was cheered up by a phone call from Carl and Richard over at .NET Rocks.  We had a catch-up chat as to what has been happening in the past year since starting work at Microsoft, talked about Team Explorer Everywhere and TFS in general.  Blame the fact that I hadn’t eaten for two days, but we jumped around a lot and covered a whole different bunch of stuff about Team Foundation Server and ALM in general. 

.NET Rocks #615: Martin Woodward Brings Team Foundation Server to Everyone!

Anyway, it’s always fun talking with the guys but hopefully it turned out to be an interesting enough podcast.  Let me know what you think!

Author: "Martin Woodward" Tags: "Podcasting, Vsts, tfs, podcast, tee, tfs..."
Send by mail Print  Save  Delicious 
Date: Thursday, 04 Nov 2010 00:41

On November 3rd, I had the pleasure of announcing Team Explorer Everywhere 2010 SP1 Beta at my session during Eclipse Summit Europe.  Thanks to everyone that came along to the session, and for all the follow-up discussions at the Microsoft area.  As promised, the slides for my talk are accessible below:

Author: "Martin Woodward" Tags: "Vsts, eclipse, ese, talk, tfs, vsts"
Send by mail Print  Save  Delicious 
Date: Thursday, 04 Nov 2010 00:15

Today, we have two things to celebrate.  First is the fact that we just released a beta version of Team Explorer Everywhere 2010 SP1.  Brian Harry has an excellent write up over on his blog.  I’ll be diving into more details of this release soon in some follow-up posts, but please give it a go and let us know what you think.

The second reason to celebrate is that today marks our one year anniversary at Microsoft.

Once the Teamprise acquisition was completed, the transition of the core development team to working in Microsoft has been a remarkably successful one.  I remember seeing some sobering facts from the Microsoft Mergers and Acquisitions people during our initial discussions explaining how un-likely it was that an acquisition would be successful.  We had several factors in our favor;  We joined a great team in the TFS and Visual Studio with management that were very supportive and committed to ensuring an excellent experience for Eclipse and Cross-platform developers.  When the core development team came over from Teamprise, our group was infused with some excellent talent from the existing TFS development group and so that really helped us get up to speed with the Microsoft way’s of working.  We also had some very tight deadlines to hit which meant the new team bonded very quickly around the common enemy of the impending TFS 2010 ship date. As we’d worked so closely with the team for many years as a partner (and with me as an MVP) we already knew the right people to talk to about technology stuff – the only hard bit was learning all the new admin tasks and processes that are in place inside Microsoft.

Despite the fact that we were close partners before, actually being part of the team is really helping the product shape itself in so many ways to become an even better solution for heterogeneous development.  I’m very hopeful that we continue to show this by our actions in what we have released since the acquisition and the shape of our releases to come.

I’ll always look back on the Teamprise experience and the people I got to work with in great fondness, but the future for Team Explorer Everywhere from Microsoft looks very bright.  Not only are we working well as an integrated team so soon after acquisition but people seem to like using our product – what more can you ask for.

Anyway, enough about us.  Please do give the latest release of Team Explorer Everywhere a try and let us know what you think.

Author: "Martin Woodward" Tags: "Vsts, teamprise, tfs2010, vsts"
Send by mail Print  Save  Delicious 
Next page
» You can also retrieve older items : Read
» © All content and copyrights belong to their respective authors.«
» © FeedShow - Online RSS Feeds Reader