Dynamics 365 SDK Metadata Diagram Tool
I needed to document the as-built data model (entities, attributes and relationships) for customer's Dynamics 365 implementation and thought I should give the metadata diagram tool that comes with SDK a go ...
The metadata diagram tool has been around quite sometime, it is located at: SDK\SampleCode\CS\Metadata\Diagram
It seems like the solution hasn't been updated for quite sometime, and it is still trying to connect to the 2011 organization web service to get the organization service proxy object. And during my initial testing, it couldn't connect to Dynamics 365 instance (8.2).
So I had to modify the code a bit to get it to work. Here is what you need to do:
Open the solution in Visual Studio, I am using 2015. Restore the NuGet packages, and upgrade to the latest version of the packages.
Also download and install the Microsoft.CrmSdk.XrmTooling.CoreAssembly NuGet package, the solution will eventually has the following packages installed.
<packages>
<package id="Microsoft.CrmSdk.CoreAssemblies" version="8.2.0.2" targetFramework="net452" />
<package id="Microsoft.CrmSdk.Deployment" version="8.2.0" targetFramework="net452" />
<package id="Microsoft.CrmSdk.Workflow" version="8.2.0" targetFramework="net452" />
<package id="Microsoft.CrmSdk.XrmTooling.CoreAssembly" version="8.2.0.5" targetFramework="net452" />
<package id="Microsoft.IdentityModel" version="6.1.7600.16394" targetFramework="net452" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.22.302111727" targetFramework="net452" />
</packages>
Open app.config, and put the Dynamics 365 connection string in there:
<connectionStrings>
<add name="crmConn" connectionString="AuthType=Office365;Username=user@company.com; Password=passwordhere;Url=https://customer.crm6.dynamics.com"/>
</connectionStrings>
Open Diagram.Builder.cs file in Visual Studio, and comment out the following code:
// Obtain the target organization's Web address and client logon
// credentials from the user.
//ServerConnection serverConnect = new ServerConnection();
//ServerConnection.Configuration config = serverConnect.GetServerConfiguration();
And remove the using statement completely. Add the below code:
CrmServiceClient crmSvc = new CrmServiceClient(ConfigurationManager.ConnectionStrings["crmConn"].ConnectionString);
if (crmSvc != null && crmSvc.IsReady)
{
// code was in the using statement will now be in here.
}
Now you should be able to compile the project and generate the .exe file.
To run the console app file, open cmd or create a .bat file, and enter something like below.
MetadataDiagramConsole.exe new_software new_topics new_results customer contact
The console app will go through the specified entities to generate a VISO diagram that use the name of the first entity on the command line as the name of the Visio file.
If you don't specify any entity names as parameters, it will generate a VISO diagram for all entities in Dynamics 365.
More information on the diagram being generated can be found here: https://msdn.microsoft.com/en-us/library/jj602918.aspx
The metadata diagram tool has been around quite sometime, it is located at: SDK\SampleCode\CS\Metadata\Diagram
It seems like the solution hasn't been updated for quite sometime, and it is still trying to connect to the 2011 organization web service to get the organization service proxy object. And during my initial testing, it couldn't connect to Dynamics 365 instance (8.2).
So I had to modify the code a bit to get it to work. Here is what you need to do:
Open the solution in Visual Studio, I am using 2015. Restore the NuGet packages, and upgrade to the latest version of the packages.
Also download and install the Microsoft.CrmSdk.XrmTooling.CoreAssembly NuGet package, the solution will eventually has the following packages installed.
<packages>
<package id="Microsoft.CrmSdk.CoreAssemblies" version="8.2.0.2" targetFramework="net452" />
<package id="Microsoft.CrmSdk.Deployment" version="8.2.0" targetFramework="net452" />
<package id="Microsoft.CrmSdk.Workflow" version="8.2.0" targetFramework="net452" />
<package id="Microsoft.CrmSdk.XrmTooling.CoreAssembly" version="8.2.0.5" targetFramework="net452" />
<package id="Microsoft.IdentityModel" version="6.1.7600.16394" targetFramework="net452" />
<package id="Microsoft.IdentityModel.Clients.ActiveDirectory" version="2.22.302111727" targetFramework="net452" />
</packages>
Open app.config, and put the Dynamics 365 connection string in there:
<connectionStrings>
<add name="crmConn" connectionString="AuthType=Office365;Username=user@company.com; Password=passwordhere;Url=https://customer.crm6.dynamics.com"/>
</connectionStrings>
Open Diagram.Builder.cs file in Visual Studio, and comment out the following code:
// Obtain the target organization's Web address and client logon
// credentials from the user.
//ServerConnection serverConnect = new ServerConnection();
//ServerConnection.Configuration config = serverConnect.GetServerConfiguration();
And remove the using statement completely. Add the below code:
CrmServiceClient crmSvc = new CrmServiceClient(ConfigurationManager.ConnectionStrings["crmConn"].ConnectionString);
if (crmSvc != null && crmSvc.IsReady)
{
// code was in the using statement will now be in here.
}
Now you should be able to compile the project and generate the .exe file.
To run the console app file, open cmd or create a .bat file, and enter something like below.
MetadataDiagramConsole.exe new_software new_topics new_results customer contact
The console app will go through the specified entities to generate a VISO diagram that use the name of the first entity on the command line as the name of the Visio file.
If you don't specify any entity names as parameters, it will generate a VISO diagram for all entities in Dynamics 365.
More information on the diagram being generated can be found here: https://msdn.microsoft.com/en-us/library/jj602918.aspx
Thanks for a great blog post! I did this for D365 v9.0 and there were just problems with your instructions.
ReplyDeleteyou need to comment out _serviceProxy.EnableProxyTypes();
you also need to update
RetrieveAllEntitiesResponse response = (RetrieveAllEntitiesResponse)_serviceProxy.Execute(request);
to look like
RetrieveAllEntitiesResponse response = (RetrieveAllEntitiesResponse)crmSvc.Execute(request);
Thanks for the blog and the comment from the user with the code fix. A few other things I had to do to get this working:
ReplyDeleteI could not get the CrmServiceClient to work without changing the constructor. I changed the program to prompt the user for a secure password and email instead of reading them from app.config
System.Net.ServicePointManager.SecurityProtocol = System.Net.SecurityProtocolType.Tls12;
crmSvc = new Microsoft.Xrm.Tooling.Connector.CrmServiceClient(string crmUserId, SecureString crmPassword, "", orgId, useUniqueInstance: true, useSsl: true, isOffice365: true);
Also, my organization uses MFA so I created an app password using this blog post:
https://d365demystified.com/2019/01/12/use-azure-app-passwords-for-mfa-enabled-d365-authentication-from-console-app/
Also, I manually set the Tls12 protocol before initiating the connection.