Use Visual Studio 2005 to build CRM Callouts!
You already can develop web services applications for CRM V3.0 using Visual Studio(VS) 2003 or 2005 (or any IDE that supports web service standards for that matter). This is because our web services uses WSDL standard that is platform and tool independent.
However, building Callouts for CRM V3.0 is officially supported only on VS 2003. The explanation is rather simple. CRM platform itself is built on .NET Framework V1.1 and VS 2003. The platform runs as part of the IIS process and Callouts are loaded in that process when web services are called. Common Language Runtime (CLR) does not support loading two versions of .NET code into the same process (from my old days at VS team there are a lot of reasons for that including complexity of versioning, isolation and upgrade, etc). So if you build and compile your Callout using VS 2005, the callout cannot be loaded by our platform and you get an error.
I have been asked by many partners why they can’t use VS 2005 to build their callouts so decided to carve off some time and try to find a solution for the problem and here we are. VS 2005 uses MSBuild which allows you to target different runtimes (e.g. .NET 1.1 or even a non Microsoft commanline compiler). However, the VS team hasn’t got around to integrate the MSBuild with the VS IDE "yet" (watch out for VS Orcas plans). This means that out-of-the-box you don’t see any features in VS IDE that lets you target different runtime versions. That is where this article becomes useful.
I have created a VS 2005 project template for Callouts which 1) Allows you to build, compile and debug your callouts in VS 2005 by leveraging MSBuild 2) It gives your coding a kick start by providing the basic files and template code that you need to build a callout solution.
The project template uses the a readymade .NET V1.1 target file provided by Jomo Fisher blog. It also includes the CRM callout library that you need to compile the callout and the methods that you need to override. I have wrapped the template in an MSI package so you can easy install it on your machine by right clicking on the MSI file and selecting “Install”. The install just copies the template files into your machine and you can later on uninstall the package by going to the control panel and using Add/Remove Programs ( the name of the package is “Microsoft Dynamics CRM Templates”).
So let’s get started:
1. Make sure you have Visual Studio 2005 and .NET 1.1 (runtime only) installed on your box (if you are on a Windows 2003 machine .NET 1.1 is already installed by default, if you are on XP or other versions of Windows, it is very likely that an earlier application has already installed the .NET 1.1 for you otherwise you can get it from here).
2. Download the attached MSI (CRMTemplates.msi) and right click on the file and select “Install”.
3. Click next through the installation wizard – Don’t change any of the default settings.
4. When the install is complete, open VS 2005 and from file menu select New -> Project. You should see the below screen in the New project windows. As you notice under CRM node there is a new Callout Library project.
5. Select “Callout Library” as your template, select a name for your project and click “OK”.
6. You will see a warning dialog telling you about loading a custom project template. Select “Load project normally” and click OK without changing the rest of the default values as shown below.
8. VS will create a new project for you. If you notice on the build configuration manager, you have a new selection “.NET 1.1” which enables you to build a .NET 1.1 assembly.
9. Select MyCallout.cs file. You will see that I have already included all the methods that you can override in order to build your callout. I have also included the library that you need to include in your project (Microsoft.Crm.Platform.Callout.Base.dll).
10. Build your callout and compile it. It should be compiled as a .NET 1.1 assembly. As you can see I have targeted the built dll to be dropped into a “.NET 1.1” folder.
Some interesting notes:
1. You can have a VS solution with multiple projects that have different runtime target. For example, you can create a CRM Solution in VS, add a callout project that targets .NET 1.1 and a Web service application project that targets .NET 2.0.
2. Workflow assemblies should compile and run fine using VS 2005 and .NET 2.0 (although not supported/tested) so you don’t need a target or template to build those assemblies. If I can get some more free time I might also build a new VS template for workflow assemblies.
3. If you prefer not to use my MSI, you can build your own template or create a different project type that targets .NET 1.1 using MSBuild and targets. Read Jomo’s blog (link above) on how to use MSBuild and targets to do this manually. It is not really hard but you need to learn a bit about MSBuild to get started.
4. Remember that you are using VS 2005 to build a VS 2003 library. Although you will be enjoying new VS 2005 IDE features, not all the new VS 2005 features can be used to compile your V1.1 assembly (e.g. Generics). The good thing is that the compiler should tell you if you are crossing the line.
Let me know if you found a bug in the MSI or have issues, otherwise happy coding….