Ser*_*ver 5 sharepoint sharepoint-2010
我有一个包含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();
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我从Visual Studio 2010进行F5部署.当我从UI激活该功能时,我会在功能代码中进入断点,执行功能代码.当我从PowerShell激活该功能时:
Enable-SPFeature -Url http://myserver/sites/publishing/empty -Identity MyFeatureName -force -verbose
Run Code Online (Sandbox Code Playgroud)
或者使用STSADM:
stsadm -o activatefeature -name MyFeatureName -url http://myserver/sites/Publishing/Empty -force
Run Code Online (Sandbox Code Playgroud)
我看到该功能已激活(在UI中),但我没有点击我的断点,并且没有执行功能接收器代码.
有任何想法吗?
如果使用powershell或stsadm,则该功能将不会在IIS工作进程的上下文中运行.你在调试时将VS工作室附加到什么位置?
在调试stsadm任务时,我通常会添加:
System.Diagnostics.Debugger.Launch();
对于代码,当运行命令时,系统将提示您附加调试器.原油但很容易.(别忘了删除)
小智 5
- "默认情况下,运行Visual Studio SharePoint应用程序时,会在SharePoint服务器上为您自动激活其功能.但是,这会在调试功能事件接收器时导致问题,因为当Visual Studio激活某个功能时,它会运行在与调试器不同的进程中.这意味着某些调试功能(如断点)将无法正常工作.
若要禁用SharePoint中的功能的自动激活并允许正确调试功能事件接收器,请在调试之前将项目的Active Deployment Configuration属性的值设置为No Activation.然后,在Visual Studio SharePoint应用程序运行后,手动激活SharePoint中的功能.为此,请单击SharePoint中"网站操作"菜单上的"网站设置",单击"管理网站功能"链接,然后单击该功能旁边的"激活"按钮,并正常恢复调试."
来源:http://msdn.microsoft.com/en-us/library/ee231550.aspx
| 归档时间: |
|
| 查看次数: |
7381 次 |
| 最近记录: |