Archive for the 'Technology' Category

One new book and two new videos

For those of you who follow me on Twitter, you’d be aware of my recent activities.

Professional Team Foundation Server 2013

The achievement I’m most excited and proud about is that I’ve published a book – Professional Team Foundation Server 2013!

Professional Team Foundation Server 2013

Professional Team Foundation Server 2013

As the saying goes, it’s available at all good bookstores, but to help out here are some links to the book on Wiley’s websiteAmazon, The Book Depository, and Booktopia. Of course if you’d prefer an electronic copy, there’s always iTunes, Google Play, and the Kindle store!

Tech Ed New Zealand

I also recently presented a couple of sessions at Tech Ed New Zealand.

My first session introduced the awesome new Release Management for Visual Studio tool. It gives you a great way to deploy your applications in a repeatable and predictable way. It’s great for organisations that care about stable releases, governance, and deploying their applications quickly.

My second (and favourite) session was about the many extensibility points available to you in Team Foundation Server. This is a topic I became interested in while writing the Extensibility chapter in the book. I was amazed by how many opportunities there were to extend and customize Team Foundation Server. With the release of the REST APIs early this year, those opportunities grew even further. I’m really excited about the possibilities this opens up!

If you’re interested in integrating Team Foundation Server or Visual Studio Online with your own applications, this session is definitely worth a watch.

Getting Git Commits with the VSO REST API

(Guest post by Drew Robson – our SSW TimePRO product lead)

​​​​​​​​With Visual Studio Online now supporting Git, ​​​​more developers are changing their source control repositories. What happens if an application you developed relies on the TFS Client Object Model to get information out of source control (e.g. changeset comments) and the developers start using Git?​

That’s where the new Visual Studio Online REST APIs come in. You can get a list of commits from your VSO Git repository with only a HTTP request.​ Let’s look at how to do this with C# and Visual Studio 2013. The below example gets all the commits for a particular user.

(This is based on Get started with the REST APIs and VSO Integration Reference)

You will need a method to execute the HTTP GET request.

private async Task<string> Get(HttpClient client, string url)
{
    var result = string.Empty;

    using (HttpResponseMessage response = client.GetAsync(url).Result)
    {
        response.EnsureSuccessStatusCode();
        result = await response.Content.ReadAsStringAsync();
    }

    return result;
}

And a method to set up the authentication and urls.

public async Task<IEnumerable<Commit>> GetGitCommits(string username, DateTime from, DateTime to)
{
    var result = new List<Commit>();

    using (var client = new HttpClient())
    {
        if(_settings.AuthType == AuthType.Basic.ToString())
        {
            var version = "api-version=1.0-preview.1";

            // Set up auth
            var parameters = Convert.ToBase64String(ASCIIEncoding.ASCII.GetBytes(string.Format("{0}:{1}", _settings.Username, _settings.Password)));
            client.DefaultRequestHeaders.Accept.Add(new MediaTypeWithQualityHeaderValue("application/json"));
            client.DefaultRequestHeaders.Authorization = new AuthenticationHeaderValue("Basic", parameters);

            // Get Git repositories
            var url = string.Format("{0}/{1}/_apis/git/repositories?",
                _settings.Url,
                _settings.CollectionName);
            var response = await Get(client, url + version);
            var repositories = JsonConvert.DeserializeObject<RepositoryCollection<Repository>>(response);

            // Get Git commits
            foreach (var r in repositories.Value)
            {
                url = string.Format("{0}/{1}/_apis/git/{2}/repositories/{2}/commits?committer={3}&fromdate={4}&todate={5}&",
                    _settings.Url,
                    _settings.CollectionName,
                    r.name,
                    username,
                    from.ToString("u"),
                    to.ToString("u"));

                response = await Get(client, url + version);
                var collection = JsonConvert.DeserializeObject<CommitCollection<Commit>>(response);
                if (collection != null
                    && collection.count > 0)
                {
                    result.AddRange(collection.Value);
                }
            }
        }
    }

    return result;
}

What about the classes RepositoryCollection, Repository, CommitCollection and Commit? These are the class representations of the JSON responses. See the SSW Rule Do you know how to easily get classes from a JSON response? to generate them.

Release Management for the Enterprise (with videos!)

Team Foundation Server has been a great tool for managing your development projects for some time. But while it’s been a great source control and work item management tool, it’s always lacked a bit in terms of managing the deployment cycle of your application.

Too often, deployments rely on Frank from the Infrastructure team studiously following a word document to make sure every step has been checked off. It’s error-prone to say the least.

There are two great tools that are changing that. Both give you highly repeatable and automated deployments, reducing the risk of an outage.

The first is a new tool from Microsoft called Release Management for Visual Studio 2013. Yes, that’s a long name. The product has been around for a while under a different name (InRelease), but was recently acquired by Microsoft to improve this area of their offering. It’s closely-integrated with Team Foundation Server and gives you the ability to control your releases and know exactly who did what. It’s great for enterprises.

If you’re lucky enough to be at Tech Ed New Zealand this year, I’ll be speaking about it on Wednesday afternoon. I’m yet to hear about Tech Ed Australia, but I’ll let you know when I know :).

The other tool is one I’ve been using for a while called Octopus Deploy. It gives many of the same benefits as Release Management, but isn’t as closely tied to the Microsoft infrastructure. That means you can use it to deploy nearly anything from nearly any source (not just TFS).

I’ve spoken about Octopus Deploy a couple of times in the past few months, so rather than go through the features on this blog, I’ll just show you the videos.

For a quick introduction, watch my conversation with another SSW developer and MVP, Danijel Malik, about Octopus Deploy:

I also presented at DDD Melbourne recently about Octopus Deploy, and why it’s a great tool to stop you “deploying like an idiot”:

I hope you enjoy the videos, and I’m looking forward to talking about the other great tool, Release Management, at Tech Ed NZ.

TFS Maintenance – cleaning up after yourself

It’s really important to have a TFS Master as part of your team.  As the TFS Master at SSW (amongst other things), I’m constantly looking out for best practices, improvements we can make, and problems we can avoid. In particular, we like to keep our Team Foundation Server nice and clean, making sure the devs have no abandoned changes or workspaces.

Periodically, I’ll send out an email to anyone who has files they haven’t checked in for a while as per our “Do you have a report to see who has not checked in?” rule. What I often hear back is that the files have been checked out in a workspace that no longer exists. In other words the files were edited, not checked in, then the computer was rebuilt or replaced.

So what can you do?

The best option is to remove any workspaces you no longer have access to. There are two ways to do this:

  1. Use the awesome Team Foundation Sidekicks product
  2. Use the Workspaces tool in Visual Studio

 

Option 1 – Using Team Foundation Sidekicks

  1. Download Team Foundation Sidekicks 5.0
  2. Connect to your Team Foundation Server
  3. Use the Workspaces Sidekick to find and remove any workspaces you no longer use

Using Team Foundation Sidekicks to remove Workspaces

Using Team Foundation Sidekicks to remove Workspaces

 

Option 2 – Using the Workspaces tool in Visual Studio

  1. In Visual Studio, go to File | Source Control | Advanced | Workspaces…
  2. Check the Show remote workspaces checkbox to see workspaces on every computer
  3. Select and click Remove for the workspaces you no longer use

Opening TFS Workspaces in Visual Studio

Opening TFS Workspaces in Visual Studio

The Workspaces Dialog in Visual Studio

The Workspaces Dialog in Visual Studio

 

Clearing out these abandoned workspaces will let the TFS server know you aren’t using those workspaces any more. Best of all, your TFS Master will be less likely to send out angry emails!

I’ve been awarded a Microsoft MVP in Visual Studio ALM!

Microsoft MVP logoA few days ago I received an email from Microsoft informing me that I’d been awarded an MVP for Visual Studio ALM.

While my participation in the dev community has been purely for the enjoyment and love of what I do, this has been a career goal of mine and something I’ve been working towards for a few years.  I’m super excited and humbled to have been awarded alongside many of the best guys and girls in the field.

For those unfamiliar with what this award means, the best information can be found at http://mvp.microsoft.com, but here’s a quick quote from the site:

The Microsoft Most Valuable Professional (MVP) Award is our way of saying thank you to exceptional, independent community leaders who share their passion, technical expertise, and real-world knowledge of Microsoft products with others. … Today, there are more than 4,000 MVPs worldwide. They represent more than 90 countries, speak over 40 languages, answer more than 10 million questions a year, and are awarded in almost 90 Microsoft technologies—reflecting the breadth of our products and our global communities.

Thanks must go to the awesome guys and girls I work with at SSW for their support, as well as to the many enthusiastic developers I interact with as an organiser of the Brisbane .Net User Group and DDD Brisbane.

Here’s to a great 2014!

 

How to change a Work Item’s type in Team Foundation Server

One of the most frequent questions I get asked when training a new team in TFS is how to change a Work Item’s type.  If the team is coming from Jira, I can almost guarantee I’ll get asked that question.

While you can’t change the type of an existing Work Item with Team Foundation Server 2012 and 2013, there’s a simple workaround that achieves the same result.

How to change a Work Item’s type

First, open the Work Item in Team Web Access and click this button: Copy Work Item Button

The Copy Work Item button in Team Web Access

The Copy Work Item button in Team Web Access

In the dialog, choose the Work Item type you want to change it to, and click OK.

Choose the Work Item Type

Choose the Work Item Type

Finally, go back to the original Work Item and change its state to an appropriate “closed” state. If you really want to remove all traces of the original work item, you can use the command line “witadmin destroywi” tool. I don’t recommend this!

You can perform the same tasks from within Visual Studio by right-clicking on the work item and choosing “Create Copy of Work Item”.

Visual Studio - Copy Work Item

Visual Studio – Copy Work Item

It’s a deep copy

If you look at the new Work Item, you’ll see that all of the detail and links have been copied across where there’s a corresponding field in the new type.

All related Work Items are linked, and even links to Changesets that applied to the original Work Item are copied.

Deep Copy of Work Items

Deep Copy of Work Items

This tip can be really useful for Product Owners who like to create “bugs” that don’t fit your bug definition and are really new requirements.

So there you have it, a way of “changing” the type of a Work Item that should please those Jira converts!

The new, shiny goodies in Visual Studio and TFS

I recently spent a couple of weeks speaking at Tech Ed Australia and Tech Ed New Zealand with Adam Cogan.  You can see recordings of the Tech Ed Australia sessions or the Tech Ed New Zealand ones on Channel 9 if you want the full presentation.

In this post, I wanted to specifically point out a few of my favourite Visual Studio ALM features from our sessions.

Visual Studio IDE – Peek

When I’m reading code, I’m used to jumping around between files to find definitions and usages using key combinations like F12, Ctrl+F12Shift+F12, Ctrl+-, and Ctrl+Shift+-.  Peek adds yet another key combination – Alt+F12 – to the mix, and it’s an awesome addition.

When your cursor is in the right place, just hit Alt+F12, and the definition will expand below.  Even better, you can edit it inline!  Just hit Esc when you don’t want to see it any more.

Visual Studio 2013 - Peek

Visual Studio 2013 – Peek

This small thing has already saved me so much time while coding.

Visual Studio IDE – Code Lens

When you open a project in Visual Studio 2013, you’ll notice a couple of additional bits of text above things like class methods and properties.  These code lens helpers let you see at a glance, some really important information about the method or member below.

You’ll see:

  • References
  • The number of tests that touch this code
  • TFS information about this code including recent changes and associated work items

Hovering over these bits of text (or using shortcut keys Alt+1, Alt+2, etc.) expands this information and gives you the opportunity to run tests or navigate to code, TFS changesets, or work items.

Visual Studio 2013 - Code Lens

Visual Studio 2013 – Code Lens

This is incredibly powerful.  You can see immediately how this code is being used and what has happened to it. without needing to leave your code.

Team Foundation Service – Test Case Grid View

This feature is brand new (only a couple of days old) so we didn’t get a chance to announce it at Tech Ed Australia.  A demo will be in the Tech Ed New Zealand video when it’s live.

There’s a new option in the Test hub in Web Access where you can change the view of your Test Cases to “Grid”.  Just click on the View item on the right.

Team Foundation Service - Test Grid View

Team Foundation Service – Test Grid View

Team Foundation Service - Test Grid View

Team Foundation Service – Test Grid View

What’s amazing about this view is that you can paste straight from Excel!  If that doesn’t make your testers happy, nothing will!

Team Foundation Service – Team Room

The addition of a team room to TFS adds some awesome collaboration features to Web Access.  It’s particularly useful for remote teams (which I work in a lot).  Rather than just a chat room though, it can feed you information about your project.  You can see build completions, changes to code, and updates to Work Items.

Team Foundation Service - Team Room

Team Foundation Service – Team Room

The faster release cadence of the ALM team has meant much faster additions to Team Foundation Service. If I can suggest one thing, it’s to move your ALM process onto the cloud because there’s much more to come!

There are many more great features in VS and TFS 2013.  I encourage you to take a look.

VS 2013 – Packed Rooms at Tech Ed Australia and New Zealand

Developers are very excited to get their hands on Visual Studio 2013!

I’ve spent the last couple of weeks speaking at Tech Ed Australia and Tech Ed New Zealand with Adam Cogan.  We’ve been demonstrating the awesome new features in Visual Studio 2013, as well Team Foundation Server and Microsoft Test Manager.

Watch the recordings of the Tech Ed Australia sessions on Channel 9.

Note: At time of writing, one of the videos is unavailable. It should be online for viewing by midday 13th September.

Update: Both videos are available now

Channel 9 - Tech Ed Australia - My Sessions

Channel 9 – Tech Ed Australia – My Sessions

The rooms at Tech Ed Australia were packed!  About 450 developers came to see the two sessions showing just how popular the Visual Studio ALM stack is.

In my next post, I’ll go through some of the highlights of the two sessions.

Glimpse Heads Up Display released

Today, Anthony van der Hoorn and Nik Molnar announced the release of a new version of Glimpse with a big new feature – the Heads Up Display.

I’ve been lucky enough to see this new feature grow into its current form and in my opinion, it takes this tool from the “very useful” category into the realm of “must have”.

SSW has been recommending Glimpse for some time.  With the addition of this feature, we now recommend you use it all the time!

The New HUD

Assuming you’re familiar with the previous version of Glimpse, you’ll know that once it’s set up and turned on, you see a small icon on the bottom-right of your screen (Old Glimpse Icon).  Clicking it will expand a big devtools-esque view of what’s happening on your server.  Incredibly useful.

I often keep Glimpse running while I’m in development, and whenever I want to know about what route was hit or how many SQL queries were executed for this page, I’ll click the icon and have a look.

The point is, I have to look.  Glimpse required the developer to actively investigate.  The new Heads Up Display changes the game – now I don’t have to be looking for the cause of a problem, the information is there all the time.  You now have a very powerful and proactive tool at your disposal.

Example Time!

I frequently use Glimpse to verify that a page I’m looking at doesn’t suffer from the dreaded N+1 Selects problem you can get with a lot of ORM tools.  The SQL tab (see Glimpse.Ado and Glimpse.EF) let me see what queries are being run against my SQL server.  If I see a lot, there’s likely to be a problem.

With the new Glimpse HUD, that information is always there whether I’m actively looking for it or not.  While testing one of the pre-release versions of the HUD, I noticed a page on a project I was working on that resulted in 74 SQL queries.  Had I been using the old version of Glimpse, I may not have noticed (I wasn’t working on that page)!

Here’s what I saw (minus the issue):

New Glimpse HUD

Above, you can see the number of Database queries and the time taken for those queries.  In my case, I noticed this number was a really high.  To  investigate further, I can hover over the “Host” section to get some more info.

New Glimpse Expanded

In this example, we can see that not only were there three queries, we actually have three connections.  In my case, the 74 queries were shared over maybe a dozen connections.  Something was going wrong here.  You’ll note we can see lots more information about what’s going on in terms of Controller Actions and Views as well.

As with previous versions, we can click the (new) Glimpse logo to expand Glimpse into its full view, showing us the actual queries that were run against the database.  The UI here has been updated as well and is very clean and “metro-y”.  This is where I could see all the repeated queries that were running against my SQL Server.

New Glimpse Full View

Without the HUD, I probably wouldn’t have noticed there was a problem until much later.  Because the HUD gives me this info in a relatively subtle way, I caught this issue quite quickly.

Summary

Glimpse now has three modes of delivering you data instead of just the one, and the HUD is the big game-changer here.

First, you get a Heads Up Display (HUD) that I’d strongly recommend you keep open at all times while developing.  It lets you monitor the performance of your application without getting in your way.  More importantly, it’s likely to show you issues preemptively rather than waiting for you to investigate.

If you hover over one of the HUD sections, it expands to give you even more info – this lets you investigate a bit further while still staying out of your way for the most part.

Finally, the full view of Glimpse gives you the UI you’re probably used to if you really want to dig deep.

Get it now!

The new version of Glimpse is live on Nuget, but if you want to read more about the new release, head to getglimpse.com or the blog post on the Glimpse Blog.

Getting the Glimpse SQL tab working with Linq to SQL

I’m currently working on an ASP.NET MVC project that’s using Linq to SQL for data access.

As usual, one of my first contributions was adding Glimpse (including Glimpse.MVC4 and Glimpse.Ado), initially as an easy way to confirm my suspicions of the dreaded N+1 problem.

Unfortunately, when I ran it, the SQL tab in Glimpse gave me nothing – Glimpse wasn’t tapping into my data connection.  The issue is Glimpse attaches itself by providing its own GlimpseDbProviderFactory which wraps the standard ones.  This lets it collect information about how you’re using your data connections. Our Linq to SQL implementation wasn’t using this factory so I had to do the work myself.

Here’s how I fixed this issue.  Even if you’re not using Linq to SQL, the solution is fairly generic, so you might find it’ll help you as well.

First, I found the generated Data Context class.  It should be in the .designer.cs file for your dbml.

[global::System.Data.Linq.Mapping.DatabaseAttribute(Name="MyApp")]
public partial class MyAppDataContext : System.Data.Linq.DataContext
{
    private static System.Data.Linq.Mapping.MappingSource mappingSource = new AttributeMappingSource();
    
#region Extensibility Method Definitions
    // snip
#endregion
    
    public MyAppDataContext(string connection) : 
            base(connection, mappingSource)
    {
        OnCreated();
    }
    
    public MyAppDataContext(System.Data.IDbConnection connection) : 
            base(connection, mappingSource)
    {
        OnCreated();
    }
    
    // snip
}

The highlighted lines represent two of the overloaded constructors that can be used to create a context.

Our project had been using the first one by passing in a connection string. To resolve the issue I’m having, I’m going to use the second constructor, passing in our own IDbConnection.

I need to change this:

var context = new MyAppDataContext(ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString());

to this:

var context = new MyAppDataContext(
    new GlimpseDbConnection(
        new SqlConnection(ConfigurationManager.ConnectionStrings["MyConnectionString"].ToString())
    )
);

After pressing F5, everything worked beautifully and we started seeing our SQL queries come through.

All that’s happening is that we’re manually wrapping our connection in a GlimpseDbConnection. In short, if you have control over the creation of the IDbConnection, you can get Glimpse working with very little fuss. Of course, you’ll need to include Glimpse.Ado in the project that calls this constructor.

I’m sure I don’t need to tell you that you should be using Dependency Injection to inject your IDbConnection where required, making it even easier to implement!

Next Page »