proxytypes - phuocle/Dynamics-Crm-DevKit GitHub Wiki
URL: https://github.com/phuocle/Dynamics-Crm-DevKit/wiki/cli/proxytypes
The proxytypes task generates early-bound proxy type classes using CrmSvcUtil.exe with custom extensions.
DynamicsCrm.DevKit.Cli.exe /conn:"YourConnectionString" /json:"DynamicsCrm.DevKit.Cli.json" /type:proxytypes /profile:"ProfileName"OR without connection string (using saved connection from SDK Login):
DynamicsCrm.DevKit.Cli.exe /sdklogin:"yes" /json:"DynamicsCrm.DevKit.Cli.json" /type:proxytypes /profile:"ProfileName"| Parameter | Description | Example |
|---|---|---|
/json |
Path to DynamicsCrm.DevKit.Cli.json file | "/json:DynamicsCrm.DevKit.Cli.json" |
/type |
Task type (must be "proxytypes") | "/type:proxytypes" |
/profile |
Profile name from json file | "/profile:DEFAULT" |
| Parameter | Description | Example |
|---|---|---|
/conn |
Dynamics 365 connection string | "/conn:AuthType=Office365;Url=https://yourorg.crm.dynamics.com" |
/sdklogin |
Use SDK login dialog (alternative to /conn) | "/sdklogin:yes" |
Add a proxytypes section in your DynamicsCrm.DevKit.Cli.json:
{
"proxytypes": [
{
"profile": "DEFAULT",
"namespace": "Dev.DevKit.ProxyTypes",
"output": "Dev.DevKit.ProxyTypes\\ProxyTypes.cs",
"language": "CS",
"generateGlobalOptionSets": "true",
"generateActions": "true"
}
]
}| Property | Type | Required | Description | Default |
|---|---|---|---|---|
profile |
string | Yes | Profile identifier | - |
namespace |
string | Yes | Namespace for generated classes | - |
output |
string | Yes | Output file path (relative to json) | - |
language |
string | No | Programming language: "CS" or "VB"
|
"CS" |
generateGlobalOptionSets |
string | No | Generate global option sets: "true" or "false"
|
"true" |
generateActions |
string | No | Generate custom actions: "true" or "false"
|
"true" |
Uses DynamicsCrm.DevKit.CrmSvcUtilExtensions for:
- Clean code formatting
- Improved naming conventions
- Additional metadata
- Better organization
- Entities: All standard and custom entities
- Option Sets: Local and global option sets
- Actions: Custom actions and workflow messages
- Relationships: 1:N, N:1, N:N relationships
Generates a single .cs or .vb file containing:
- Entity classes with properties
- Option set enumerations
- Relationship properties
- Action request/response classes
DynamicsCrm.DevKit.Cli.exe ^
/conn:"AuthType=Office365;Url=https://contoso.crm.dynamics.com;[email protected];Password=pass" ^
/json:"DynamicsCrm.DevKit.Cli.json" ^
/type:proxytypes ^
/profile:"DEFAULT"JSON:
{
"proxytypes": [
{
"profile": "DEFAULT",
"namespace": "MyProject.ProxyTypes",
"output": "Shared\\ProxyTypes.cs",
"language": "CS",
"generateGlobalOptionSets": "true",
"generateActions": "true"
}
]
}DynamicsCrm.DevKit.Cli.exe ^
/sdklogin:"yes" ^
/json:"DynamicsCrm.DevKit.Cli.json" ^
/type:proxytypes ^
/profile:"DEFAULT"Workflow:
- Opens login dialog
- Saves connection for current session
- Generates proxy types
- Connection is cached for subsequent uses
{
"proxytypes": [
{
"profile": "VBNET",
"namespace": "MyProject.ProxyTypes",
"output": "Shared\\ProxyTypes.vb",
"language": "VB",
"generateGlobalOptionSets": "true",
"generateActions": "true"
}
]
}{
"proxytypes": [
{
"profile": "MINIMAL",
"namespace": "MyProject.Entities",
"output": "Entities\\EarlyBound.cs",
"language": "CS",
"generateGlobalOptionSets": "false",
"generateActions": "false"
}
]
}namespace Dev.DevKit.ProxyTypes
{
[EntityLogicalName("account")]
public partial class Account : Entity
{
public static class Fields
{
public const string AccountId = "accountid";
public const string Name = "name";
public const string PrimaryContactId = "primarycontactid";
}
public Guid AccountId
{
get { return GetAttributeValue<Guid>("accountid"); }
set { SetAttributeValue("accountid", value); }
}
public string Name
{
get { return GetAttributeValue<string>("name"); }
set { SetAttributeValue("name", value); }
}
public EntityReference PrimaryContactId
{
get { return GetAttributeValue<EntityReference>("primarycontactid"); }
set { SetAttributeValue("primarycontactid", value); }
}
}
}public enum Account_StatusCode
{
Active = 1,
Inactive = 2
}[RequestProxy(typeof(new_CustomActionRequest))]
[ResponseProxy(typeof(new_CustomActionResponse))]
public class new_CustomAction
{
// Request and Response properties
}Sample output:
|
| ? Generating proxy types...
| ? Connected to: https://contoso.crm.dynamics.com
| ? Output: Dev.DevKit.ProxyTypes\ProxyTypes.cs
| ?? Entities: 150
| ?? Global Option Sets: 50
| ?? Actions: 10
| ? Generation completed successfully
|
The task uses DynamicsCrm.DevKit.CrmSvcUtilExtensions.dll which provides:
- INamingService: Improved naming conventions
- ICodeWriterFilterService: Enhanced entity/attribute filtering
- ICodeGenerationService: Better code organization
- ICustomizeCodeDomService: Custom code DOM modifications
- Cleaner generated code
- Better IntelliSense
- Consistent naming
- Additional metadata attributes
Solution: Ensure Microsoft.CrmSdk.XrmTooling.CrmConnector.PowerShell is installed via NuGet
Solution: Large metadata may take time. Be patient or filter entities if possible
Solution: Ensure user has privileges to read entity metadata
Solution: Close Visual Studio or any process using the output file
- Use specific entity lists if possible (requires custom filtering)
- Generate during off-peak hours for large organizations
- Disable unused options (global option sets, actions) if not needed
-
Use
/sdkloginto avoid typing connection strings repeatedly
- Version control the generated file
- Don't manually edit the generated code (use partial classes)
- Regenerate periodically to stay in sync with metadata changes
- Use partial classes for custom logic
// In a separate file: Account.Custom.cs
namespace Dev.DevKit.ProxyTypes
{
public partial class Account
{
// Your custom properties and methods
public string FullAddress
{
get { return $"{Address1_Line1}, {Address1_City}"; }
}
}
}- task: PowerShell@2
displayName: 'Generate Proxy Types'
inputs:
targetType: 'inline'
script: |
.\DynamicsCrm.DevKit.Cli.exe `
/conn:"$(ConnectionString)" `
/json:"DynamicsCrm.DevKit.Cli.json" `
/type:proxytypes `
/profile:"DEFAULT"- name: Generate Proxy Types
run: |
.\DynamicsCrm.DevKit.Cli.exe `
/conn:"${{ secrets.D365_CONNECTION }}" `
/json:"DynamicsCrm.DevKit.Cli.json" `
/type:proxytypes `
/profile:"DEFAULT"- generators - Generate late-bound classes (alternative approach)