Category Archives: CRM 2011

Dynamics CRM Parallel Development with Solution Packager

The Solution Packager is a very useful tool that has been released with Dynamics CRM 2011 Update Rollup 10 and is currently also available in Dynamics CRM 2013 Sdk. Traditionally you can only move CRM components around between two environments using CRM Solutions. You will soon start to see the limitations of this if you are doing one of the below:

  • You are working on a team where each developer has their own virtual machine or CRM organization for isolation purposes
  • You are on a project with one or more parallel streams of work where each stream has their own environment and different release schedule but working on the same CRM Solution

In all of the above cases you will need to bring all the pieces together once the work is ready and release them into your main CRM environment for testing or further packaging as CRM solutions. You will find that the only way to merge these changes with the existing solution is to place your changes into a new/existing solution and deploy that to your main CRM environment that contains the existing changes (Note these could have moved on since you started to work your specific feature). Below are a few issues you might encounter with that approach:

  • When you deploy the CRM Solution containing your changes this might potentially override customizations that are already in there. You might end up re-doing some of work manually in two places.
  • It is difficult to track what changes were made to implement that specific feature. You can track your source control items such as JavaScript files and CSharp code files but not your CRM customisations such as changes to data model, workflows, user interface and others.

The solution packager allows to extract your customizations from your own/team environment after you are done with a feature and check-in your changes into source control along with changes you have made to the files that are normally in source control such as JavaScript & other code files for your plug-ins for example. By default when you run the extract operation this will include everything that is contained in the solution zip files so it will include things like your plug-in assemblies and JavaScript that you already have in source control. The solution packager allows you to provide a mapping file so that during the extract operation it can skip the files you already have in source control and use the files you already have in source control and use the newly complied assemblies from the latest source code. Below is a diagram so you can picture this.

Extract Solution

To help make this easier I have created a sample PowerShell script that automates some of the activities discussed above.This is included in the latest xRM CI Framework along with the required assemblies. This script will do the below.

  • Check-out your existing extracted files from TFS (optional)
  • Export your managed and unmanaged solution from CRM
  • Find the deltas and mark the files under TFS with add/delete/check-out accordingly
  • Check-in the updated files back into TFS (optional)

You can use the sample script below and make any changes as required. Don’t forget to download and install the assemblies for the xRM CI Framework or plug-in your own utilities.

Code Snippet
  1. # Filename: ExtractCustomizations.ps1
  2. param([string]$solutionPackager, #The full path to the solutionpackager.exe
  3. [string]$solutionFilesFolder, #The folder to extract the CRM solution
  4. [string]$mappingFile, #The full path to the mapping file
  5. [string]$solutionName, #The unique CRM solution name
  6. [string]$connectionString, #The connection string as per CRM Sdk
  7. [switch]$checkout, #Optional – pass if you want to Check Out the existing files in the extract location
  8. [switch]$checkin) #Optional – pass if you want to Check In the updated files after extraction
  9. $ErrorActionPreference = “Stop”
  10. Write-Host “Solution Packager: $solutionPackager”
  11. Write-Host “Solution Files Folder: $solutionFilesFolder”
  12. Write-Host “Mapping File: $mappingFile”
  13. Write-Host “ConnectionString: $connectionString”
  14. Write-Host “Check In: $checkin”
  15. Write-Host “Check Out: $checkout”
  16. # CI Toolkit
  17. $scriptPath = split-path -parent $MyInvocation.MyCommand.Definition
  18. $xrmCIToolkit = $scriptPath + “\..\PowerShell Cmdlets\Xrm.Framework.CI.PowerShell.dll”
  19. Write-Host “Importing CIToolkit: $xrmCIToolkit”
  20. Import-Module $xrmCIToolkit
  21. #TF.exe
  22. $tfCommand = “C:\Program Files (x86)\Microsoft Visual Studio 11.0\Common7\IDE\tf.exe”
  23. #Check Pending Changes
  24. $pendingChanges = & “$tfCommand” status /recursive /noprompt “$solutionFilesFolder”
  25. if ($pendingChanges -like “*no pending changes*”)
  26. {
  27.     Write-Output $pendingChanges
  28. }
  29. else
  30. {
  31.     Write-Output $pendingChanges
  32.     Write-Error “Pending Changes Detected. Undo your changes and try again.”
  33.     return
  34. }
  35. #Before Files
  36. [string[]]$beforeFiles = [System.IO.Directory]::GetFileSystemEntries($solutionFilesFolder, “*”, [IO.SearchOption]::AllDirectories)
  37. Write-Host “Before Files: ” $beforeFiles
  38. #Check Out
  39. if ($checkout -and ($beforeFiles.Length -gt 0))
  40. {
  41.     & “$tfCommand” checkout /recursive /noprompt “$solutionFilesFolder”
  42. }
  43. #Export Solutions
  44. Write-Host “Exporting Solutions to: ” $env:TEMP
  45. $unmanagedSolution = Export-XrmSolution -ConnectionString $connectionString -Managed $False -OutputFolder $env:TEMP -UniqueSolutionName $solutionName
  46. Write-Host “Exported Solution: $unmanagedSolution”
  47. $managedSolution = Export-XrmSolution -ConnectionString $connectionString -Managed $True -OutputFolder $env:TEMP -UniqueSolutionName $solutionName
  48. Write-Host “Exported Solution: $managedSolution”
  49. #Solution Packager
  50. $extractOuput = & “$solutionPackager” /action:Extract /zipfile:”$env:TEMP\$unmanagedSolution” /folder:”$solutionFilesFolder” /packagetype:Both /errorlevel:Info /allowWrite:Yes /allowDelete:Yes /map:$mappingFile
  51. Write-Output $extractOuput
  52. if ($lastexitcode -ne 0)
  53. {
  54.     throw “Solution Extract operation failed with exit code: $lastexitcode”
  55. }
  56. else
  57. {
  58.     if (($extractOuput -ne $null) -and ($extractOuput -like “*warnings encountered*”))
  59.     {
  60.         Write-Warning “Solution Packager encountered warnings. Check the output.”
  61.     }
  62. }
  63. #After Files
  64. [string[]]$afterFiles = [System.IO.Directory]::GetFileSystemEntries($solutionFilesFolder, “*”, [IO.SearchOption]::AllDirectories)
  65. Write-Host “After Files: ” $afterFiles
  66. #Get the deltas
  67. $deletedFiles = $beforeFiles | where {$afterFiles -notcontains $_}
  68. $addedFiles = $afterFiles | where {$beforeFiles -notcontains $_}
  69. if ($deletedFiles.Length -gt 0)
  70. {
  71.     Write-Host “Deleted Files:” $deletedFiles
  72.     $_files = [System.String]::Join(“”” “””, $deletedFiles)
  73.     & “$tfCommand” undo /noprompt “$_files”
  74.     & “$tfCommand” delete /noprompt “$_files”
  75. }
  76. if ($addedFiles.Length -gt 0)
  77. {
  78.     Write-Host “Added Files:” $addedFiles
  79.     $_files = [System.String]::Join(“”” “””, $addedFiles)
  80.     & “$tfCommand” add /noprompt “$_files”
  81. }
  82. # Checkin
  83. if ($checkin)
  84. {
  85.     & “$tfCommand” checkin /noprompt /recursive /override:”PowerShell Extract” “$solutionFilesFolder” /bypass
  86. }
  87. # End of script

Below is also a sample script that invokes the script above with some predefined parameters to get you started.

Code Snippet
  1. & “C:\Program Files (x86)\Xrm CI Framework\CRM 2013\PowerShell Cmdlets\ExtractCustomizations.ps1” -solutionPackager “C:\workspace\CISample\Src\Sample2\Lib\CrmSdk\solutionpackager.exe” -solutionFilesFolder “C:\waelcrm2013\CISample\Src\Sample2\SolutionFiles” -mappingFile “C:\workspace\CISample\Src\Sample2\LocalSolutionPackagerMapping.xml” -solutionName “Sample” -connectionString “ServiceUri=http://myapp.cloudapp.net:5555/Sample2Dev/XRMServices/2011/Organization.svc; Domain=domain; Username=username; Password=******” -checkout

If you this approach and you are using TFS for managing your backlog, I would strongly recommend you associated your check-in of the CRM Customizations (Extracted using the above) and any source files developed in visual studio with your product backlog item. This way you can later see what were the changes that were done to meet that specific requirement or bug.

Having said all of the above, parallel development adds an overhead and additional complexity. So only go for that option if you really need to. If you decide to ahead anyway, avoid making changes to the same customizations and components by different team  members/teams and remember communication and a good process in place is always important. Bare in mind you can still use the solution packager for keeping a backup or your customizations and viewing deltas overtime which can be helpful in troubleshooting as well.

In the next post I will showing you how to automate the build of these extracted solution files and produce solutions that you can then deploy to other environments or ship to your customers.

How to create an Automated TFS Build for Dynamics CRM Solutions?

In this post I will show you how to fully automate the build of your Dynamics CRM Solutions using TFS and the xRM CI Framework. Creating an automated build when you start a new project is probably the least things on your mind when you have so many requirements to worry about. For this reason I tried to make this process easy and intuitive so you can get this up and running with a few clicks. This will definitely save you time down the line and make your overall process more consistent and reliable.

For this post I am going to show you how to do a Dynamics CRM Online Automated Build. I do not mean the cloud version of Dynamics CRM in this case. I mean creating CRM Solutions by exporting them from an available CRM environment. In this scenario the development team have decided that they want to use Dynamics CRM as their golden source of customizations as opposed to source control. I will assume that you are using the CRM Developer Toolkit to develop your custom assemblies and web resources.

Before you proceed. Follow the instructions in my previous posts to learn more about the xRM CI Framework for CRM 2011 & 2013. Also make sure you have completed the setup instructions detailed in this post.

The first thing is to create a TFS Build Definition. This provides all the configurations values that define what takes place once your build is triggered. The main difference is that instead of using the default build template we are using the customised build template that comes with the xRM CI Toolkit. This will give you the additional options that will allow to build your CRM solution as I will describe below. The default parameters are still available. These form the basis of all builds. If you need more information around these I suggest you read this msdn article. Below is a screen shot of the customised template so you can see what I mean.
BuildProcess

Check my previous post to learn about the flow of this build. Below are step by step instructions to create your first Dynamics CRM Build definition.

  1. Enter your build name. This should take into consideration the CRM Solution name, the source control branch, the build type and any other criteria you want to include.
    BuildName
  2. Select the trigger. I suggest you start with a Manual trigger until your build is working as expected, you can then change it to run on check-in or scheduled basis.
    BuildTrigger
  3. Select the source. This would be the folder containing the visual studio solution that contains the projects for your plug-ins etc…Ideally this should have been created using the CRM Developer Toolkit. But this is not a requirement.
    BuildSource
  4. Set the build controller. TFS online comes with a default build controller. For on premise version you will need to have this setup. Make sure you have configured the build controller with the custom toolkit assemblies as detailed in the installation guide. Also set the Drop Folder. This is where all the outputs will be placed including the exported CRM solutions.
    BuildDefaults
  5. Process. This is where the build workflow is configured. Select the Dynamics CRM Build template from the toolkit as per the installation guide.
    BuildProcess
  6. Set the items to build and configurations. In this case this is your visual studio solution contains all the things you want to build. If you only have customizations in CRM, you can skip this step.
    ItemToBuildSolutionFile
  7. Configure your test settings if you want any unit tests to run as part of your build. Then set the build number format. Use a format similar to the below if you are planning to use this number for your CRM Solution versioning as well. You can update this later if needed to increment your major or minor versions.
    BuildBasic
  8. Set the CRM connection string. The format follow the CRM Sdk connection string. Note if you click on the dots in the field you will be able to provide this using a wizard. Don’t worry you can still update the field manually later to add things such as timeout settings. Then provide the unique solution name. These settings will be used in the following sections for connecting to the Dynamics CRM Server.
    DynamicsCRM
  9. Complete this section if you are using the CRM Developer toolkit and you want to perform the equivalent of deploy from visual studio to ensure that the target CRM environment is inline with your source code before doing the export. The parameters are self explanatory except for the table below.
    CrmPackage

    Parameter Name Description
    Check-In Register File When you perform a deploy on the CrmPackage project using the CRM Developer Toolkit this updates the RegisterFile.crmregister file with the assembly and step GUIDs from CRM. Set this to true to check-in these changes post deployment or false to discard.
    Copy Dependent Packages If you add any dependent CRM Solutions to your package project, setting this to true will copy all of these solutions to the drop folder.
    Enable Deploy If this is set to False then this section will be skipped and no deployment will take place.
  10. Final and most important step. This export the CRM Solution from the specified environment into the drop location. You can optionally publish customizations and increment the Solution version number inline with the build number.
    SolutionExport

    Parameter Name Description
    Enable Solution Export Setting this to False will inform the build to skip this section completely
    Publishes Customizations Publishes all the customizations prior to the export operation
    Update Solution Version to Build Setting this to True will inform the build to update the version number of the CRM Solution in the specified CRM Environment to the Build version number (the part after the ‘_’). This happens before the export operation.
  1. Save the build definition. Trigger a new build and wait until this complete. If everything went ok you should see something similar to the below. Notice that I also get my unit test results and the code coverage.
    BuildCompleted
  2. Finally go to the drop location for that build. You should see all the outputs including the exported CRM Solutions. Notice in this case my solutions have the same version as the build number.
    BuildOutput

By now you should have a fully automated build. That you can re-use. Off course not all builds are simple as this. But this will cater for many scenarios.

Watch out for the up coming posts. I will show you how you can use the CRM Solution packager to do your builds and implement Continuous Integration including extending your builds to deal with more complex scenarios.

Automate your Dynamics CRM Builds and Deployments with PowerShell

Using the xRM CI Framework and Windows PowerShell you can easily extend the build and automate the deployment of your CRM Solutions.

PowerShell allows you to automate various processes by scripting the tasks that are normally performed manually on servers and applications. PowerShell is built on the .NET Framework. That allows you to use any .NET library in your scripts and allows you to work with and manipulate standard .NET objects in a friendly syntax that is close to C# and JavaScript.

Microsoft provides lots of PowerShell commands “cmdlets” that allow you to manage Windows Servers (IIS, File System, Registry) and applications such as Microsoft Office.

The Dynamics CRM SDK includes some PowerShell cmdlets but these are limited to managing CRM organizations through the Deployment Web Service. Check this post for more information about these.

The xRM CI Framework provides you with PowerShell “cmdlets” to allow you to script some of the task that are done manually during the build and/or deployment of Dynamics CRM Solutions.

Using the custom “cmdlets” you are able to assemble a script that can be triggered during your TFS build process or executed on demand from your desktop or other automation tools.

Below is a list of “cmdlets” that are available in the initial release:

CmdLet Name Description SDK Message
Import-XrmSolution Imports a CRM Solution ImportSolutionRequest
Export-XrmSolution Exports a managed or unmanaged CRM Solution ExportSolutionRequest
Get-XrmSolution Retrieves CRM Solution details using the unique solution name Not Applicable
Publish-XrmCustomizations Publishes all customizations for a CRM organization PublishAllXmlRequest
Add-XrmEntity Create a new entity in CRM CreateRequest
New-XrmEntity Creates a new instance of the Entity class Not Applicable
Set-XrmEntity Updates an existing entity in CRM UpdateRequest
Remove-XrmEntity Deletes an existing entity from CRM DeleteRequest

Note that most cmdlets will accept the “ConnectionString” parameter. The format is based on the SDK connection string and the cmdlet will use that parameter to connect to CRM.

To get started follow the setup instructions in my previous post.

To get more information about the parameters each cmdlet provides, run the Get-Help cmdlet as shown below from the PowerShell Console. More information on PowerShell can be found in  the PowerShell getting started manual. All the parameters are inline with the Dynamics CRM SDK messages of the corresponding cmdlets as shown in the table above.

Get-Help

The next step is to write your first PowerShell Script. Below is a sample script that checks the version of the currently deployed CRM solution and updates the target system if the version deployed is older than the latest version.

Write-Host “Deployment Started…”

# Import the xRM CI Framework Dynamics CRM Cmdlets
Import-Module “C:\Program Files (x86)\Xrm CI Framework\CRM 2011\PowerShell Cmdlets\Xrm.Framework.CI.PowerShell.dll”

#Define the CRM connection
$targetCrmConnectionUrl = “ServiceUri=http://test/testorg/XRMServices/2011/Organization.svc`;”

# Retrieve the solution details from CRM

$testSolution = Get-XrmSolution -ConnectionString $targetCrmConnectionUrl -UniqueSolutionName “TestSolution”

if ($testSolution -eq $null)
{
Write-Host “Test Solution not currently installed”
}
else
{
Write-Host “Current Test Solution version: “ -NoNewline $testSolution.Version
}

if (($testSolution -eq $null) -or ($testSolution.Version -ne “2.0.1.0”))
{
$importPath = “TestSolution_2_0_1_0_managed.zip”
Write-Host “Importing Solution: $importPath”

# Import CRM Solution
Import-XrmSolution -ConnectionString $targetCrmConnectionUrl -SolutionFilePath $importPath -PublishWorkflows $true -OverwriteUnmanagedCustomizations $true
}
else
{
Write-Host “Skipped import of Test Solution”
}

This library contains only a subset of what you can do with Dynamics CRM. You can expose any Dynamics CRM SDK message as a PowerShell cmdlet and use it to automate anything that you could be doing manually today.

Having your builds and deployment automated will allow you to build and deploy quickly and will give you the added consistency and reliability.

In future posts, I will show you how you can implement continuous integration by combining the automated builds discussed in this post and the PowerShell cmdlets for Dynamics CRM.

Building CRM Solutions with TFS Build

Using the xRM CI Framework and TFS Build you can easily automate the build of your CRM Solutions.

In this post  will go through the details of the Dynamics CRM TFS Build template “DynamicsCrm2011Template.11.1.xaml” that makes of all this possible. Before I proceed further, a TFS Build template is a workflow that defines the flow and steps of a TFS Build. This is normally implemented using Windows Workflow Foundation. TFS Build allows you provide custom build templates to suite your needs.

The Dynamics CRM 2011 TFS build template extends the default TFS Build template to provide the extra steps required to Build CRM Solutions and implement Continuous Integration.

Below are the high level steps the Dynamics CRM Build will go through. Note that all these steps can be configured using parameters and can be turned on or off to suite your specific scenarios.

  1. Compile your Visual Studio Solution (Plug-ins, Custom Workflows, Silverlight, Dependencies, etc…)
  2. Run Unit Tests
  3. Invoke CRM Developer Toolkit CrmPackage project deployment (deploy solution components from source control)
  4. Publish Customizations
  5. Update CRM Solution version number from TFS Build number (the part after the ‘_’)
  6. Export your CRM Solution from a CRM Instance
  7. Unpack an exported CRM Solution using Solution Packager and update your source control
  8. Update version number of your unpacked solution stored in source control (“\Other\Solution.xml”)
  9. Pack your customizations from source control and produce a CRM Solution Package
  10. Invoke a PowerShell script to further extend the Build and/or deploy your solution and dependencies
  11. Run Integration tests on your selected environment

Using various combinations of the above you can implement different types of builds to suite your needs.

Note that all components required to build your CRM Solution should be either in source control or CRM instance for the Build Template to work correctly.

As I mentioned before all of the above can be configured very easily using the TFS Build user interface inside visual studio. So you can create a new build definition in a matter of minutes.

DynamicsCRMBuildDefinition

To visualize the build workflow for Dynamics CRM, below is a Visio diagram showing the main flow.

Dynamics CRM 2011 TFS Build Template Flow

Dynamics CRM 2011 TFS Build Template Flow

In the coming posts I will go into the details of the different types of Builds you can create and how you can use this template to implement these.

In the meantime you can have a go at creating a build definition using the template after following the setup instructions in my previous post.

xRM CI Framework is now available

The xRM CI Framework is a set of tools that allows you to quickly and easily implement Continuous Integration for your Dynamics CRM solutions.

The framework provides an implementation of some of the concepts detailed in the recently published Microsoft Dynamics CRM Application Lifecycle Management (ALM) white paper. The framework is also compatible with the Dynamics CRM Developer toolkit from the SDK.

The framework allows you to improve efficiency and consistency by automating your build and deployments using Team Foundation Server (TFS) 2012 and PowerShell.

Below is the list of features provided in the first release.

  1. Dynamics CRM TFS Build Template that allows you to easily create your Check-In, Continuous Integration, Nightly and Release Builds
  2. Dynamics CRM PowerShell Cmdlets to extend your build process and automate your deployments
  3. Ability to support online & offline Dynamics CRM Builds (Build from CRM instance v.s. from source control)
  4. Ability to trigger automated deployments from your TFS Builds
  5. Ability to run Integration Tests from your TFS Builds after deployment
  6. Automatic versioning of your CRM Solutions inline with your TFS Build number
  7. Ability to automate the updating of your customisations stored in source control from CRM using the solution packager
  8. Support for Dynamics CRM on-premise & online
  9. Support for TFS 2012 on-premise & online
  10. Easy to use and extensible to meet your specific scenarios

Apart from the benefits above you will also get all the benefits of using Team Foundation Server Build to improve your ALM.

There will be a series of blog articles to show you how you can use the framework to implement your specific scenarios in your projects.

In the meantime you can download a copy of the framework from the visual studio gallery.

Don’t forget to check out the setup post on how to get started.

Installing the xRM CI Framework

In this post I will provide you with the details on how to setup  the xRM CI Framework.

The process is simple and easy. After this stage you will be ready to create your automated builds and deployments.

Framework Download & Installation:

  1. The first step is to download the setup files from the visual studio gallery.
  2. Run the setup which will copy all the required files to the installation directory “C:\Program Files (x86)\Xrm CI Framework”.

Automated Build Template Setup:

  1. The first step is to copy the contents from the installation directory “C:\Program Files (x86)\Xrm CI Framework\CRM 2011\VS 2012\TFS Build Templates” and store them under source control in TFS.
  2. Once the files are under source control, you will need configure your Build Controller to use the custom assemblies required by the template.
  3. Follow this link to perform the two steps above. This is based on TFS online but you can use the same process for TFS on premise.
  4. The final step is to register the Dynamics CRM 2011 Build templates with TFS. Follow this link to register the template by selecting the template from the location in source control from the previous step.
  5. Now you should be ready to create your first Build Definition using the Dynamics CRM 2011 template.

Dynamics CRM PowerShell Cmdlets Setup

  1. Start the PowerShell Console and run the command below.
  2. Import-Module “C:\Program Files (x86)\Xrm CI Framework\CRM 2011\PowerShell Cmdlets\Xrm.Framework.CI.PowerShell.dll”. This will give you access to all the xRM CI Framework PowerShell Cmdlets.
    If you are running this on Windows 7 or 8. You will most probably have PowerShell using .NET 2.0 and encounter some errors. To force PowerShell to use .NET follow this blog.
  3. Create your PowerShell Script using the Cmdlets

This article demonstrated how to setup the xRM CI Framework. In the next blogs i will show you how to configure different types of builds and deployment to suite your specific scenario.

Building the CRM Developer Toolkit Solution (CrmPackage) in the Cloud (TFS Online)

As most of you probably know, Microsoft released an online version of  TFS that is host in the cloud. You can find more information about this http://tfs.visualstudio.com/.

This allows you to store and manage all the artefacts related to your application life cycle management in the cloud. This includes source control, work item management and testing.

One of the cool features that TFS provides is Automated Builds. This can among other things compile your code in a consistent way and also run automated tests and produce packages such as your CRM solutions.

TFS online comes with a hosted pre-configured build controller that you can use to build your software. This comes pre-configured with a list of software packages. These don’t include the CRM Developer Toolkit. As such trying to compile any Visual Studio projects created using the CRM Developer Toolkit will not work by default.

In this post I will show you how to configure your CrmPackage project to make it compatible with the hosted build controller.

A typical project created using the CRM Developer Toolkit will look something like the below. This contains Plug-in,Workflow and  XAML Workflow projects. It also contains the CrmPackage Project that is used to deploy all the previous components.
EmptyDeveloperToolkitProject

Once you created the projects, you will notice that all references to the CRM Sdk and Developer Toolkit Libraries are pointing to the local installation folder of the Developer Toolkit which will not be available on the Hosted Build Server.

DeveloperToolkitPluginDefaultReference

To get everything to build online, you will need to store all CRM Sdk libraries in source control and change all the references in your projects (Plugins, Workflows, XAML Workflows) to point to the relative path in your workspace.

SampleLibDeveloperToolkitPluginLocalReference

The next step is to fix the CrmPackage Project. Right click on the project and select Unload.

UnloadPackageProject

Then Right click and edit.

EditPackageProject

Locate the import statement below. This imports the developer toolkit targets from the installation directory.

  1. <ImportProject=$(MSBuildExtensionsPath32)\Microsoft\CRM\Microsoft.CrmDeveloperTools.12.targets />

Before you change that, you will need to copy the files from the installation directory below and store them in source control along with the CRM Sdk binaries.

DeveloperToolkitTargetsDirectory

Now change the import statement to the relative path in your source control workspace as below.

  1. <ImportProject=..\Lib\CrmSdk\Microsoft.CrmDeveloperTools.12.targets />

Now you can save and reload the package project.

ReloadPackageProject

At this stage you should be able to rebuild the package project successfully  and all the dependencies should be in your workspace together with your source code. Check-in all your changes into source control.

The next step is to create a Build Definition. For example you can create a build definition to compile your code and run your uni tests every time somebody check-in any code. This will ensure that the latest version of your code is always working.

More information on creating build definitions can be found http://msdn.microsoft.com/en-us/library/ms181716.aspx

In my next posts I will show you how to configure and modify your Build definitions to make them more useful. This will include things such as producing CRM Solutions.

Dynamics CRM 2011 Organization Service Tracing

In Dynamics CRM 4.0 you used to be able to run Fiddler to look at the contents of the HTTP requests being made to the CRM Service. When playing with the Dynamics CRM 2011 SDK i was curious to have a look at the messages that are being send across the wire between my development PC and the Dynamics CRM Organization service. This can be useful to look sometimes at what is happening behind the scenes when you work with the early bound model/LINQ and also when debugging various scenarios. When trying to run Fiddler on an on-premise deployment i noticed that the messages were encrypted. So i figured another way to achieve this using WCF standard mechanism since the CRM Service and SDK libraries are build around the WCF stack. All you need to do is put the sample cconfiguration below to your application configuration file. This will log any messages that are send and received on the client side. All you have to do now is open the trace log file with the Service Trace Viewer (SvcTraceViewer.exe). A similar mechanism can also be adoped on the server side.

  <system.diagnostics>
    <sources>
      <source name ="System.ServiceModel.MessageLogging"
              switchValue="Verbose, ActivityTracing">
        <listeners>
          <add name="xml" />
        </listeners>
      </source>
    </sources>
    <sharedListeners>
      <add name="xml" type="System.Diagnostics.XmlWriterTraceListener"
           traceOutputOptions="LogicalOperationStack"
           initializeData="C:\log\CRMTrace.svclog" />
    </sharedListeners>
    <trace autoflush="true" />
  </system.diagnostics>
  <system.serviceModel>
    <diagnostics>
      <messageLogging
           logEntireMessage="true"
           logMalformedMessages="false"
           logMessagesAtServiceLevel="true"
           logMessagesAtTransportLevel="false"/>
    </diagnostics>
  </system.serviceModel>

I will show samples messages captured using the Fiddler and WCF traces for the code below.

            using (OrganizationServiceProxy proxy = CreateProxy())
            {
                WhoAmIRequest req = new WhoAmIRequest();
                WhoAmIResponse res = proxy.Execute(req) as WhoAmIResponse;
                Console.WriteLine("WhoAmIUserId: " + res.UserId);
                return res.UserId;
            }
Below is the Fiddler trace the request. As you can see nothing very useful.
 
<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <s:Header>
    <a:Action s:mustUnderstand="1" u:Id="_4">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute</a:Action>
    <a:MessageID u:Id="_5">urn:uuid:e5c9ff4c-0752-4c24-9dbb-8ac49e6f4c46</a:MessageID>
    <a:ReplyTo u:Id="_6">
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink">uIDPoxO2jGq+wmJNtFyl0vt7JzoAAAAA4Whc+xgnSU6m/mUlFbvDxSBygozH25xJqktDA+Roo0AACQAA</VsDebuggerCausalityData>
    <a:To s:mustUnderstand="1" u:Id="_7">http://[Server]/[Org]/XRMServices/2011/Organization.svc</a:To>
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <u:Timestamp u:Id="uuid-4e6e29af-ab82-458e-9dbc-e8a0aac0342a-4">
        <u:Created>2011-04-09T22:02:06.117Z</u:Created>
        <u:Expires>2011-04-09T22:07:06.117Z</u:Expires>
      </u:Timestamp>
      <c:SecurityContextToken u:Id="uuid-8fcc72f9-4325-4918-84d2-20233d35381a-4477" xmlns:c="http://schemas.xmlsoap.org/ws/2005/02/sc">
        <c:Identifier>urn:uuid:247def00-8dd1-47ee-b396-538ae9bcbc44</c:Identifier>
      </c:SecurityContextToken>
      <c:DerivedKeyToken u:Id="_0" xmlns:c="http://schemas.xmlsoap.org/ws/2005/02/sc">
        <o:SecurityTokenReference>
          <o:Reference ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/sct" URI="#uuid-8fcc72f9-4325-4918-84d2-20233d35381a-4477"/>
        </o:SecurityTokenReference>
        <c:Offset>0</c:Offset>
        <c:Length>24</c:Length>
        <c:Nonce>X/8UYVFOuWcc6UTL/OqAvQ==</c:Nonce>
      </c:DerivedKeyToken>
      <c:DerivedKeyToken u:Id="_1" xmlns:c="http://schemas.xmlsoap.org/ws/2005/02/sc">
        <o:SecurityTokenReference>
          <o:Reference ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/sct" URI="#uuid-8fcc72f9-4325-4918-84d2-20233d35381a-4477"/>
        </o:SecurityTokenReference>
        <c:Nonce>sdrDI626w2V+kUT5XKE3Mg==</c:Nonce>
      </c:DerivedKeyToken>
      <e:ReferenceList xmlns:e="http://www.w3.org/2001/04/xmlenc#">
        <e:DataReference URI="#_3"/>
        <e:DataReference URI="#_8"/>
      </e:ReferenceList>
      <e:EncryptedData Id="_8" Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:e="http://www.w3.org/2001/04/xmlenc#">
        <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
        <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
          <o:SecurityTokenReference>
            <o:Reference ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/dk" URI="#_1"/>
          </o:SecurityTokenReference>
        </KeyInfo>
        <e:CipherData>
          <e:CipherValue>MkIW8r9bYxpZnDE5UhgsxgHS2Y28jm9sY0KKZVS+sPIKpxek/rVJeyWsnplje8pxaJV6/+VrTsdmK25WXbKQ3P+A7XPkutdeIXFIrKCFeYBD7L6hNOPtaf+I7i2yoDEEYM9FGhdgpOS1hrmmux38ekXMwj069Xz+hflhmabFSJHooMZHGmVHOhZJQxkk9+++I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lCYiA0JqZvraQLtwz+EuLxoyEnAZpczCEnycfjN8t0xxs1hdOlGJrc5gm3KRkHvd+BSrxKSsF0RSe5AQFrTu3IOiSFcAl/kCIRH6o6bVi0T6f94OpGhzsKsk1H6++cTS4PkMGr/F8qfSj1A2W6XYQ/Cxv0DkLjKxaB7bIYEmCosfQcZBSxqJ8UdHu/RIjFJDIaaJKjydJDO+yGGNEZBJUAjP07zLhQNoHqwn09tCiNsyYybbR5B+1OMC4Aw7iJXt28ey7/X4NhKY22Qxr0FxPOu0K51WkRJKxoNAYt2fPLkMwVDs3yG6Xrh4XEa5I6RjtrjrI64IAsiPfVVAYoLXRjDKVSczfkJuy4BUa7PA2z8skQ4i/+rGmnWXNk4lN8SH7qk8OyjugHMM8N5i1</e:CipherValue>
        </e:CipherData>
      </e:EncryptedData>
    </o:Security>
  </s:Header>
  <s:Body u:Id="_2">
    <e:EncryptedData Id="_3" Type="http://www.w3.org/2001/04/xmlenc#Content" xmlns:e="http://www.w3.org/2001/04/xmlenc#">
      <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
      <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
        <o:SecurityTokenReference xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
          <o:Reference ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/dk" URI="#_1"/>
        </o:SecurityTokenReference>
      </KeyInfo>
      <e:CipherData>
        <e:CipherValue>naQiwhfpoT8xWJ72S9E62+dkbV/RKc9idba5I5UyeMvchrE8DWpsPFeiNlSvvR8SpgVgE7S1f7HuqhRgqOiB4QBPbiWUZRycMVo7f2Suj+uJ3/hTxB51MpZ9jEYGf3Vbi2qjrgUN1BEWg/R5yYbWUB1hsXzaL6ccqIqgI4hHWhX55te6lvg0bs7CwfKZorLYY7+1UeMkaDEu83Dsy6O4oYKfKSyRDRpFRRzG0kk/H50bDut4Jl8NlO/L6HRROVOZLShuttymxlkEdAsojZm7g1MKiff1imUcfxJoSUYETYl6hXd8EKADiS22vhc+3F4ZXCux/exy2STxgBei8OYsLH3mV6SS2yKyLUG1yyMSScXjKPYRFtd9Ku1rzl7YYBabm+5l59vIwAgN8pK+NRuVuNwpgU9ARNDWOYb5dllS6OBNc3S7U7ANNEL+FOsWSv71PtyttWFn8anecWaTnnm85qe4VA97rEmArJw3cSZ0YFt7cHfuR1miCjek2sU3DY5zuCrAi5ObBjvy40/1iB3vv6rLkm2KJzksyhFO2OXd8rilMpnE6Yp+aWn5Zjujjz+YH8oQGfEkxOAE+wKOOXGpUzhnAIoAmYxyL0hTaBe6eokOUKONvxiZtpR5T86mjNry</e:CipherValue>
      </e:CipherData>
    </e:EncryptedData>
  </s:Body>
</s:Envelope>

Again below this is the Fiddler trace for the response message.

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope" xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
  <s:Header>
    <a:Action s:mustUnderstand="1" u:Id="_4">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/ExecuteResponse</a:Action>
    <a:RelatesTo u:Id="_5">urn:uuid:e5c9ff4c-0752-4c24-9dbb-8ac49e6f4c46</a:RelatesTo>
    <ActivityId CorrelationId="cf45b67e-ea16-4a0b-b9fa-cafc8b70ac8e" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId>
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <u:Timestamp u:Id="uuid-8fcc72f9-4325-4918-84d2-20233d35381a-4480">
        <u:Created>2011-04-09T22:02:14.688Z</u:Created>
        <u:Expires>2011-04-09T22:07:14.688Z</u:Expires>
      </u:Timestamp>
      <c:DerivedKeyToken u:Id="_0" xmlns:c="http://schemas.xmlsoap.org/ws/2005/02/sc">
        <o:SecurityTokenReference>
          <o:Reference URI="urn:uuid:247def00-8dd1-47ee-b396-538ae9bcbc44" ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/sct"/>
        </o:SecurityTokenReference>
        <c:Offset>0</c:Offset>
        <c:Length>24</c:Length>
        <c:Nonce>deNjAhrA3jpalpOD2mfjSg==</c:Nonce>
      </c:DerivedKeyToken>
      <c:DerivedKeyToken u:Id="_1" xmlns:c="http://schemas.xmlsoap.org/ws/2005/02/sc">
        <o:SecurityTokenReference>
          <o:Reference URI="urn:uuid:247def00-8dd1-47ee-b396-538ae9bcbc44" ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/sct"/>
        </o:SecurityTokenReference>
        <c:Nonce>dCRq0bmNk5BYAs++nDBFrQ==</c:Nonce>
      </c:DerivedKeyToken>
      <e:ReferenceList xmlns:e="http://www.w3.org/2001/04/xmlenc#">
        <e:DataReference URI="#_3"/>
        <e:DataReference URI="#_6"/>
      </e:ReferenceList>
      <e:EncryptedData Id="_6" Type="http://www.w3.org/2001/04/xmlenc#Element" xmlns:e="http://www.w3.org/2001/04/xmlenc#">
        <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
        <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
          <o:SecurityTokenReference>
            <o:Reference ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/dk" URI="#_1"/>
          </o:SecurityTokenReference>
        </KeyInfo>
        <e:CipherData>
          <e:CipherValue>aigA7nWL7kS6sGtoAyXXZjgZUn7TlWoa8vjaut609vNpE2ijl/6g1obAwizJXVZskbRW9Y2cEGqisxbe/3zv9KVEywiYiI7IEB98lORGFc+U8zJVWxWuuNZRMGQU6u1ypA5Aj9FF3mYwWeUmuHzmjrLYemiin3VBojne/jsG55APbaRMit8N1jNRg4cNBqI/3Tak0w4GvKycs0hqi7KDvQURlT/Io9EoYNzzKSKcC7B5CWov2hqoVjBd0SWQ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8OKrG/q8hnHgd91ZUte44Cb3sshMiZVFzJ3I+DQzJCqQWhm4RjBJlNKRjA7vh+tnluShpdDCpgX/Xo+Yw+LiPsGhSXXHJUUF+PkkiqP0njFhk7jEM985RELTOsLqBdZS/WRnWvV5tc72DNHBbHh5GgKZShewVyb6pVgP5ySYe2AV1SiPfiv4Bp5oyDePznNr3aczBGFN9ihB8ZDdEaAHnWa3nSk9ZPFDBguWDaap2kyT9Id0H35MhXfTMbpQT1t95+kGBlH9pHFZR/K4bmjKM+WLJycU3+Otrbrq6C9qUOl8TWKqGNos4Efnot3OoFtSdu/LC6rDRszUXM8m87aLqNYNkEXwVqKCCceamSUeHSjmB37qCau2mS6brVGRdNZiOctK70JGsGT8jKSnSbBGLYJ9TsrmW9DDFr2RA+qwgBj75h3oFJtgX4lTi3CPDs2yrW7rOKdBPuo5XU6Y5lzTCFL2eMAO1PJduXuyyUihWiopIuM82CtpsPodfa/sFvjguFbQc7o1/wvEPBd3jXt/ZYDToF3WqUdw55jOs0iqNL2JLGc45nXgcYHyarZCp9HVPtwcK7cjXDtkz/4x51XZU3aDcLI96KPjoa1QaulKqgrwccZXHcz8I0Zo8rvc25Mxctd3B7lF0uNhAj4T7nLs9IOQ1X3B1aZgXRx7aXDNRzEeBeO7GPUEfq3KKqfkJYsfo9uFjJDXo5R8GHDmUV1QHULILNwkYeY31yg9d0SgB53PGjiohm3ug5PZ0mBHShBfUCuBpRcq9fa2h</e:CipherValue>
        </e:CipherData>
      </e:EncryptedData>
    </o:Security>
  </s:Header>
  <s:Body u:Id="_2">
    <e:EncryptedData Id="_3" Type="http://www.w3.org/2001/04/xmlenc#Content" xmlns:e="http://www.w3.org/2001/04/xmlenc#">
      <e:EncryptionMethod Algorithm="http://www.w3.org/2001/04/xmlenc#aes256-cbc"/>
      <KeyInfo xmlns="http://www.w3.org/2000/09/xmldsig#">
        <o:SecurityTokenReference xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
          <o:Reference ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/dk" URI="#_1"/>
        </o:SecurityTokenReference>
      </KeyInfo>
      <e:CipherData>
        <e:CipherValue>5HSblwEyHFKE78RidjYtxVfsh8oOfFBH6afHqreaRmfeD0Tokt8g1bhZheACIOX6T/lTcI7wuMJL57A0Yi/qZSsZ9NpecnkbRiN3hUs+e+9JxyG3rf7q3by58yb6/4fR3Hl+xVz6yzcjU2gTcBoZoB3seXu3UQZoIsI9YZ9ci0eeOY3wqOoNxvusUpURnOX00IKrubmK6wAKe4sLcDfmDasU/Qf425Ts4PMh3xwlv+n/yivUVKwhZWu1XVbPWrW0xzbHRkjpVt1UT3wU6MnnaPEXYHRhNp2F466SZf7/DhV10AJwjBCt44VPowcQ3DL1UEgu89ypIgMm/3Dqp1VGeIerQS+qkEkHIVPxNaV5nhbwAGnYUUZtUZfSH6FDV/Ubw8BEEZO1+mgwqzUid4X0AfvnWmDzdzayIInXROSdSaq3B4Imn4d+cYXobUBwIoJwD3ySt3W74jHQuKB8FCHvMoTb3yHuWG/bxUuvgWTOLM/VnprmTC9/dDNd+kD1rZkV0oIynuNLc4wipPXyHLCt2tKwQw+QDGxzm82N5nVIrFpI8lftAmmCfwCeyBPA3WmJkMUnZqfPet94Jpuo3WrLXc+f9ojghBpVPs66GDwmstgrJ3BicIQcZNh0hesfb4pCE732b1xIN3OOTm0kfyhBVQYOPOYP6h6P2nWebSCaoon6+HEOkcc5BwJZkk93/LgdoTJVOmsyvQ5TKtGG9tHgnVMrj6VVHEg/6/PqDpLgsvQ/MWH4OcvIvHkHMB09yO6yvxB7XpW2XVOaYvd2M9ZX4EzJbmiiwJKXS529VC9XPe9aLvdpnte5hyKDpQxQyuiGaRCELV0KKZyLA8MhO6EGk2z3xnCw2euFueMHj2+ffJp760nfbV/3VFhWED0kMlPL4ULCeitGR5+dBseF5prTvg18MTnUTrjq7+skiyfyQqAH8Bq0Ra7gqtuoXatCzyzESS8nhRYv8SGyXzSuIWeokf5VsJCmfHz4uxA0ioBZ6OOOXLt8ApMRLYw/vUDwP6thArjDVO7nDG8tvyngSlrIs0ePzBJzA1pO5IC7tZrLP4H0gOzmYLsMCMC29VmoxPe5VKa43O420jXi/syioqnDk7TPuzPUU0mstkUN5jkARn8+spT0atDNjrqdkfEMmMlxVqLVnf8oMpGcqQKBH//mF2RmGXG+2aKSc1npZcgdiiA6ajohONaU1SPXtW+UN07WEWjif/zQWlmC1FtareLJxhOyM7EcI1YJIS3Y+ODNZgH/Co4sLm5eM/64/m5ymwbNhFZZXNlaMNHctAk7inwULBIzC2KH9wPKgFLDjTNh1s+Pd4BiVgvzMP1wwH4EW1EstwhqZefmJpQDXWQPLSkl3CqySMMe1E/EsGLxn/n/8n2iYc2mnxZY6yjbzWCa8vlt8aWZAX5h7KCHvJpM+7gqAmLBqWpuNwdjDVAfynqNaWH6gRjUOHqbfLcIfCkAvtWAivY9kWlU48zqScwTdUb9KiMVGP01X7rw3tpKpYp+H1lR6u3jQSSnU8sr1XEVIs3Z</e:CipherValue>
      </e:CipherData>
    </e:EncryptedData>
  </s:Body>
</s:Envelope>

Now below is the WCF trace at the service level that shows the actual contents of the SOAP request.

<s:Envelope xmlns:a="http://www.w3.org/2005/08/addressing" xmlns:s="http://www.w3.org/2003/05/soap-envelope">
  <s:Header>
    <a:Action s:mustUnderstand="1">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/Execute</a:Action>
    <a:MessageID>urn:uuid:e5c9ff4c-0752-4c24-9dbb-8ac49e6f4c46</a:MessageID>
    <a:ReplyTo>
      <a:Address>http://www.w3.org/2005/08/addressing/anonymous</a:Address>
    </a:ReplyTo>
    <VsDebuggerCausalityData xmlns="http://schemas.microsoft.com/vstudio/diagnostics/servicemodelsink"></VsDebuggerCausalityData>
  </s:Header>
  <s:Body>
    <Execute xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
      <request xmlns:d4p1="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:d4p3="http://schemas.microsoft.com/crm/2011/Contracts" i:type="d4p3:WhoAmIRequest">
        <d4p1:Parameters xmlns:d5p1="http://schemas.datacontract.org/2004/07/System.Collections.Generic"></d4p1:Parameters>
        <d4p1:RequestId i:nil="true"></d4p1:RequestId>
        <d4p1:RequestName>WhoAmI</d4p1:RequestName>
      </request>
    </Execute>
  </s:Body>
</s:Envelope>

Finally below is the WCF trace at the service level that shows the actual contents of the SOAP response. You can see the details about the executing user.

<s:Envelope xmlns:s="http://www.w3.org/2003/05/soap-envelope">
  <s:Header>
    <a:Action s:mustUnderstand="1" u:Id="_4" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:a="http://www.w3.org/2005/08/addressing">http://schemas.microsoft.com/xrm/2011/Contracts/Services/IOrganizationService/ExecuteResponse</a:Action>
    <a:RelatesTo u:Id="_5" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd" xmlns:a="http://www.w3.org/2005/08/addressing">urn:uuid:e5c9ff4c-0752-4c24-9dbb-8ac49e6f4c46</a:RelatesTo>
    <ActivityId CorrelationId="cf45b67e-ea16-4a0b-b9fa-cafc8b70ac8e" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId>
    <o:Security s:mustUnderstand="1" xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
      <u:Timestamp u:Id="uuid-8fcc72f9-4325-4918-84d2-20233d35381a-4480" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <u:Created>2011-04-09T22:02:14.688Z</u:Created>
        <u:Expires>2011-04-09T22:07:14.688Z</u:Expires>
      </u:Timestamp>
      <c:DerivedKeyToken u:Id="_0" xmlns:c="http://schemas.xmlsoap.org/ws/2005/02/sc" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <o:SecurityTokenReference>
          <o:Reference URI="urn:uuid:247def00-8dd1-47ee-b396-538ae9bcbc44" ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/sct"></o:Reference>
        </o:SecurityTokenReference>
        <c:Offset>0</c:Offset>
        <c:Length>24</c:Length>
        <c:Nonce>
          <!-- Removed-->
        </c:Nonce>
      </c:DerivedKeyToken>
      <c:DerivedKeyToken u:Id="_1" xmlns:c="http://schemas.xmlsoap.org/ws/2005/02/sc" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
        <o:SecurityTokenReference>
          <o:Reference URI="urn:uuid:247def00-8dd1-47ee-b396-538ae9bcbc44" ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/sct"></o:Reference>
        </o:SecurityTokenReference>
        <c:Nonce>
          <!-- Removed-->
        </c:Nonce>
      </c:DerivedKeyToken>
      <e:ReferenceList xmlns:e="http://www.w3.org/2001/04/xmlenc#">
        <e:DataReference URI="#_3"></e:DataReference>
        <e:DataReference URI="#_6"></e:DataReference>
      </e:ReferenceList>
      <Signature xmlns="http://www.w3.org/2000/09/xmldsig#">
        <SignedInfo>
          <CanonicalizationMethod Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></CanonicalizationMethod>
          <SignatureMethod Algorithm="http://www.w3.org/2000/09/xmldsig#hmac-sha1"></SignatureMethod>
          <Reference URI="#_2">
            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></Transform>
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></DigestMethod>
            <DigestValue>CM5e0byUp3ccAE2dGzBmaEoULOQ=</DigestValue>
          </Reference>
          <Reference URI="#_4">
            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></Transform>
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></DigestMethod>
            <DigestValue>T5XEnhEHcT3kntcAeWTHEDElkHg=</DigestValue>
          </Reference>
          <Reference URI="#_5">
            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></Transform>
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></DigestMethod>
            <DigestValue>qUejK6uFN8IMPRBGOgD0T+IRpYk=</DigestValue>
          </Reference>
          <Reference URI="#uuid-8fcc72f9-4325-4918-84d2-20233d35381a-4480">
            <Transforms>
              <Transform Algorithm="http://www.w3.org/2001/10/xml-exc-c14n#"></Transform>
            </Transforms>
            <DigestMethod Algorithm="http://www.w3.org/2000/09/xmldsig#sha1"></DigestMethod>
            <DigestValue>TY+iuqtq/ZKovc0vC9ZKFPMEttQ=</DigestValue>
          </Reference>
        </SignedInfo>
        <SignatureValue>Z6DV7dz+0wTs9aeynb/6KC04Pcs=</SignatureValue>
        <KeyInfo>
          <o:SecurityTokenReference xmlns:o="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-secext-1.0.xsd">
            <o:Reference ValueType="http://schemas.xmlsoap.org/ws/2005/02/sc/dk" URI="#_0"></o:Reference>
          </o:SecurityTokenReference>
        </KeyInfo>
      </Signature>
    </o:Security>
  </s:Header>
  <s:Body u:Id="_2" xmlns:u="http://docs.oasis-open.org/wss/2004/01/oasis-200401-wss-wssecurity-utility-1.0.xsd">
    <ExecuteResponse xmlns="http://schemas.microsoft.com/xrm/2011/Contracts/Services">
      <ExecuteResult i:type="b:WhoAmIResponse" xmlns:a="http://schemas.microsoft.com/xrm/2011/Contracts" xmlns:i="http://www.w3.org/2001/XMLSchema-instance" xmlns:b="http://schemas.microsoft.com/crm/2011/Contracts">
        <a:ResponseName>WhoAmI</a:ResponseName>
        <a:Results xmlns:c="http://schemas.datacontract.org/2004/07/System.Collections.Generic">
          <a:KeyValuePairOfstringanyType>
            <c:key>UserId</c:key>
            <c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">8179fcb3-fb55-e011-ab42-005056b863d7</c:value>
          </a:KeyValuePairOfstringanyType>
          <a:KeyValuePairOfstringanyType>
            <c:key>BusinessUnitId</c:key>
            <c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">a6fa9e52-564a-e011-ab42-005056b863d7</c:value>
          </a:KeyValuePairOfstringanyType>
          <a:KeyValuePairOfstringanyType>
            <c:key>OrganizationId</c:key>
            <c:value i:type="d:guid" xmlns:d="http://schemas.microsoft.com/2003/10/Serialization/">dec6a83f-564a-e011-ab42-005056b863d7</c:value>
          </a:KeyValuePairOfstringanyType>
        </a:Results>
      </ExecuteResult>
    </ExecuteResponse>
  </s:Body>
</s:Envelope>

Hope you find this useful.

CRM Developer Toolkit for Visual Studio 2012: Package Project not loading

If you have installed the new Dynamics CRM 2011 Developer Toolkit for Visual Studio 2012, you might notice that package projects created using the old developer toolkit fail to load. This is manifested in an error similar to the below.

TargetFilesNotFound

To fix the problem follow the steps below:

  1. Right click on the package project and click Unload
  2. Right click on package project and click on Edit
  3. Replace “<Import Project=”$(MSBuildExtensionsPath32)Microsoft\CRM\Microsoft.CrmDeveloperTools.CrmClient.targets” />” with “<Import Project=”$(MSBuildExtensionsPath32)Microsoft\CRM\Microsoft.CrmDeveloperTools.12.targets” />”
  4. Right click on the package project and click on Reload

This will fix the problem. The problem is because the target files location is different between the developer tools for visual studio 2010 and visual studio 2012.

Hope this helps