Dynamics 365 CRM插件编写

1.新建一个类库
Dynamics 365 CRM插件编写_第1张图片
2.填写名称保存位置
Dynamics 365 CRM插件编写_第2张图片
3.选择目标框架.net framework 4.6.2
4.新建一个类
Dynamics 365 CRM插件编写_第3张图片
5.安装nuget包
Dynamics 365 CRM插件编写_第4张图片
6.对插件进行签名
Dynamics 365 CRM插件编写_第5张图片
Dynamics 365 CRM插件编写_第6张图片
Dynamics 365 CRM插件编写_第7张图片
7.写好代码编译一下

// Obtain the tracing service
ITracingService tracingService =
(ITracingService)serviceProvider.GetService(typeof(ITracingService));

// Obtain the execution context from the service provider.  
IPluginExecutionContext context = (IPluginExecutionContext)
    serviceProvider.GetService(typeof(IPluginExecutionContext));

// The InputParameters collection contains all the data passed in the message request.  
if (context.InputParameters.Contains("Target") &&
    context.InputParameters["Target"] is Entity)
{
    // Obtain the target entity from the input parameters.  
    Entity entity = (Entity)context.InputParameters["Target"];

    // Obtain the organization service reference which you will need for  
    // web service calls.  
    IOrganizationServiceFactory serviceFactory =
        (IOrganizationServiceFactory)serviceProvider.GetService(typeof(IOrganizationServiceFactory));
    IOrganizationService service = serviceFactory.CreateOrganizationService(context.UserId);

    try
    {
        // Plug-in business logic goes here.  
    }

    catch (FaultException<OrganizationServiceFault> ex)
    {
        throw new InvalidPluginExecutionException("An error occurred in FollowUpPlugin.", ex);
    }

    catch (Exception ex)
    {
        tracingService.Trace("FollowUpPlugin: {0}", ex.ToString());
        throw;
    }
}

最后用插件工具注册发布就好了
详情参考官方文档:Tutorial: Write and register a plug-in

你可能感兴趣的:(Dynamics,365,CRM,c#)