다음을 통해 공유


특수 배포 처리

배포는 프로젝트에 대한 선택적 작업입니다. 예를 들어 웹 프로젝트는 프로젝트가 웹 서버를 업데이트할 수 있도록 배포를 지원합니다. 마찬가지로 스마트 디바이스 프로젝트는 빌드된 애플리케이션을 대상 디바이스에 복사하는 배포를 지원합니다. 프로젝트 하위 형식은 IVsDeployableProjectCfg 인터페이스를 구현하여 특수한 배포 동작을 제공할 수 있습니다. 이 인터페이스는 배포 작업의 전체 집합을 정의합니다.

하위 형식 프로젝트에서 특수화된 배포를 처리하려면

  • AdviseDeployStatusCallback 배포 상태 이벤트의 알림을 받도록 환경을 등록하는 메서드를 구현합니다.

    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;
    }
    
    
  • UnadviseDeployStatusCallback 배포 상태 이벤트의 알림을 수신하도록 환경 등록을 취소하는 메서드를 구현합니다.

    public int UnadviseDeployStatusCallback(uint dwCookie)
    {
        adviseSink.RemoveAt(dwCookie);
        return VSConstants.S_OK;
    }
    
    
  • 애플리케이션에 특정한 커밋 작업을 수행할 Commit 메서드를 구현합니다. 이 메서드는 주로 데이터베이스 배포에 사용됩니다.

    public int Commit(uint dwReserved)
    {
         //Implement commit operation here.
         return VSConstants.S_OK;
    }
    
    
  • Rollback 롤백 작업을 수행하는 메서드를 구현합니다. 이 메서드가 호출되면 배포 프로젝트는 변경 내용을 롤백하고 프로젝트의 상태를 복원하기 위해 적절한 모든 작업을 수행해야 합니다. 이 메서드는 주로 데이터베이스 배포에 사용됩니다.

    public int Rollback(uint dwReserved)
    {
        //Implement Rollback operation here.
        return VSConstants.S_OK;
    }
    
    
  • QueryStartDeploy 프로젝트가 배포 작업을 시작할 수 있는지 여부를 결정하는 메서드를 구현합니다.

    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;
    }
    
    
  • QueryStatusDeploy 배포 작업이 성공적으로 완료되었는지 여부를 확인하는 메서드를 구현합니다.

    public int QueryStatusDeploy(out int pfDeployDone)
    {
        pfDeployDone = 1;
        if (deploymentThread != null && deploymentThread.IsAlive)
            pfDeployDone = 0;
        return VSConstants.S_OK;
    }
    
    
  • StartDeploy 별도의 스레드에서 배포 작업을 시작하는 메서드를 구현합니다. 메서드 내에 애플리케이션의 배포와 관련된 코드를 배치합니다 Deploy .

    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;
    }
    
    
  • StopDeploy 배포 작업을 중지하는 메서드를 구현합니다. 이 메서드는 사용자가 배포 프로세스 중에 취소 단추를 누를 때 호출됩니다.

    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;
    }
    
    

비고

이 항목에 제공된 모든 코드 예제는 VSSDK 샘플에서 더 큰 예제의 일부입니다.