Here are the steps:
- Open up the solution we created in our last blog.
- Add a new class file to the project. I named my class file BasicFilteringService.cs. I copied this file from the sdk samples. Here is the code. The code will restrict the code generation utility to generate just the custom entities.
using System; using Microsoft.Crm.Services.Utility; using Microsoft.Xrm.Sdk.Metadata; namespace CRMExtensions { ///
/// Sample extension for the CrmSvcUtil.exe tool that generates early-bound /// classes for custom entities. /// 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); } } // } - Add codewriterfilter parameter to CrmSvcUtil.exe.config file. <add key="codewriterfilter" value="CRMExtensions.BasicFilteringService, CRMExtensions"/>
- Press F5 to debug the solution. It will generate a file with the name specified in “o” or output parameter.
- Check the size of the file. It will be very very small as compare to the file generated without codewriterfilter. The size of the file created for default CRM online organization with codewriterfilter is just 44 kb as compared to 4.7 mb without codewriterfilter.
if (!entityMetadata.IsCustomEntity.GetValueOrDefault()) { return false; }with
if (entityMetadata.LogicalName!="account") { return false; }The utility will generate just account entity. Happy programming.
Brilliant, thanks for the tip Amreek.
ReplyDeleteThanks for the feedback buddy.
ReplyDeletereally helped me! thanks
ReplyDeleteI m glad it helped. Thanks mate.
DeleteReally nice. Thanks Amreek. Do you know if this works on the crmsrvutil in 4.0?
ReplyDeleteThanks Mate.
DeleteTry this tool (https://xrmearlyboundgenerator.codeplex.com/)! It will also limit which Entities are generated, as well as a whole list of other features.
ReplyDeleteThanks for sharing.
ReplyDelete