Muokkaa

Jaa


Handle specialized deployment

A deployment is an optional operation for projects. A Web project, for example, supports a deployment to let a project update a Web server. Likewise, a Smart Device project supports a deployment to copy a built application to the target device. Project subtypes can supply specialized deployment behavior by implementing the IVsDeployableProjectCfg interface. This interface defines a complete set of the deployment operations:

To handle a specialized deployment by a subtype project

  • Implement the AdviseDeployStatusCallback method to register the environment to receive notifications of deployment status events.

    private Microsoft.VisualStudio.Shell.EventSinkCollection adviseSink = new Microsoft.VisualStudio.Shell.EventSinkCollection();
    public int AdviseDeployStatusCallback(IVsDeployStatusCallback pIVsDeployStatusCallback,
                                          out uint pdwCookie)
    {
        if (pIVsDeployStatusCallback == null)
            throw new ArgumentNullException("pIVsDeployStatusCallback");
    
        pdwCookie = adviseSink.Add(pIVsDeployStatusCallback);
        return VSConstants.S_OK;
    }
    
    
  • Implement the UnadviseDeployStatusCallback method to cancel the environment's registration to receive notifications of deployment status events.

    public int UnadviseDeployStatusCallback(uint dwCookie)
    {
        adviseSink.RemoveAt(dwCookie);
        return VSConstants.S_OK;
    }
    
    
  • Implement the Commit method to perform the commit operation specific to your application. This method is used mainly for database deployment.

    public int Commit(uint dwReserved)
    {
         //Implement commit operation here.
         return VSConstants.S_OK;
    }
    
    
  • Implement the Rollback method to perform a rollback operation. When this method is called, the deployment project must do whatever is appropriate to roll back changes and restore the state of the project. This method is used mainly for database deployment.

    public int Rollback(uint dwReserved)
    {
        //Implement Rollback operation here.
        return VSConstants.S_OK;
    }
    
    
  • Implement the QueryStartDeploy method to determine whether or not a project is able to start a deployment operation.

    public int QueryStartDeploy(uint dwOptions, int[] pfSupported, int[] pfReady)
    {
        if (pfSupported != null && pfSupported.Length >0)
            pfSupported[0] = 1;
        if (pfReady != null && pfReady.Length >0)
        {
            pfReady[0] = 0;
            if (deploymentThread != null && !deploymentThread.IsAlive)
                pfReady[0] = 1;
        }
        return VSConstants.S_OK;
    }
    
    
  • Implement the QueryStatusDeploy method to determine whether or not a deployment operation has completed successfully.

    public int QueryStatusDeploy(out int pfDeployDone)
    {
        pfDeployDone = 1;
        if (deploymentThread != null && deploymentThread.IsAlive)
            pfDeployDone = 0;
        return VSConstants.S_OK;
    }
    
    
  • Implement the StartDeploy method to begin a deployment operation in a separate thread. Place the code specific to your application's deployment inside the Deploy method.

    public int StartDeploy(IVsOutputWindowPane pIVsOutputWindowPane, uint dwOptions)
    {
        if (pIVsOutputWindowPane == null)
            throw new ArgumentNullException("pIVsOutputWindowPane");
    
        if (deploymentThread != null && deploymentThread.IsAlive)
            throw new NotSupportedException("Cannot start deployment operation when it is already started; Call QueryStartDeploy first");
    
        outputWindow = pIVsOutputWindowPane;
    
        // Notify that deployment is about to begin and see if any user wants to cancel.
        if (!NotifyStart())
            return VSConstants.E_ABORT;
    
        operationCanceled = false;
    
        // Create and start our thread
        deploymentThread = new Thread(new ThreadStart(this.Deploy));
        deploymentThread.Name = "Deployment Thread";
        deploymentThread.Start();
    
        return VSConstants.S_OK;
    }
    
    
  • Implement the StopDeploy method to stop a deployment operation. This method is called when a user presses the Cancel button during the deployment process.

    public int StopDeploy(int fSync)
    {
        if (deploymentThread != null && deploymentThread.IsAlive)
            return VSConstants.S_OK;
    
        outputWindow.OutputStringThreadSafe("Canceling deployment");
        operationCanceled = true;
        if (fSync != 0)
        {
            // Synchronous request, wait for the thread to terminate.
            if (!deploymentThread.Join(10000))
            {
                Debug.Fail("Deployment thread did not terminate before the timeout, Aborting thread");
                deploymentThread.Abort();
            }
        }
    
        return VSConstants.S_OK;
    }
    
    

Note

All code examples provided in this topic are parts of a larger example in VSSDK samples.