Was this page helpful?
Your feedback about this content is important. Let us know what you think.
Additional feedback?
1500 characters remaining
Create extensions for the code generation tool
Collapse the table of content
Expand the table of content

Create extensions for the code generation tool

Applies To: CRM 2015 on-prem, CRM Online

You can extend the functionality of the code generation tool by specifying additional command-line parameters and parameter values. To specify a parameter, add the following to the command line: /<parametername>:<class name>,<assembly name>. Note that assembly name does not include the .dll extension. As an alternative, you can add the equivalent value to the config file in the format “<add key=”<parametername>” value=”<class name>,<assembly name>” />”.

The following table lists the parameters that you can use.


Parameter name Interface Name Description



Called after the CodeDOM generation has been completed, assuming the default instance of ICodeGenerationService. It is useful for generating additional classes, such as the constants in picklists.



Called during the process of CodeDOM generation, assuming the default instance of ICodeGenerationService, to determine whether a specific object or property should be generated.



Called during the process of CodeDOM generation, assuming the default instance of ICodeGenerationService, to determine whether a specific message should be generated. This should not be used for requests/responses as these are already generated in Microsoft.Crm.Sdk.Proxy.dll and Microsoft.Xrm.Sdk.dll.



Called to retrieve the metadata from the server. This may be called multiple times during the generation process, so the data should be cached.



Core implementation of the CodeDOM generation. If this is changed, the other extensions may not behave in the manner described.



Called during the CodeDOM generation to determine the name for objects, assuming the default implementation.

The implementation of these interfaces must have one of the following constructors:

MyNamingService(IDictionary<string, string> parameters)
MyNamingService(INamingServicedefaultService, IDictionary<string, string> parameters)

The Microsoft.Crm.Services.Utility namespace is defined in CrmSvcUtil.exe. Add a reference to CrmSvcUtil.exe in your Microsoft Visual Studio code generation tool extension projects.

Sample extension to generate enumerations for option sets

The following sample code demonstrates how to write an extension.

using System;

using Microsoft.Crm.Services.Utility;
using Microsoft.Xrm.Sdk.Metadata;

/// <summary>
/// Sample extension for the CrmSvcUtil.exe tool that generates early-bound
/// classes for custom entities.
/// </summary>
public sealed class BasicFilteringService : ICodeWriterFilterService
    public BasicFilteringService(ICodeWriterFilterService defaultService)
        this.DefaultService = defaultService;

    private ICodeWriterFilterService DefaultService { get; set; }

    bool ICodeWriterFilterService.GenerateAttribute(AttributeMetadata attributeMetadata, IServiceProvider services)
        return this.DefaultService.GenerateAttribute(attributeMetadata, services);

    bool ICodeWriterFilterService.GenerateEntity(EntityMetadata entityMetadata, IServiceProvider services)
        if (!entityMetadata.IsCustomEntity.GetValueOrDefault()) { return false; }
        return this.DefaultService.GenerateEntity(entityMetadata, services);

    bool ICodeWriterFilterService.GenerateOption(OptionMetadata optionMetadata, IServiceProvider services)
        return this.DefaultService.GenerateOption(optionMetadata, services);

    bool ICodeWriterFilterService.GenerateOptionSet(OptionSetMetadataBase optionSetMetadata, IServiceProvider services)
        return this.DefaultService.GenerateOptionSet(optionSetMetadata, services);

    bool ICodeWriterFilterService.GenerateRelationship(RelationshipMetadataBase relationshipMetadata, EntityMetadata otherEntityMetadata,
    IServiceProvider services)
        return this.DefaultService.GenerateRelationship(relationshipMetadata, otherEntityMetadata, services);

    bool ICodeWriterFilterService.GenerateServiceContext(IServiceProvider services)
        return this.DefaultService.GenerateServiceContext(services);

You can find this sample code and the GeneratePicklistEnums sample extension in the following folder SampleCode\CS\CrmSvcUtilExtensions of the SDK. Download the Microsoft Dynamics CRM SDK package. The GeneratePicklistEnums sample extension outputs a source code file that contains enumerations for all option sets, state codes, and status codes. For an example of how to use these enumerations, see the SampleCode\CS\QuickStart sample.

See Also

Microsoft Dynamics CRM 2015 and Microsoft Dynamics CRM Online
Send comments about this topic to Microsoft.
© 2015 Microsoft. All rights reserved.
© 2015 Microsoft