Take the 2-minute tour ×
SharePoint Stack Exchange is a question and answer site for SharePoint enthusiasts. It's 100% free, no registration required.

Is there a simple way to run code after solution install and before solution uninstall ? I know I can do that with feature but I don't want to use it.

share|improve this question
    
Is there any good reason for you to not want to use EventReceivers, since this is the very purpose of the feature event receivers? –  Robert Lindgren Apr 11 '13 at 14:18
add comment

2 Answers

You could potentially do it with a feature event reciever as described in this article by microsoft.

Feature event receivers are methods that execute when one of the following feature-related events occurs in SharePoint:

•A feature is installed.

•A feature is activated.

•A feature is deactivated.

•A feature is removed.

share|improve this answer
    
The question states that he / she does not want to use EventReceivers for whatever reason! –  Robert Lindgren Apr 11 '13 at 14:17
add comment

If you want to perform additional tasks when a SharePoint project is deployed or retracted, you can handle events that are raised by Visual Studio.

For example:

using System;
using Microsoft.VisualStudio.SharePoint;
using Microsoft.VisualStudio.SharePoint.Deployment;
using System.ComponentModel.Composition;

namespace Contoso.ProjectDeploymentExtension
{
    [Export(typeof(ISharePointProjectExtension))]
    internal class ExampleProjectDeploymentExtension : ISharePointProjectExtension
    {
        public void Initialize(ISharePointProjectService projectService)
        {
            projectService.DeploymentStarted += ProjectService_DeploymentStarted;
            projectService.DeploymentCompleted += ProjectService_DeploymentCompleted;
        }

        void ProjectService_DeploymentStarted(object sender, DeploymentEventArgs e)
        {
            if (e.DeploymentContext.IsDeploying)
            {
                string message = String.Format("Deployment started for the {0} project.",
                     e.Project.Name);
                e.DeploymentContext.Logger.WriteLine(message, LogCategory.Status);
            }
        }

        void ProjectService_DeploymentCompleted(object sender, DeploymentEventArgs e)
        {
            if (e.DeploymentContext.IsDeploying)
            {
                string message = String.Format("Deployment completed for the {0} project.",
                     e.Project.Name);
                e.DeploymentContext.Logger.WriteLine(message, LogCategory.Status);
            }
        }
    }
}

Reference:

http://msdn.microsoft.com/en-us/library/ee843866.aspx

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.