Allow breaking oData client generated files into multiple files so you do not end up with one huge 50+MB file that crashes Visual Studio when debugging
NOTE: I used Visual Studio 2015 in my testing.
To find the edits to the standard oData T4 template, you can search for "xxce" which is the prefix used for any customizations.
To use these files:
- Install the "OData v4 Client Code Generator" Visual Studio extension (Open Visual Studio > Tools > Extensions and Updates > search for "OData v4 Client Code Generator" published by Microsoft)
- In your project, add new item, and select "OData Client", name the file "D365ODataClient.tt"
- Replace the generated tt and ttinclude files with the files from this project
To refresh the data entity client
- Open your browser of preference.
- Navigate to your D365 instance base URL to get auth token first. For ex: https://usnconeboxax1aos.cloud.onebox.dynamics.com
- After logged in, go here: {baseURL}/data/$metadata For ex: https://usnconeboxax1aos.cloud.onebox.dynamics.com/data/$metadata
- Allow it to load, might take several minutes.
- After it finishes loading, then right click and download the file contents to c:\temp\data$metadata.xml
- Open the D365ODataClient.tt file
- Edit this line to point to the file: public const string MetadataDocumentUri = "file:///C:/Temp/data$metadata.xml";
- Save the .tt file, and click "OK" when prompted to refresh it. If you aren't prompted when saving the file, then right click on the "D365ODataClient.tt" file and choose "run custom tool"
- This will regenerate the odata client classes located under the D365ODataClient namespace (or whatever you have set as the NamespacePrefix in the D365ODataClient.tt file), so that you can use any new Data Entities, or access newly added fields/actions/etc.
Credits:
I leveraged this awesome helper class written by Damien Guard (with a few tweaks) to break out the files.
https://github.com/damieng/DamienGKit/blob/master/T4/MultipleOutputHelper/MultipleOutputHelper.ttinclude
More info about this MultipleOutputHelper here: https://damieng.com/blog/2009/11/06/multiple-outputs-from-t4-made-easy-revisited