Skip to content

Generate Context

Michael Lisby edited this page Feb 18, 2022 · 10 revisions

The executable can be used from a command prompt, but also directly from code, if you want the generation of the context files to be a part of your workflow.

Command prompt

Example usage from a command prompt:

XrmContext.exe /url:http://<serverName>/<organizationName>/XRMServices/2011/Organization.svc  
        /out:..\path\to\BusinessDomain /username:<username> /password:<password> /domain:<domainName>

Simple Generation Example in F#

It can also be run through code by referencing the executable and calling the GetContext function.

open Microsoft.Xrm.Sdk.Client
open DG.XrmContext

XrmContext.GenerateFromCrm(
  "http://<serverName>/<organizationName>/XRMServices/2011/Organization.svc", 
  "username", "password", 
  out = @"..\path\to\BusinessDomain")

Arguments

The arguments are similar to those given to the CrmSvcUtil tool, but with a few additions. Here is the full list of arguments:

Connection args

Argument Shorthand Description
url URL to the Organization.svc
username u, usr CRM Username
password p, pwd CRM Password
domain d, dmn Domain to use for CRM
ap Authentication Provider Type
mfaAppId Azure Application Id
mfaReturnUrl Return URL of the Azure Application
mfaClientSecret Azure Application Secret
method OAuth, ClientSecret, ConnectionString or Proxy (Deprecated)
connectionString Connection String used for authentication

Generation arguments

Argument Shorthand Description
out o Output directory for the generated files.
solutions ss Comma-separated list of solutions names. Generates code for the entities found in these solutions.
entities es Comma-separated list of logical names of the entities it should generate code for. This is additive with the entities gotten via the solutions argument.
namespace ns The namespace for the generated code. The default is the global namespace.
servicecontextname scn The name of the generated organization service context class. If no value is supplied, no service context is created.
deprecatedprefix dp Marks all attributes with the given prefix in their display name as deprecated.
sdkversion sv The version of CrmSdk.CoreAssemblies used by your library. Automatically finds the matching version from CRM if nothing is specified.
intersect is Comma-separated list of named semicolon-separated lists of entity logical names that should be intersected. Example: ICustomer:account;contact, IActivity: phonecall;email;task
onefile of Set to false to genereate one file per entity instead of one file for the entire context
labelMappings lm Comma-separated list of mappings between unicodes and the mapped string. Example:\u2714\uFE0F: checkmark, \u26D4\uFE0F: stopsign
localizations l Comma seperated list of LCIDs to include as OptionSetMetadataAttribute the, default is to use UserLocalizedLabel.

Special arguments

Argument Shorthand Description
save Flag to indicate to retrieve the metadata and store it in a file.
load Flag to indicate to load the metadata from a local file instead of contacting CRM.
genconfig gc Flag to indicate a dummy configuration file should be generated

You can also view this list of arguments using the "/help" argument.

Configuration file

If no arguments are given to the executable, it will check if there is an configuration file in the same folder with arguments it can use instead.

If you want to generate a dummy configuration file to use for arguments, you can use the "/genconfig" argument. If you want to use a mix of the arguments from the configuration file and arguments passed to the executable, you can specify the "/useconfig" argument in the command-line.