【转】Dynamics 365 Customer Engagement中插件的调试
微軟動(dòng)態(tài)CRM專家羅勇 ,回復(fù)319或者20190319可方便獲取本文,同時(shí)可以在第一間得到我發(fā)布的最新博文信息,follow me!我的網(wǎng)站是 www.luoyong.me 。
本文主要根據(jù)官方的教程?Tutorial: Debug a plug-in?而寫,使用的環(huán)境是我自己搭建在Azure VM中的,版本為?版本 1612 (9.0.2.3034) (DB 9.0.2.3034) (本地) 。
最近開(kāi)始我的博文使用的Dynamics 365 Customer Engagement版本都不再使用V8.2版本,而會(huì)使用V9.X版本。插件程序集需要引用?Microsoft.CrmSdk.CoreAssemblies 這個(gè)NuGet包的最新版本,當(dāng)然針對(duì)的.NET Framework 也要變化,使用的版本是 4.6.2版本,若還沒(méi)有下載,可以去?.NET SDKs for Visual Studio?下載?.NET Framework 4.6.2 Develper Pack?安裝即可。
根據(jù)?Tutorial: Write and register a plug-in?,我注冊(cè)個(gè)簡(jiǎn)單的插件,代碼很簡(jiǎn)單,如下:
using System; using System.Security.Cryptography; using System.ServiceModel; using Microsoft.Xrm.Sdk;namespace CRM.Plugins {public class PreWorkOrderCreate : IPlugin{public void Execute(IServiceProvider serviceProvider){ITracingService tracingService = (ITracingService)serviceProvider.GetService(typeof(ITracingService));IPluginExecutionContext context = (IPluginExecutionContext)serviceProvider.GetService(typeof(IPluginExecutionContext));if (context.InputParameters.Contains("Target") && context.InputParameters["Target"] is Entity){Entity currentEntity = (Entity)context.InputParameters["Target"];IOrganizationServiceFactory serviceFactory = (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);try{var rng = new RNGCryptoServiceProvider();byte[] data = new byte[100000];int seed = BitConverter.ToInt32(data, 0);var rand = new Random(seed);currentEntity["ly_autonum"] = rand.Next(1, 100000).ToString("000000");}catch (FaultException<OrganizationServiceFault> ex){throw new InvalidPluginExecutionException("An error occurred in PreWorkOrderCreate.", ex);}catch (Exception ex){tracingService.Trace("PreWorkOrderCreate unexpected exception: {0}", ex.Message);throw;}}}} }?
這里貼兩個(gè)注冊(cè)插件的截圖:因?yàn)槲易约捍罱ǖ腛P V9.0環(huán)境注冊(cè)插件報(bào)錯(cuò),所以我用CRM Online來(lái)完成本博文的,報(bào)錯(cuò)信息如下:此插件程序集使用了版本 4.6.2 的 .NET Framework。目前,Microsoft Dynamics 365 要求插件程序集使用版本 4.5.2 的 .NET Framework。請(qǐng)使用 .NET Framework 版本 4.5.2 重新生成此程序集,然后重試。
特別說(shuō)明,本地部署版本注冊(cè)插件報(bào)錯(cuò)的問(wèn)題在?Microsoft Dynamics 365 Server v9.0 (on-premises) Update 0.3?中解決了。
?
?
?然后我測(cè)試下插件代碼基本有效。
下面開(kāi)始講述如何調(diào)試插件。首先點(diǎn)擊插件注冊(cè)工具上的【Install Profiler】安裝,我安裝失敗,報(bào)錯(cuò)如下,原來(lái)是我這個(gè)用戶雖然有系統(tǒng)管理員角色,但是其【Access Mode】為Administration,所以會(huì)缺少很多權(quán)限。將這個(gè)用戶在Office 365 Admin Portal中授予其Dynamics 365 Customer Engagement的許可(License)稍等一會(huì)兒待該用戶的【Access Mode】變成Read-Write后重新點(diǎn)擊插件注冊(cè)工具上的【Install Profiler】按鈕即可。
Microsoft.Crm.CrmSecurityException: SecLib::CheckPrivilege failed. User: 28eafdf4-363a-e911-a9ae-000d3a1ad5ea, PrivilegeName: prvCreateContractTemplate, PrivilegeId: d6cd0451-bca1-42b0-9ffd-5596a3b9a8f9, Required Depth: Basic, BusinessUnitId: 5d2366b2-3b1d-e911-a9b1-000d3a1adfba, MetadataCache Privileges Count: 3998, User Privileges Count: 555 ---> Microsoft.Crm.CrmSecurityException: SecLib::CheckPrivilege failed. User: 28eafdf4-363a-e911-a9ae-000d3a1ad5ea, PrivilegeName: prvCreateContractTemplate, PrivilegeId: d6cd0451-bca1-42b0-9ffd-5596a3b9a8f9, Required Depth: Basic, BusinessUnitId: 5d2366b2-3b1d-e911-a9b1-000d3a1adfba, MetadataCache Privileges Count: 3998, User Privileges Count: 555
?
?
?然后選中我要調(diào)試的插件步驟,然后點(diǎn)擊 【Start Profiling】這個(gè)菜單項(xiàng)
?
?保持不變,直接點(diǎn)擊 【OK】按鈕。
?
【Start Profiling】成功的話可以看到這個(gè)插件步驟后面多了【Profiled】,然后我要觸發(fā)這個(gè)插件的執(zhí)行,我這里就簡(jiǎn)單,創(chuàng)建一條【工單】記錄就可以。然后點(diǎn)擊 【Stop Profiling】按鈕停止Profile,Stop Profiling成功的話,這個(gè)插件步驟后面多了的【Profiled】字眼會(huì)消失。
?
在選中要調(diào)試的插件步驟的前提下,點(diǎn)擊 【Debug】按鈕。
?
在彈出的對(duì)話框中,點(diǎn)擊Profile 文本框旁邊的向下按鈕,會(huì)彈出【Select Profile From CRM】窗口,選擇合適的記錄(每次記錄成功的Profile都有一條記錄,所以可能會(huì)出來(lái)多條,根據(jù)Created和Type Name選擇合適的)后點(diǎn)擊【Select】按鈕。
?
然后選擇合適的【Assembly Location】和【Plugin】,也就是插件編譯的程序集,此時(shí)不要點(diǎn)擊【Start Execution】按鈕,請(qǐng)繼續(xù)后面的步驟。
?
然后在Visual Studio對(duì)插件的代碼設(shè)置好斷點(diǎn),再點(diǎn)擊【Debug】 > 【Attach to Process】,在彈出的如下【Attach to Process】框中,找到名稱為【PluginRegistration.exe】的Process (前面步驟的截圖中已經(jīng)告知了這個(gè)Process 的ID為16700,剛好對(duì)上),點(diǎn)擊【Attach】后。點(diǎn)擊前面步驟截圖中的【Start Execution】按鈕。
?
可以看到下圖,擊中斷點(diǎn),你可以盡情調(diào)試?yán)?/p>
總結(jié)
以上是生活随笔為你收集整理的【转】Dynamics 365 Customer Engagement中插件的调试的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問(wèn)題。
- 上一篇: 曝《海王2》将删除“海后”戏份:重新选角
- 下一篇: 2千元就能买到旗舰配置!2022上半年真