CrmSvcUtil.exe is a command-line code generation tool for use with Microsoft Dynamics 365 (online & on-premises). This tool generates early-bound .NET Framework classes that represent the entity data model used by Microsoft Dynamics 365. This tool is in the SDK package in the SDK\Bin folder. Download the Microsoft Dynamics CRM SDK package.

The CrmSvcUtil.exe tool creates a Microsoft Visual C# or Microsoft Visual Basic .NET output file that contains strongly-typed classes for entities in your organization. This includes custom entities and attributes. This output file contains one class for each entity, providing early binding and IntelliSense support in Microsoft Visual Studio to aid you as you write custom code. The generated classes are partial classes that can be extended with custom business logic in separate files. You can also create extensions to this tool. For more information, see Create extensions for the code generation tool.

The tool can also be used to generate a class derived from the OrganizationServiceContext class that acts as an entity container in the entity data model. This service context provides the facilities for tracking changes and managing identities, concurrency, and relationships. This class also exposes a SaveChanges method that writes inserts, updates, and deletes records in Microsoft Dynamics 365. For more information, see Use the OrganizationServiceContext class.

The code generation tool takes several parameters that determine the contents of the file that is created. The parameters can be passed in from the command line when you run the tool or in a .NET-connected application configuration file.

The classes created by the code generation tool are designed to be built into a class library that can be referenced by projects that use Microsoft Dynamics 365. After you have generated the class file using the tool, you should add the file to your Visual Studio project. You must also add references to several assemblies that the generated classes are dependent upon.

The following lists assemblies that must be referenced in your project when you use the generated code file.

For the username parameter, type the user name that is used to sign in to Microsoft account or Microsoft Office 365. You can look up the correct URL in the web application by selecting Settings, navigating to Customizations, and then choosing Developer Resources. The URL is shown under Organization Service.

To list the supported command-line parameters, use the following command.

When you run the tool against Microsoft Dynamics 365 (online) using the Microsoft account identity provider, you no longer have to supply the deviceid and devicepassword parameters from the command line. The tool registers your device automatically. However, you can manually register your device and obtain values for these parameters by first compiling and running the DeviceRegistration code sample as described here.

The following table lists the code generation tool parameters and a gives a brief description of their use.

Parameter

Shortcut

Description

Required

deviceid

di

Device ID used when you connect to the Online server for authentication. Only required if the device ID has not been stored on disk in the %USERPROFILE%\LiveDeviceID folder. Only used with the Microsoft account identity provider.

False

devicepassword

dp

Device password that is used when you connect to the Online server for authentication. Only required if the device password has not been stored on disk in the %USERPROFILE%\LiveDeviceID folder. Only used with the Microsoft account identity provider.

False

domain

d

The domain to authenticate against when you connect to the server.

False

url

The URL for the Organization service.

True

out

o

The file name for the generated code.

True

language

l

The language to generate the code in. This can be either “CS” or “VB”. The default value is “CS”.

False

namespace

n

The namespace for the generated code. The default is the global namespace.

False

username

u

The user name to use when you connect to the server for authentication.

False

password

p

The password to use when you connect to the server for authentication.

False

servicecontextname

The name of the generated organization service context class. If no value is supplied, no service context is created.

False

help

?

Show usage information.

False

nologo

Suppress the banner at runtime.

False

generateActions

Generate request and response classes for actions.

interactivelogin

il

When set to true, a dialog to log into the Dynamics 365 service is displayed. All other connection related parameters specified on the command line are
ignored.

The following examples show how to use of the code generation tool from the command line for each deployment type. Note that user name and password are optional parameters. If your credentials for the target Microsoft Dynamics 365 server are stored in the Windows credential vault, you do not have to provide them to run the code generation tool.

The following sample shows how to run the code generation tool by using claims authentication in Active Directory. Note the use of https because this sample server is using Transport Layer Security (TLS) or Secure Sockets Layer (SSL).

The following sample shows how to run the code generation tool for Microsoft Dynamics 365 (online). The first example is for the Microsoft account identity provider and the second is for the Office 365 identity provider.

The CrmSvcUtil.exe.config configuration file must be in the same folder as the CrmSvcUtil.exe tool. The configuration file uses the standard key/value pairs in the appSettings section. However, if you enter a value at the command line, that value will be used instead of the one in the configuration file. Any key/value pairs found in the application configuration file that do not match any of the expected parameters are ignored.

Do not include the url and namespace parameters in the configuration file. These must be entered from the command line when the CrmSvcUtil.exe tool is being run.

The following sample shows how to configure the output file and the domain name parameters in the application configuration file using shortcut keys.