I have a WSP containing a web scope feature with the following code:
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. When I activate the feature from PowerShell:
Enable-SPFeature -Url http://myserver/sites/publishing/empty -Identity MyFeatureName -force -verbose
or with 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.
Any ideas?
If you use powershell or stsadm the feature will not run in the context of the IIS worker process. What do you attach VS studio to when you debug?
When debugging stsadm tasks I usually add:
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)
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With