Generate EarlyBoundClass File With Code GenerationTool In Dynamics CRM

Introduction

In Dynamics 365 CRM or Power Platform, under core tools category, the Code Generation Tool CrmSvcUtil.exe is useful to generate an early bound class file which makes life easy for the developer by simply instantiating the class. Visual Studio Intellisense provides the names of properties and relationships without the need of explicitly memorizing names of properties. By using the following process one can easily generate an early bound class file in a few minutes. 

Step 1

Navigate to the folder where Core CRM Tools are generated by Power shell as shown in below, if you want to know about how to generate CRM tools using power shell, refer to my earlier post.

Generate EarlyBoundClass File with Code GenerationTool in Dynamics CRM

Step 2

After step 1, copy the path of Core Tools and then open Developer Command Prompt of Visual Studio from Visual studio Folder which is present in the Windows Start Menu, and double click on it and open as shown below,

Generate EarlyBoundClass File with Code GenerationTool in Dynamics CRM

Step 3

After step 2, the Developer Command Prompt gets opened, here as an example, you could see Developer Command Prompt for VS 2019 gets opened as shown below,

Generate EarlyBoundClass File with Code GenerationTool in Dynamics CRM

Step 4

After Step3, type the cd and Paste path that is copied in step2 and click on enter key as shown below,

Example

cd C:\devtools\Tools\CoreTools

Generate EarlyBoundClass File with Code GenerationTool in Dynamics CRM

Step 5

After step 4, we must give output file name where early bound class content gets generated, namespace name, service Context Name, and click on enter as shown below,

Syntax

CrmSvcUtil.exe /interactivelogin ^
/out:<outputFilename>.cs ^
/namespace:<outputNamespace> ^
/serviceContextName:<serviceContextName> ^
/generateActions

Example

CrmSvcUtil.exe /interactivelogin ^
/out:Entity.cs ^
/namespace:earlybound ^
/serviceContextName:earlyboundContext ^
/generateActions

Generate EarlyBoundClass File with Code GenerationTool in Dynamics CRM

Step 6

After Step5, a popup window will come where provide required CRM Environment details and click on login as shown below figure,

Generate EarlyBoundClass File with Code GenerationTool in Dynamics CRM

Step 7

After Step 6, after successful login to respective Dynamics CRM post provision of username and password then the window will get closed as shown below,

Generate EarlyBoundClass File with Code GenerationTool in Dynamics CRM

Step 8

After Step7, in the background early bound class generation will happen and the respective class file gets generated. Here as an example Entity.cs file will be created, and a message can be seen in the dos command prompt as shown below,

Generate EarlyBoundClass File with Code GenerationTool in Dynamics CRM

Step 9

After Step 8, to test whether the given Entity.cs file got generated or not, navigate to the core tools folder and observe Entity.cs file gets generated with the latest timestamp as shown below,

Generate EarlyBoundClass File with Code GenerationTool in Dynamics CRM

Step 10

After Step 9, to test whether the given Entity.cs file has content or not, open Entity.cs file and see content as shown below,

Generate EarlyBoundClass File with Code GenerationTool in Dynamics CRM

Note

  1. Make sure to execute the code generation tool from the respective Core Tools Folder.
  2. If any case if you want to run this tool from another folder location, then make sure that a copy of the Microsoft.Xrm.Sdk.dll assembly is in that same folder.

References - Generate early-bound classes for the Organization service

Conclusion

In this way, one can easily generate an early bound class file that can be used in CRM custom development in few minutes.