如何更新 SharePoint 中列表的 SPItemEventReceiver 程序集版本? [英] How to update SPItemEventReceiver assembly version for a list in SharePoint?

查看:35
本文介绍了如何更新 SharePoint 中列表的 SPItemEventReceiver 程序集版本?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我们有一个 SPItemEventReceiver 编译成它自己的程序集.

We have an SPItemEventReceiver compiled into its own assembly.

我们正在使用 STSDev 将此 EventReceiver 作为一项功能打包一个 SharePoint 解决方案.我没有将 SPItemEventReceiver 分配给 elements.xml 中的特定 ListTemplateId,而是链接 feature.xml 中的 ReceiverAssembly 并以编程方式将 SPItemEventReceiver 分配给多个 SPList 项目.

We are using STSDev to package up a SharePoint solution with this EventReceiver as a feature. I am not assigning the SPItemEventReceiver to a specific ListTemplateId within the elements.xml, but am instead linking a ReceiverAssembly in the feature.xml and programmaticaly assigning the SPItemEventReceiver to multiple SPList items.

    public override void FeatureActivated(SPFeatureReceiverProperties properties)
    {
        foreach (SPWeb web in site.AllWebs)
        {
            SPListCollection webListCollection = web.Lists;

            foreach (SPList myList in webListCollection)
            {
                if (myList.Title == "Lab Reports")
                {
                    SPEventReceiverDefinitionCollection receivers = myList.EventReceivers;
                    SPEventReceiverDefinition receiver = receivers.Add();
                    receiver.Name = "PostUpdateLabReport";
                    receiver.Assembly = "LabReportEventHandlers, Version=1.0.0.0, Culture=neutral, PublicKeyToken=1111111111111";
                    receiver.Class = "LabReportEventHandlers.LabReportsHandler";
                    receiver.Type = SPEventReceiverType.ItemUpdated;
                    receiver.Update();
                    break;
                }
            }

            web.Dispose();
        }
    }

我正在使用 FeatureDeactivation 执行上述代码的相反操作,从列表中删除 EventReceiver.

I am using FeatureDeactivating to do the reverse of the above code, removing the EventReceiver from the lists.

问题:

如果将来发生 LabReportEventHandlers 更新和版本更改的事件,我应该如何处理?

How should I handle the future event where LabReportEventHandlers is updated and the version changes?

这些是我能想到的选项:

These are the options I can think of:

  1. 停用/重新激活功能 -- 我会将更新后的 dll 包装回 SharePoint 解决方案文件,更改上面的代码以反映新版本,并使用 stsadmin 升级解决方案.然后我会停用/重新激活该功能.

  1. Deactivate / Reactivate feature -- I would wrap the updated dll back into the SharePoint solution file, change my code above to reflect the new version, and use stsadmin to upgrade the solution. I would then deactivate/ reactivate the feature.

将程序集重定向添加到 web.config.

Add Assembly redirection to the web.config.

不要修改 LabReportEventHandlers 版本号.

Don't bump the LabReportEventHandlers version number.

更改解决方案版本是否对我有帮助?

Is there something in changing the solution version that will help me?

我认为这 3 个选项有问题:

I think there are problems with the 3 options:

  1. 停用该功能后,有人可以在我重新激活之前更新项目.

  1. After deactivation of the feature, someone could update an item before I can reactiave.

我不想手动编辑 web.config,所以我会改用 sharepoint API.我会在哪里运行该代码?

I would not want to edit the web.config by hand, so I would use the sharepoint API instead. Where would I run that code?

这完全是错误的,但很简单.

This is just plain wrong, but easy.

推荐答案

也许您可以将易于更改的逻辑封装到一个单独的程序集中,由您的事件处理程序引用和使用.这样,事件处理程序本身就不会更改而不必更改,您只需将更新的逻辑"程序集适当地部署到 GAC 或 bin 目录即可.

Maybe you can encapsulate the logic that is prone to change into a separate assembly, that is referenced and used by your event handler. This way, the event handler itself won't change have to change, you would only deploy the updated "logic" assembly to the GAC or bin directory(ies) appropriately.

HTH,jt

这篇关于如何更新 SharePoint 中列表的 SPItemEventReceiver 程序集版本?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆