简体   繁体   English

SharePoint 2010:从UI执行的功能接收器代码,而不是PowerShell或stdadm

[英]SharePoint 2010: feature receiver code executed from UI, not from PowerShell or stdadm

I have a WSP containing a web scope feature with the following code: 我有一个包含Web范围功能的WSP,其代码如下:

using System;
using System.Runtime.InteropServices;
using System.Security.Permissions;
using Microsoft.SharePoint;
using Microsoft.SharePoint.Security;

namespace Macaw.DualLayout.Samples.Features.DualLayoutSampleEmpty_Web
{
    [Guid("8b558382-5566-43a4-85fa-ca86845b04b0")]
    public class DualLayoutSampleEmpty_WebEventReceiver : SPFeatureReceiver
    {
        public override void FeatureActivated(SPFeatureReceiverProperties properties)
        {
            using (SPWeb web = (SPWeb)properties.Feature.Parent)
            {
                using (SPSite site = (SPSite)web.Site)
                {
                    Uri uri = new Uri(site.Url + "/_catalogs/masterpage/DLSampleEmpty.master");
                    web.CustomMasterUrl = uri.AbsolutePath; // Master for all publishing pages
                    web.Update();
                }
            }
        }

        public override void FeatureDeactivating(SPFeatureReceiverProperties properties)
        {
            using (SPWeb web = (SPWeb)properties.Feature.Parent)
            {
                using (SPSite site = (SPSite)web.Site)
                {
                    Uri uri = new Uri(site.Url + "/_catalogs/masterpage/v4.master");
                    web.CustomMasterUrl = uri.AbsolutePath; // Master for all publishing pages
                    web.Update();
                }
            }
        }
    }
}

I do F5 deployment from Visual Studio 2010. When I activate the feature from UI I get into my breakpoint in the feature code, the feature code is executed. 我从Visual Studio 2010进行F5部署。当我从UI激活该功能时,我会在功能代码中进入断点,执行功能代码。 When I activate the feature from PowerShell: 当我从PowerShell激活该功能时:

Enable-SPFeature -Url http://myserver/sites/publishing/empty -Identity MyFeatureName -force -verbose

or with STSADM: 或者使用STSADM:

stsadm -o activatefeature -name MyFeatureName -url http://myserver/sites/Publishing/Empty -force

I see that the feature is activated (in the UI), but I don't hit my breakpoint and the feature receiver code is NOT executed. 我看到该功能已激活(在UI中),但我没有点击我的断点,并且没有执行功能接收器代码。

Any ideas? 有任何想法吗?

If you use powershell or stsadm the feature will not run in the context of the IIS worker process. 如果使用powershell或stsadm,则该功能将不会在IIS工作进程的上下文中运行。 What do you attach VS studio to when you debug? 你在调试时将VS工作室附加到什么位置?

When debugging stsadm tasks I usually add: 在调试stsadm任务时,我通常会添加:

System.Diagnostics.Debugger.Launch();

to the code and you will be prompted to attach a debugger when the command is run. 对于代码,当运行命令时,系统将提示您附加调试器。 Crude but easy. 原油但很容易。 (Don't forget to remove) (别忘了删除)

-"By default, when you run a Visual Studio SharePoint application, its features are automatically activated for you on the SharePoint server. However, this causes problems when you debug feature event receivers, because when a feature is activated by Visual Studio, it runs in a different process than the debugger. This means that some debugging functionality, such as breakpoints, will not work correctly. - “默认情况下,运行Visual Studio SharePoint应用程序时,会在SharePoint服务器上为您自动激活其功能。但是,这会在调试功能事件接收器时导致问题,因为当Visual Studio激活某个功能时,它会运行在与调试器不同的进程中。这意味着某些调试功能(如断点)将无法正常工作。

To disable the automatic activation of the feature in SharePoint and allow proper debugging of Feature Event Receivers, set the value of the project's Active Deployment Configuration property to No Activation before debugging. 若要禁用SharePoint中的功能的自动激活并允许正确调试功能事件接收器,请在调试之前将项目的Active Deployment Configuration属性的值设置为No Activation。 Then, after your Visual Studio SharePoint application is running, manually activate the feature in SharePoint. 然后,在Visual Studio SharePoint应用程序运行后,手动激活SharePoint中的功能。 To do this, click Site Settings on the Site Actions menu in SharePoint, click the Manage Site Features link, and then click the Activate button next to the feature and resume debugging as normal." 为此,请单击SharePoint中“网站操作”菜单上的“网站设置”,单击“管理网站功能”链接,然后单击该功能旁边的“激活”按钮,并正常恢复调试。“

Source: http://msdn.microsoft.com/en-us/library/ee231550.aspx 来源: http//msdn.microsoft.com/en-us/library/ee231550.aspx

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM