CrmSvcUtil Entity Generator Extension

Following from my other CrmSvcUtil extensions CrmSvcUtil Attribute Constant Generator Extension and CrmSvcUtil Option Set Enum Generator Extension, I’ve also implemented a (light-weight) extension to the standard entity generator.

Currently, the list of customisations that this extension adds is:

  1. Replaces the standard <summary> tag for all attributes with the new summary in the form: [ISNULL(Attribute.Label, Attribute.LogicalName)]: [Attribute.Description].
  2. Add a System.ComponentModel.Description attribute to each attribute showing the label of the attribute.

The purpose of these extensions is to give visiblity of the label of an attribute – specifically to make our lives easier when coding against attributes whose labels no longer match their logical name.

Download the CrmSvcUtil extension at codeplex: CrmSvcUtil Generate Entities.

To use the extension:

  1. Copy GenerateEntities.dll into the directory containing CrmSvcUtil.exe
  2. Run CrmSvcUtil with the following parameters:
CrmSvcUtil.exe ^
/codecustomization:"GenerateEntities.CodeCustomizationService, GenerateEntities" ^
/url:http://servername/orgname/XRMServices/2011/Organization.svc ^
/out:Attributes.cs ^

CrmSvcUtil Option Set Enum Generator Extension

Following from my recent post, I thought I’d release the option set enumeration generator I have been using as well.

I am aware that several existing CrmSvcUtil extensions as well as the unextended CrmSvcUtil generate option set enumerations but this one has several key advantages:

  1. Enumerations are generated as members of the entity classes, not global options sets. This allows copies of global option sets per attribute that uses the global option set.
  2. Duplicate enumeration options are handled by appending the value of the item, not an arbitrary counter. Appending a counter can actually cause bugs that are incredibly difficult to track down if another duplicate instance is added in between two existing duplicates – effectively changing the key/value pair combination without updating dependent code.
  3. Enumerations are generated and consistently named for Option Set, Boolean, State and Status attribute types. Enumerations are referred to in the form “[Entity Schema Name].[Attribute Logical Name]Values” in all cases.

Download the CrmSvcUtil extension at codeplex: CrmSvcUtil Generate Option Set Enums.

To use the extension:

  1. Copy GenerateOptionSetEnums.dll into the directory containing CrmSvcUtil.exe
  2. Run CrmSvcUtil with the following parameters:
CrmSvcUtil.exe ^
/codecustomization:"GenerateOptionSetEnums.CodeCustomizationService, GenerateOptionSetEnums" ^
/codewriterfilter:"GenerateOptionSetEnums.FilteringService, GenerateOptionSetEnums" ^
/url:http://servername/orgname/XRMServices/2011/Organization.svc ^
/out:Enumerations.cs ^

The baseTypes parameter is optional and can be used to override the base types for entity classes which is needed if you have previously generated the wrapper classes with an extension (eg. Microsoft.Xrm.Client.CodeGeneration.CodeCustomization).

To use the generated option set enumerations:

Contact contact = new Contact();
contact.Attributes[Contact.firstnameAttribute] = "Michael";
contact.Attributes[Contact.lastnameAttribute] = "Palmer";
contact.EducationCode = new OptionSetValue((int)Contact.gendercodeValues.Male);

CrmSvcUtil Attribute Constant Generator Extension

A recent question on the CRM MSDN forum made me realise that as far as I can see, no-one has yet created a CrmSvcUtil extension to generate attribute constants. So I did.

Download the CrmSvcUtil extension at codeplex: CrmSvcUtil Generate Attribute Constants.

To use the extension:

  1. Copy GenerateAttributeConstants.dll into the directory containing CrmSvcUtil.exe
  2. Run CrmSvcUtil with the following parameters:
CrmSvcUtil.exe ^
/codecustomization:&quot;GenerateAttributeConstants.CodeCustomizationService, GenerateAttributeConstants&quot; ^
/codewriterfilter:&quot;GenerateAttributeConstants.FilteringService, GenerateAttributeConstants&quot; ^
/url:http://servername/orgname/XRMServices/2011/Organization.svc ^
/out:Attributes.cs

The baseTypes parameter is optional and can be used to override the base types for entity classes which is needed if you have previously generated the wrapper classes with an extension (eg. Microsoft.Xrm.Client.CodeGeneration.CodeCustomization).

To use the generated attribute constants:

Contact contact = new Contact();
contact.Attributes[Contact.firstnameAttribute] = &quot;Michael&quot;;
contact.Attributes[Contact.lastnameAttribute] = &quot;Palmer&quot;;