Configuring visual diff and merge tools for git on Windows

There’s plenty of information available on the net for configuring your visual diff/merge tool of choice for git. However, a lot of it is out of date. As of Jan 2014 using git v 1.8.4 this is the concise guide to setting up your visual diff and merge tool(s) of choice.

Add the following to your .gitconfig. If you don’t know what that is go here.

   external = C:\\Program Files\\Perforce\\p4merge.exe
    tool = p4merge
[difftool "p4merge"]
    cmd = p4merge.exe $LOCAL $REMOTE
    prompt = false
    tool = p4merge
[mergetool "p4merge"]
    cmd = p4merge.exe $BASE $LOCAL $REMOTE $MERGED

I’m using p4merge by Perforce. It’s free and supports the git three way merge well. If you want to use any other tool of choice add it to your path and replace the references to the .exe accordingly.

| Leave a comment

Avoid storing Nuget packages in your Git Repository

Git is a fantastic version control system but it was never designed for storing binary files. They clutter the history and even if removed that history must still be maintained. Ideally a remote pull should be a fast and pain free operation; one of the core tenets of git is speed. Something that anyone who has spent any amount of time within TFS will appreciate.

The screenshot below shows the packages folder of a newly created ASP.NET MVC 4 project. I appreciate some of these are scripts but that’s 47MB (before adding any project specific packages such as DI or Mocking) of binary data your git repo needs to maintain history for, binary history that you’re unlikely to ever care about.

You may now be thinking “What if we need to revert to an earlier build?”.  You can still do this using the exact same binary versions as when you created the commit. Simply check out the commit and build the solution as normal. Your packages will be restored to the exact versions at the time of the commit because the packages.config file which defines the versions of those packages is stored in your repo.

Let’s fix this…

  1. Enable NuGet Package Restore by right clicking on your VS solution. This will as the name suggests ensure on build of the solution that all package dependencies are pulled in from the configured nuget repositories. What to restore is defined in the packages.config file which is stored in the root of each project in the the solution. As mentioned earlier these will be version controlled which is what allows us to always restore source and package dependencies for any commit in the history. More info on this feature is available on the NuGet website.

  1. Add the line packages/ to your gitignore file. This is the important bit and something a lot of people forget to do.
  2. Commit the changes to the repo.
  3. That’s it we’re done!

Make sure you do this BEFORE the initial commit to the repo.

| Tagged , | Leave a comment

CRM 2011 SDK Dependency Starter now on Nuget

Each time I want to create a quick project in Visual Studio to connect to CRM 2011 I head to the SDK and pull in Microsoft.Xrm.Sdk then the source code for the helper classes and finally resolve all the missing framework dependencies IdentityModel, DirectoryServices etc.  The latter being made considerably easier with Resharper.

I’ve been meaning to package up this process that I’ve now repeated far too many times and throw it up on Nuget.  I finally managed to find the huge 10 minute commitment it eventually took to get this done tonight.

Available on the gallery or to install the package in Visual Studio just open up the Package Manager console and type:

install-package CRMSDKDependencyStarter

or for those of us averse to typing you can shorten this with:

install-p [tab] crm [tab] 

| Tagged | Leave a comment

Taking Team Foundation Service for a quick spin

Having just watched Brian Keller’s talk at //Build online I decided to give the new Team Foundation Service offering a spin. It’s free for teams of up to five users and whilst in preview also free for larger teams. No confirmed pricing plans yet so let’s hope MS don’t go silly if they really want to complete with the likes of GitHub and AppHarbor.

Setup is an absolute breeze having just created an account with my Live ID I was able to create a Team Project and start creating tasks in seconds. Make sure you pick your org name carefully as it cannot be changed at a later date. It also forms part of your URL so company name will be the obvious choice over a specific project name.

Hooking into Visual Studio 2012 is equally easy using the Team Explorer dialog to add a new server you just enter your URL and you’ll be prompted for Live ID and you’re up and running. I just tried creating a task, pushing it to Outlook (2013) and following the link to view online and all went well. Having been through the pain of setting up an on-premise TFS environment including the SharePoint, SQL Reporting and Build Controllers this is a real step forward for smaller teams and I’ll definitely be digging in a lot more.

In an upcoming post I’ll be taking a closer look at the Azure Continuous Deployment Build Definition and comparing this with the new Continuous Deployment offering for GitHub and CodePlex integration introduced to Azure Websites recently.

If you want to try out any of the new Azure features head over to the Azure Website and sign up for the 10 free Azure Websites offering. Alternatively, if you’re a Microsoft Partner you can sign up for Cloud Essentials for your Azure access and whilst you’re there why not get on board with CRM 2011 Online and Office 365 partner access.

| Leave a comment

Windows 8 – Import pictures directly to a custom SkyDrive folder

If you want to import pictures from a camera or any other USB device straight to a custom SkyDrive folder you can’t do this using the Windows 8 Photo Application. By default it will import all photos to your picture library which won’t be linked to your SkyDrive folder. Whilst you can then upload the imported pictures to SkyDrive manually, this will duplicate the content, it’s far too time consuming and it will also incur the extra download from the SkyDrive servers to sync back with your local SkyDrive folder! There must be a better way.

I’ve fixed this by setting up my pictures library to point straight to the pictures folder within my local SkyDrive folder (which is stored on a second hard disk rather than my SSD where space is always at a premium). That way you’re importing from USB straight to SkyDrive all through the new Windows 8 Photo Application.

  1. Open Windows Explorer (Win + E)
  2. Move all of your pictures from Libraries\Pictures to the folder of your choice within your SkyDrive folder. For most people this will be the default Pictures folder you are provided with SkyDrive.
  3. Right click on Libraries\Pictures and select Properties

  4. Select the path to the current pictures folder most likely C:\Users\username_000. I don’t like the way Windows 8 creates these folder names when using Windows Live for your login.

  5. Click Remove
  6. Click Add
  7. Navigate to the pictures folder within your SkyDrive folder you just moved all your pictures to
  8. Click Include Folder

  9. Click OK.

  10. Click OK.

You now have the Windows 8 Photo Application importing directly to your SkyDrive.

You can also hide the Picture Library from the photo app as this is now just duplicating your SkyDrive folder. Open the charms menu (Win + C) inside the Photo App. Select Settings, Options and uncheck Picture Library. Alternatively you could setup a new “Local” picture library as I have done for importing/storing images you don’t want synced to the cloud.

| Leave a comment

Error when saving URL addressed record in CRM 2011 (Rollup 5)

If you’re on Rollup 6 or higher you can ignore this post.

I came across a problem today when loading a record using the URL addressable form feature as documented over on the Microsoft site here. The record would load fine but when I tried saved the record the page wouldn’t refresh correctly. I would end up with a disabled ribbon and no other page content! The save operation was however succeeding.

I traced this down to an exception being thrown from within the platform JavaScript code. It was making the assumption that the querystring value extraqs was available and calling string.startsWith()which was throwing the null exception.

If you take a look at the URL for any entity loaded via a hyperlink in CRM they all contain this parameter which is typically used to pass attribute values to a form so those values can be pre-populated on load. The value of this parameter must be URL encoded.

Here’s a contact loaded from the default Homepage grid:


Here’s the sample URL provided for loading an account on the MSDN article linked above:

Switching out the values in blue for environment specific values you’ll see that the record will load correctly. However, if you then make a change and click save the page will hang as show below.


Reformatting the sample URL as follows (bolded) will fix the issue when saving the record.


| Leave a comment

Custom Web Pages with CRM 2011 Look and Feel using knockout.js

In this post (it’s been a while!) I’m looking at building a custom html page (ISV hosted or otherwise) that looks as close as possible to the CRM lookup dialog. This will allow us to provide our users with a seamless experience when moving from OOB functionality to custom web pages as was needed on a recent project.

For those that would prefer to skip the how and why and just get the code it’s available on github. Simply plug your data into lookupForm.js along with optional actions for the buttons and away you go. How you choose to get the data into the viewModel is entirely up to you.

This is what we’re trying to reproduce, but outside CRM.

Unfortunately there aren’t any stylesheet or html resources available in the SDK to help us achieve this. There are a set of articles that discuss UX guidelines which are worth a read but none of this information is backed up by reusable templates.

What I needed was a stripped down version of the CRM lookup into which I could add my own code. I found a project created by Darren Lui on Codeplex that is essentially a screen scrape of the HTML and dependent stylesheets for the common forms. It’s a great start but it was missing a number of features I wanted.

Required Features


The pages in the template project are a copy of the actual html generated by CRM and therefore it’s a bit tricky to work out exactly where you need to inject your own content and markup into this. CRM 2011 relies heavily on tables for layout so any html purists out there may want to look away now.

Data Separation

I didn’t want to start doing string concatenation to build my html from the data. I wanted to be able to provide the dialog with my own data without having to touch the html and let it build out the page for me. Ideally this should be achieved without the dependency on a server-side framework (ASP.NET). To achieve this I used knockout.js, the MVVM JavaScript framework written by the incredibly smart Steven Sanderson. It allows you to produce a view model in JavaScript and bind this to your html through declarative bindings using the html 5 data-* attributes (don’t worry they’re fully backward compatible to IE6).


The stylesheets used in CRM are quite large and take dependencies on several server-side *.htc files (global.css is 245k incl. all the CSS sprites).

Strip out the html we don’t need from Darren’s template

This was a just a case of stepping through the code bit by bit removing sections and checking the effect of their absence. Not too difficult just quite time consuming. There are many nested tables used in CRM along with custom attributes and as I’ve already mentioned a lot of them exist to provide the rich user experience that I’m not trying to replicate here. Including the knockout bindings and some superfluous commented html the final page is approx. 172 lines rather than the original 492. The size isn’t the issue but the less unnecessary html we have in there in the first place the easier this is going to be for reuse and maintenance by other developers.

Add the declarative bindings (Yes, it’s a screenshot!)

The new container-less bindings available in knockout were used for generating the rows of data dynamically. The much pared down html for generating the data rows is shown below.

Create our View Model in a separate JavaScript file

I created this so that each area of the page that requires data or behaviour is configured on the view model. The code will hopefully be self-explanatory but essentially the column headings are dictated by the headings property, the data rows are in the entities property and the actions bound to the click of each button are bound in the actions object. At the time of writing, the disabling or hiding of buttons isn’t implemented but this will be easy to do using knockout and may well have appeared in the code by the time you read this.

Sort out the StyleSheets

The dialog uses styles from the following stylesheets:










These have all been parsed and the minimum styles required for the dialog have been exported to a single file called lookupForm.css. To reduce the number of dependent files further I’ve also base 64 encoded the button background images used so they are in-lined in the CSS. I’ve also removed all references to the CRM *.htc files.

The end result

Next Steps

  • Bundle this up as a CRM 2011 Solution.
  • Configurable or dynamic column widths based on the data in the column.
  • Due to the removal of all the htc resources the horizontal scrolling of the column headers doesn’t work. I need to look at the best way to re-implement this feature.


I’m not going to spend much more time on this as its application is pretty specific. In using it you’d need to consider the affect if CRM styles changes. It’s only been tested in IE which is fine at the moment but when the 2012 Q2 rollout drops with support for Chrome, Firefox and mobile you’ll need to consider the effort involved in updating this solution to work in those browsers. Having said this hopefully it will prove useful to others.


As I published this I’ve also added the ability to show or hide the checkbox and define an image for each row.

| 1 Comment