Search code examples
c#.net-coreodatadynamics-crm

Extracting classes from ODataV4 Metadata XML in .NET-core


I downloaded the file ODataV4Metadata.xml from Microsoft Dynamics 365. This file contains many EntityType tags in which classes are described. For reference, this is how it (partly) looks:

<Schema xmlns="http://docs.oasis-open.org/odata/ns/edm" Namespace="Microsoft.Dynamics.CRM" Alias="mscrm">
            <EntityType Name="crmbaseentity" Abstract="true" />
            <EntityType Name="accountleads" BaseType="mscrm.crmbaseentity">
                <Key>
                    <PropertyRef Name="accountleadid" />
                </Key>
                <Property Name="accountleadid" Type="Edm.Guid" />
                <Property Name="overriddencreatedon" Type="Edm.DateTimeOffset" />
                <Property Name="timezoneruleversionnumber" Type="Edm.Int32" />
                <Property Name="importsequencenumber" Type="Edm.Int32" />
...etc

This should, for example, generate a class called Accountleads, with properties like

[DataMember(Name = "overriddencreatedon")]
        public System.DateTimeOffset? Overriddencreatedon
        {
            get
            {
                return this._Overriddencreatedon;
            }
            set
            {
                this._Overriddencreatedon = value;
            }
         }

As I'm working in .NET-core it seems rather impossible. I was able to generate a HUGE (100k lines of code) file consisting out of all the EntityTypes with lots of comments. However, it seems I am not able to do this in .NET-core, although I am able to use the generated classes. The second problem is, it generates just one file, with all classes in it (and it doesn't include all the namespaces beforehand using the using keyword)

Is there any tool which has some more flexibility, works in .NET-core and generates classes in separate files? Googling it gives many solutions in ASP.NET and .NET v4.

If necessary I will make an Open Source tool to do this, but maybe I haven't looked at enough places.


Sources I checked:


Solution

  • The out-of-box tool for creating early-bound proxy classes is CrmSvcUtil.

    Daryl LaBar has written the Early Bound Generator for XrmToolbox, which I believe leverages CrmSvcUtil.

    There's a commercial VS add-on for D365 called XrmToolkit that includes the ability to create proxy classes (using a proprietary algorithm, so they are different from the classes that CrmSvcUtil generates). This is the tool I use, and it does create each class as a separate file.

    As a side note, Jason Lattimer's D365 Developer Extensions has a lot of helpful features, but I don't believe it has built-in proxy class generation.