我正在 Visual Studio 2010 中预先存在的 Microsoft Dynamics CRM 4 解决方案中的新项目中创建新插件。该解决方案已包含已使用插件注册工具成功部署的其他项目/DLL。
但是,当我构建我的项目并将 .dll 文件加载到插件注册工具中时,加载的程序集中没有插件被拾取!
我的插件类包含 IPlugin 接口并已签名。我不知道我还需要做什么?有人有建议吗?
更新:我的班级-
如您所见,我在第一次测试部署中保持简单。
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Data;
using System.Data.Sql;
using System.Data.SqlClient;
using Microsoft.Crm.Sdk;
using Microsoft.Crm.Sdk.Query;
using Microsoft.Crm.SdkTypeProxy;
using System.Web;
using System.Xml;
using System.Runtime.InteropServices;
namespace RI.CRM.Plugins2
{
class SupportAutoNumber : IPlugin
{
public void Execute(IPluginExecutionContext context)
{
if (context == null) throw new InvalidPluginExecutionException("Context is null.", new ArgumentNullException("context"));
// Verify that there is an entity in the target
if (context.InputParameters.Properties.Contains(ParameterName.Target)
&& context.InputParameters.Properties[ParameterName.Target] is DynamicEntity)
{
ICrmService crmService = context.CreateCrmService(true);
DynamicEntity theAutonumber = RetrieveDynamicEntitiesByProperty(crmService, "ri_autonumber", "ri_name", "Support Ticket Numberer");
throw new InvalidPluginExecutionException(string.Format("Retrieved Autonumber: {0}", theAutonumber.Name));
}
}
public static DynamicEntity RetrieveDynamicEntitiesByProperty(ICrmService service, string Entity, string Column, string Value)
{
ConditionExpression con = new ConditionExpression();
con.AttributeName = Column;
con.Operator = ConditionOperator.Equal;
con.Values = new string[] { Value };
FilterExpression filter = new FilterExpression();
filter.FilterOperator = LogicalOperator.And;
filter.AddCondition(con);
QueryExpression query = new QueryExpression();
query.EntityName = Entity;
query.ColumnSet = new AllColumns();
query.Criteria = filter;
RetrieveMultipleRequest retrieve = new RetrieveMultipleRequest();
retrieve.Query = query;
retrieve.ReturnDynamicEntities = true;
RetrieveMultipleResponse retrieved = (RetrieveMultipleResponse)service.Execute(retrieve);
//I prefer Lists to BusinessEntityCollection objects
IList<DynamicEntity> Entities = new List<DynamicEntity>();
foreach (DynamicEntity de in retrieved.BusinessEntityCollection.BusinessEntities)
Entities.Add(de);
if (retrieved.BusinessEntityCollection.BusinessEntities.Count == 0)
return null;
DynamicEntity entity = (DynamicEntity)retrieved.BusinessEntityCollection.BusinessEntities[0];
return entity;
}
}
}