다음을 통해 공유


방법: 핸들 전문화 배포

배포 프로젝트에 대해 선택적인 작업입니다. 예를 들어, 웹 프로젝트를 배포 하는 웹 서버를 업데이트 하는 프로젝트를 지원 합니다. 마찬가지로, 한 스마트 장치 프로젝트에 빌드된 응용 프로그램을 대상 장치에 복사 하 여 배포를 지원 합니다. 프로젝트 하위 유형을 제공할 수 있습니다 배포 특수 한 동작을 구현 하 여 해당 IVsDeployableProjectCfg 인터페이스입니다. 이 인터페이스는 배포 작업의 전체 집합을 정의합니다.

실제 배포 작업을 하는 별도 스레드에서 수행 Visual Studio 사용자 상호 작용에 더 빠르게 응답 합니다. 가 제공 하는 방법을 IVsDeployableProjectCfg 를 비동기적으로 호출 됩니다 Visual Studio 와 필요에 따라 언제 든 지 배포 작업의 상태를 쿼리할 수 또는 작업을 중지 하려면 환경 수 있도록 백그라운드에서 작동 합니다. IVsDeployableProjectCfg 배포 명령을 선택할 때 인터페이스 배포 작업 환경에 의해 호출 되지.

배포 작업을 시작 또는 종료 하는 환경에 알리려면 프로젝트 하위 형식을 호출 해야는 OnStartDeployOnEndDeploy 방법.

배포 처리 전문

하위 프로젝트에 의해 특별 한 배포를 처리 하

  • 구현에서 AdviseDeployStatusCallback 환경 배포 상태 이벤트의 알림을 받도록 등록할 수 있는 메서드.

    Private adviseSink As Microsoft.VisualStudio.Shell.EventSinkCollection = New Microsoft.VisualStudio.Shell.EventSinkCollection()
    Public Function AdviseDeployStatusCallback(ByVal pIVsDeployStatusCallback As IVsDeployStatusCallback, _
                                               ByRef pdwCookie As UInteger) As Integer
    
        If pIVsDeployStatusCallback Is Nothing Then
            Throw New ArgumentNullException("pIVsDeployStatusCallback")
        End If
    
        pdwCookie = adviseSink.Add(pIVsDeployStatusCallback)
        Return VSConstants.S_OK
    
    End Function
    
    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 Function UnadviseDeployStatusCallback(ByVal dwCookie As UInteger) As Integer
        adviseSink.RemoveAt(dwCookie)
        Return VSConstants.S_OK
    End Function
    
    public int UnadviseDeployStatusCallback(uint dwCookie)
    {
        adviseSink.RemoveAt(dwCookie);
        return VSConstants.S_OK;
    }
    
  • 구현에서 Commit 응용 프로그램에 커밋 작업을 수행 하는 방법입니다. 이 방법은 데이터베이스 배포에 주로 사용 됩니다.

    Public Function Commit(ByVal dwReserved As UInteger) As Integer
        'Implement commit operation here.
        Return VSConstants.S_OK
    End Function
    
    public int Commit(uint dwReserved)
    {
         //Implement commit operation here.
         return VSConstants.S_OK;
    }
    
  • 구현에서 Rollback 롤백 작업을 수행 하는 방법입니다. 이 메서드를 호출 하면 배포 프로젝트를 모든 변경 내용을 롤백하고 적합 하지 하 고 프로젝트의 상태를 복원 해야 합니다. 이 방법은 데이터베이스 배포에 주로 사용 됩니다.

    Public Function Commit(ByVal dwReserved As UInteger) As Integer
        'Implement commit operation here.
        Return VSConstants.S_OK
    End Function
    
    public int Rollback(uint dwReserved)
    {
        //Implement Rollback operation here.
        return VSConstants.S_OK;
    }
    
  • 구현에서 QueryStartDeploy 메서드가 프로젝트 배포 작업을 시작할 수 있는지 여부를 결정 합니다.

    Public Function QueryStartDeploy(ByVal dwOptions As UInteger, ByVal pfSupported As Integer(), ByVal pfReady As Integer()) As Integer
        If Not pfSupported Is Nothing AndAlso pfSupported.Length > 0 Then
            pfSupported(0) = 1
        End If
        If Not pfReady Is Nothing AndAlso pfReady.Length > 0 Then
            pfReady(0) = 0
            If Not deploymentThread Is Nothing AndAlso (Not deploymentThread.IsAlive) Then
                pfReady(0) = 1
            End If
        End If
        Return VSConstants.S_OK
    End Function
    
    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 Function QueryStatusDeploy(ByRef pfDeployDone As Integer) As Integer
        pfDeployDone = 1
        If Not deploymentThread Is Nothing AndAlso deploymentThread.IsAlive Then
            pfDeployDone = 0
        End If
        Return VSConstants.S_OK
    End Function
    
    public int QueryStatusDeploy(out int pfDeployDone)
    {
        pfDeployDone = 1;
        if (deploymentThread != null && deploymentThread.IsAlive)
            pfDeployDone = 0;
        return VSConstants.S_OK;
    }
    
  • 구현에서 StartDeploy 메서드는 배포 작업이 별도 스레드에서 시작 합니다. 특정 응용 프로그램의 배포 내에서 코드를 넣을 Deploy 메서드가 있습니다.

    Public Function StartDeploy(ByVal pIVsOutputWindowPane As IVsOutputWindowPane, ByVal dwOptions As UInteger) As Integer
        If pIVsOutputWindowPane Is Nothing Then
            Throw New ArgumentNullException("pIVsOutputWindowPane")
        End If
    
        If Not deploymentThread Is Nothing AndAlso deploymentThread.IsAlive Then
            Throw New NotSupportedException("Cannot start deployment operation when it is already started; Call QueryStartDeploy first")
        End If
    
        outputWindow = pIVsOutputWindowPane
    
        ' Notify that deployment is about to begin and see if any user wants to cancel.
        If (Not NotifyStart()) Then
            Return VSConstants.E_ABORT
        End If
    
        operationCanceled = False
    
        ' Create and start our thread
        deploymentThread = New Thread(AddressOf Me.Deploy)
        deploymentThread.Name = "Deployment Thread"
        deploymentThread.Start()
    
        Return VSConstants.S_OK
    End Function
    
    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 Function StopDeploy(ByVal fSync As Integer) As Integer
        If Not deploymentThread Is Nothing AndAlso deploymentThread.IsAlive Then
            Return VSConstants.S_OK
        End If
    
        outputWindow.OutputStringThreadSafe("Canceling deployment")
        operationCanceled = True
        If fSync <> 0 Then
            ' Synchronous request, wait for the thread to terminate.
            If (Not deploymentThread.Join(10000)) Then
                Debug.Fail("Deployment thread did not terminate before the timeout, Aborting thread")
                deploymentThread.Abort()
            End If
        End If
    
        Return VSConstants.S_OK
    End Function
    
    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;
    }
    

참고

이 항목에서 제공 하는 모든 코드 예제는 보다 큰 예제의 일부입니다 Visual Studio 확장성 샘플.

참고 항목

기타 리소스

프로젝트 하위