»

Introduction

Microsoft Dynamics 2011 has made deployment of customisation much easier than pervious version. However there are some technical limitations you face when using Microsoft Crm Online such as not being able to install stuff on the server (such as putting dll’s in the GAC). One of the great features of the framework is the Early Bound Entity code generator. It is useful to put this in a separate project so it can be re-used across other projects, such as the Plugin and Workflow projects. However to deploy this solution structure to Online you need all the code compiled into a single assembly. This post describes how I solved this problem allowing me to have a common project with business logic shared between the assemblies that get deployed.

The project used in this post

I run a small software company called See The Link. The project I am using as an example is one done for one of my clients that we did a ]Dynamics Crm Online solution for. <plug> i’m always looking out for new business - if you want to hire me please get in touch!</plug>

Solution Setup

This is the solution setup I have. It is based on the Dynamics 2011 toolkit template for Visual Studio 2011. As you can see I have a project for plugins, SeeTheLink.Visalogic.Crm.Plugins, and another project for Workflows, SeeTheLink.Visalogic.Crm.Workflow, (I realise that custom workflows cannot be deployed online yet but will be coming in Q2 this year). The early bound entities have been put in the “SeeTheLink.Visalogic.Crm.XrmEntities’ project. The last important project is the CrmPackage, this project is created by the dynamics template. I don’t understand all the voodoo that this project type does by it is responsible for deploying the assets to the target Dynamics solution. This is where we need to tap into to make it merge the assemblies before it deploys them.

We need to take copies of these files so we can edit the targets per solution otherwise it will happen for all solutions built on the computer. Copy these to a folder just below the solution, I called mine “Tools”

Also put ILMerge.exe in there as well. This is the magic tool that does the merging for us. In the above screenshot I have my solution in the DynamicsSolution folder.

Step 2 – Edit the Microsoft.CrmDeveloperTools.CrmClient.targets file

Edit the in file. Find the <Target Name="BeforeDeploy"> tag. Here we put in the command to use ILMerge command:

The ‘PluginMergedOutputName’ is what the output or the merge will be called. It is therefore important to update the RegisterFile.crmregister file. We will do that after we have reloaded the project:

Step 4 – Edit the RegisterFile.crmregister file

In the CrmPackage project there is a file called RegisterFile.crmregister. This contains all the references to the plugins that are required for the deploy project to register the dlls. We want to register the merged file so we have to just rename the reference:

Step 5 – Deploy!

When you deploy the package you will see the new steps in the build output

A couple of gotchas

If you are registering the same plugins just in a dll with a different name then you will need to un-register any dlls already deployed.

You will also need to add

[assembly: Microsoft.Xrm.Sdk.Client.ProxyTypesAssemblyAttribute()]

to the AssemblyInfo.cs file of the plugin and workflow assemblies so the early bound entities work.

In summary

This allows for having common / other files merged into a single assembly that can then be deployed. This allows for more advance features to be included in Online installations where it is not possible to install 3rd party dlls on the server.

I have been to a number of charity coding events over the last few years. Craig Hogan has just asked people for their ideas on how he might run the second Dev4Good event this year, so here my top 6 things I like to get out of these events with my idea on how to implement them.

Why I enjoy these events

Using my imagination on how to solve a problem. I truly love doing this, being given a problem and trying to solve it in a way that using various tools and services that are out there and I know how to use. Sometimes what I think is easy and straight forward is complete magic for non technical people.

Creating a working solution. Actually creating something that adds value to a charities efforts and is actually used. As these events are short the scope of the solution has to be small for it to be successful.

Meet interesting people – The type of person that goes to these events and donate their time are good people. The fact they are there and you are there makes it a pretty high chance you will be ‘liked minded’ with similar interests and a lot to talk about.

Winning a competition – I’m quiet a competitive person and have always enjoyed working towards winning. This is something that PayPal’s charity hack event is very good at, they have different categories and a judging panel which makes it a real competition. They do have great first prizes in the categories which is a bonus BUT I would be very happy just having my name up in lights on the event’s website for bragging rights!

Learning something new – it is not often that you get to mingle with a wide variety of other coders who are willing to share and show you how they work, equally I get a lot of satisfaction showing others new techniques and tools as well.. Getting a good opportunity to cross pollinate this knowledge is fantastic.

Getting the T-Shirt – Getting swag is always a bonus at these events, but usually I have already got all the tools in my tool bag to do my job, I can go out and buy it. However there is one thing that you cannot buy – the Event’s T-Shirt. Long after the event has finished and possibly forgotten about, I often pull on an event T-Shirt and it brings back all the memories in an instant. I love it.

What I would do for my event

Have a large collection of problems or goals from charities (Points 1,2 & 4)

To achieve items 1, 2 and 4 I would try and collect the problems that charities have. Not just a few problems, lots and lots of them no matter how big or how small.

One of the recurring issues I have hear from event organisers is trying to get charities to engage with the event. To solve this I would partner up with organisation that deal with lots of charities, like JustGiving.com, and ask them to question the charities about ‘what is your pain’. It might be they need to be able to bulk e-mail, better analytics on their website, needing to raise more awareness of their brand, who knows. I believe by making the only effort by the charities to describe ‘their pain’ means it will only take then a few minutes of their time and a few sentences to submit an idea. There is no expectation on their half they will get anything and if they do they will be really happy.

Now we have a large pot of problems we can put them up on a “Problem Board” at the event and just let people pick the ones they would like to do. No direction about technology or implementation will be given (other than competition categories if they want to win a prize), leaving the developer to use their imagination (Point 1 solved). They might even create some working solutions (Point 2 solved) and then you can judge who created solutions that fit the different categories to have some winners (Point 3 solved).

Learn something new and getting the T-Shirt (Points 3, 5 & 6)

If possible have a social event the night before coding starts, hand out the T-Shirts, put up the “Problem Board” and let people meet and discuss how they might do things over a few beers and food in the evening. This should really help people meet each other in a relaxed environment which is the best thinking happen. It would be nice to have a way to identify what skills other people have. Name badges with skillset and twitter / linkedin details would be useful to solve this.

I would also had a period of de-brief and reflection after the event. It can be a full on experience with little sleep and lots of effort and emotion going in. People love to talk about how it went for them afterwards. I know my wife will never properly appreciate what I’ve been doing so having an opportunity to talk to people that went through it with me afterwards is really great. GiveCamp had a hog roast and a couple of hours of down time before the presentations which was perfect and really enjoyable.

In Summary

Every event I’ve been to has it’s own character and charm. Letting me use my imagination to add value and meet new people makes it very enjoyable for me. I have really enjoyed every event I’ve been to and you never know, perhaps some of these ideas might be adopted by Craig for this years Dev4Good!

I recently did a talk at DevEvening about how I managed to using Amazon’s Simple Email Service with my (fairly) new website The Gig Market and I thought I would just share a bit more information about it if anyone was interested.

The Problem

As the website is hosted on Windows Azure there is no hosting mail server that I can use to send out emails. The answer is to use a 3rd Party service to do this for you. I had been using a company for 3 years for my other websites to do this and had been very happy with them…. until I breached the send limit one month and they just stopped sending emails. This really annoyed me so I set about to find a better service. What I found was AWS’s SES which only costs $0.10 per 1000 emails, the problem was it is a webservice, not an smtp server, so I couldn’t just change the smtp server in my app’s settings.

The Research

What I wanted to do was to tweak my code to use SES api. To limit the impact I only wanted to change the:

SmtpClient smtp = new SmtpClient();
smtp.Send(mailMessage);

code to something that could just send the mailMessage object to Amazon SES. The problem is that out of the box the .Net MailMessage object can only be used with the .Net SmtpClient. doh.

This post by Neil Deadman was a great article and I thought I had found my solution BUT there was a big big problem. I needed to send BCC and set the priority of the email. It turned out that I could not achieve this using the solution. So what could I do?

The Solution

I ended up hitting the Amazon docs and discovered that I would have to send a RAW message format and I would also have to write the email out by hand in MIME format. I thought this would be hard but it turned out to be pretty easy, I knocked up an extension method on the MailMessage class to do this for me.

So I have been very busy this year and have not had time to blog anything. Now I find myself at the www.dev4good.net event and needing to show people on my team how to get the tools needed to use Git effectivly installed and running on their computers.

This post is just a short instruction set on how to do this and could be of use to others!

Tools to download

»

I was kindly given the opportunity to give a talk to the DevEvening crowd about my experiences with using PayPal’s Adaptive Payment services.

These Adaptive Payment services offer some very interesting and useful ways to collect and distribute money on the Internet, which is very important if you want to make a living with an online business!

My experience with the the Api was implementing a Chained Payment system on my Training Course Booker website to collect and distribute money to Training Providers that use it. There are lots of other uses, to find out more please visit PayPal’s developer website x.com and / or have a look at my slide deck below.

On my current Microsoft Dynamics Crm project we have done a lot of customisations, both creating custom pages and manipulating the existing crm pages via the OnLoad method. This post describes a method of ensuring the load order plus the benefit in increasing performance compared with loading multiple external JavaScript files the more conventional way.

The existing approach

One of the big problems we faced was making sure that the JavaScript files load in a specific order. This is because we have got some common functions in a file which can be re-used in multiple pages. These need to be loaded before the main page JavaScript file which might call one of the common functions.

There are a number of good blog post about this topic so I won’t go over this ground again. Here are a few articles I’ve found:

What is different with this new approach

The solution that I propose here was the brainchild of @njwatkins who came up with the idea of implementing at generic .net http handler as part of our custom webpages proejct that would read in the various external JavaScript files, in the correct order, compress them and then stream them back to the browsers as a single JavaScript file.

Unfortunately I cannot post the source code of the handler we use on this project here but a google round on topics like Gzip and StreadReaders and Handlers should enough to get most developers to a solution.

The contact.ashx file is the handler that does all the work and where you would define which JavaScript files to include and does the merging and compressing. It means you only need to load one external JavaScript reference and you can guarantee which order they external files will be loaded.

Other benefits of this approach is that you can control things like caching length which can be a problem when changing and deploying new external files to clients. We achieved a significant saving on load time of the javascript from 900ms down to 200ms using this approach and we have ideas on how to improve it further but this is as far as we have got today!

»

If you follow my blog you will hopefully be well aware of my involvement with the Windows Phone 7 development community in the UK. I was fortunate enough to be invited to the launch party of the phone in London as well as present demo’s of apps I’m developing to London’s Windows Phone User Group.

‘The short’ of the post is if you want to be compliant with Microsoft’s stying guidlines watch this video about some templates they have developed and made available for free download for Windows Phone Development. Please read to the end of the article for ‘'the long’ of my thoughts!

One of the things which is a building block of Microsoft’s vision of Windows Phone 7 (WP7) is a consistent feel to applications that are developed and put into Marketplace. This is why the developed Metro as well as spending a lot of time and energy into creating detailed design guidelines for developers to follow. The problem is the majority of developers are more interested in writing code that reading design documents, are more interested in getting async callbacks to work than making sure the pixel spacing is correct between their labels and textboxes. Unfortunately for techies spacing and nice looking UI is as important to you app as the technical solution (developers are just a cog) To help us coding slaves Microsoft have kindly developed some Blend templates that implement the UI design templates, these can be copy and pasted into your solution for free.

I had a great time, met a load of interesting people doing interesting things for Windows Phone 7 and I managed to get a few sound bites of video from some of them which I have edited together for your viewing enjoyment!

My Windows Phone 7 Developer launch party experience!

Many thanks to @will_coleman and his team for making everything happen and I am really looking forward to the future!

»

I’ve just discovered something that I really really don’t like about Microsoft CRM 4. This is that creating some custom workflow activities that are used in a Crm Workflow means they are linked together forever and ever by version numbers.

I was getting this error message:

After some investigation it turned out that it was because I had changed the version number of the assembly that contained the custom workflow activities which meant that I could no longer publish the workflows that use them. When I try I get this error message.

The answer is to manually set the version number of the dll back to what it was when the workflows were originally published which is just silly.

We have recently upgraded our development environments on my project to match the production environment which is running on a 64bit servers. There was a big gotcha which was the delayed signed dll’s in the dev environment were chucking a “Strong name validation failed” error when they were accessed.

There are well documented solutions around using the following command

SN.exe -Vr *,*

However this did not work on the 64bit computer because SN.exe is a 32bit program and put the entry in the 32bit part of the registry. So I moved the registry key this tool enters and put it in the 64bit part of the registry and then everything worked.