다음을 통해 공유


연습: SharePoint 프로젝트용 사용자 지정 배포 단계 만들기

SharePoint 프로젝트를 배포하면 Visual Studio 2010에서 일련의 배포 단계를 특정 순서대로 실행합니다. Visual Studio에는 많은 기본 제공 배포 단계가 포함되어 있지만 사용자가 직접 만들 수도 있습니다.

이 연습에서는 SharePoint 서버의 솔루션을 업그레이드하는 사용자 지정 배포 단계를 만듭니다. Visual Studio에는 솔루션 제거 또는 추가와 같은 여러 작업에 대한 기본 제공 배포 단계가 포함되어 있지만 솔루션 업그레이드에 대한 배포 단계는 없습니다. 기본적으로 SharePoint 솔루션을 배포하면 Visual Studio에서 먼저 솔루션을 제거한 다음(이미 배포된 경우) 전체 솔루션을 다시 배포합니다. 기본 배포 단계에 대한 자세한 내용은 SharePoint 솔루션 패키지 배포를 참조하십시오.

이 연습에서는 다음 작업을 수행합니다.

  • 다음 두 가지 주요 작업을 수행하는 Visual Studio 확장 만들기

    • SharePoint 솔루션을 업그레이드하는 사용자 지정 배포 단계를 정의합니다.

    • 새 배포 구성을 정의하는 프로젝트 확장을 만듭니다. 배포 구성은 지정된 프로젝트에 대해 실행되는 일련의 배포 단계입니다. 새 배포 구성에는 사용자 지정 배포 단계와 여러 개의 기본 제공 배포 단계가 포함됩니다.

  • 확장 어셈블리를 통해 호출되는 두 개의 사용자 지정 SharePoint 명령 만들기. SharePoint 명령은 확장 어셈블리가 SharePoint 서버 개체 모델에서 API를 사용하기 위해 호출할 수 있는 메서드입니다. 자세한 내용은 SharePoint 개체 모델 호출을 참조하십시오.

  • 두 어셈블리를 모두 배포하기 위한 VSIX(Visual Studio Extension) 패키지 빌드

  • 새 배포 단계 테스트

사전 요구 사항

이 연습을 완료하려면 개발 컴퓨터에 다음 구성 요소가 필요합니다.

다음 개념을 알고 있으면 연습을 완료하는 데 도움이 되지만 반드시 필요하지는 않습니다.

프로젝트 만들기

이 연습을 완료하려면 세 프로젝트를 만들어야 합니다.

  • VSIX 패키지를 만들어 확장을 배포하기 위한 VSIX 프로젝트

  • 확장을 구현하는 클래스 라이브러리 프로젝트. 이 프로젝트는 .NET Framework 4를 대상으로 해야 합니다.

  • 사용자 지정 SharePoint 명령을 정의하는 클래스 라이브러리 프로젝트. 이 프로젝트는 .NET Framework 3.5를 대상으로 해야 합니다.

먼저 프로젝트를 만들어 연습을 시작합니다.

VSIX 프로젝트를 만들려면

  1. Visual Studio를 시작합니다.

  2. 파일 메뉴에서 새로 만들기를 가리킨 다음 프로젝트를 클릭합니다.

  3. 새 프로젝트 대화 상자에서 Visual C# 또는 Visual Basic 노드를 확장한 다음 확장성을 클릭합니다.

    참고

    확장성 노드는 Visual Studio 2010 SDK를 설치한 경우에만 사용할 수 있습니다. 자세한 내용은 위의 필수 구성 요소 단원을 참조하십시오.

  4. 대화 상자 맨 위의 콤보 상자에서 .NET Framework 4를 선택합니다.

  5. VSIX 프로젝트 템플릿을 클릭합니다.

  6. 이름 상자에 UpgradeDeploymentStep을 입력합니다.

  7. 확인을 클릭합니다.

    Visual Studio에서 솔루션 탐색기UpgradeDeploymentStep 프로젝트를 추가합니다.

확장 프로젝트를 만들려면

  1. 솔루션 탐색기에서 솔루션 노드를 마우스 오른쪽 단추로 클릭한 다음 추가, 새 프로젝트를 차례로 클릭합니다.

    참고

    Visual Basic 프로젝트에서는 옵션 대화 상자, 프로젝트 및 솔루션, 일반에서 솔루션 항상 표시 확인란을 선택한 경우에만 솔루션 탐색기에 솔루션 노드가 표시됩니다.

  2. 새 프로젝트 대화 상자에서 Visual C# 또는 Visual Basic 노드를 확장하고 Windows를 클릭합니다.

  3. 대화 상자 맨 위의 콤보 상자에서 .NET Framework 4를 선택합니다.

  4. 클래스 라이브러리 프로젝트 템플릿을 선택합니다.

  5. 이름 상자에 DeploymentStepExtension을 입력합니다.

  6. 확인을 클릭합니다.

    Visual Studio에서 솔루션에 DeploymentStepExtension 프로젝트를 추가하고 기본 Class1 코드 파일을 엽니다.

  7. 프로젝트에서 Class1 코드 파일을 삭제합니다.

SharePoint 명령 프로젝트를 만들려면

  1. 솔루션 탐색기에서 솔루션 노드를 마우스 오른쪽 단추로 클릭하고 추가를 가리킨 다음 새 프로젝트를 클릭합니다.

    참고

    Visual Basic 프로젝트에서는 옵션 대화 상자, 프로젝트 및 솔루션, 일반에서 솔루션 항상 표시 확인란을 선택한 경우에만 솔루션 탐색기에 솔루션 노드가 표시됩니다.

  2. 새 프로젝트 추가 대화 상자에서 Visual C# 또는 Visual Basic을 확장하고 Windows를 클릭합니다.

  3. 클래스 라이브러리 프로젝트 템플릿을 클릭합니다.

  4. 대화 상자 맨 위의 콤보 상자에서 .NET Framework 3.5를 선택합니다.

  5. 이름 상자에 SharePointCommands를 입력합니다.

  6. 확인을 클릭합니다.

    SharePointCommands 프로젝트가 솔루션에 추가되고 기본 Class1 코드 파일이 열립니다.

  7. 프로젝트에서 Class1 코드 파일을 삭제합니다.

프로젝트 구성

사용자 지정 배포 단계를 만드는 코드를 작성하기 전에 코드 파일과 어셈블리 참조를 추가하고 프로젝트를 구성해야 합니다.

DeploymentStepExtension 프로젝트를 구성하려면

  1. DeploymentStepExtension 프로젝트에서 다음과 같은 이름의 두 코드 파일을 추가합니다.

    • UpgradeStep

    • DeploymentConfigurationExtension

  2. 프로젝트 메뉴에서 참조 추가를 클릭합니다.

  3. .NET 탭에서 Ctrl 키를 누르고 다음 어셈블리를 선택한 다음 확인을 클릭합니다.

    • Microsoft.VisualStudio.SharePoint

    • System.ComponentModel.Composition

SharePointCommands 프로젝트를 구성하려면

  1. SharePointCommands 프로젝트에 Commands라는 코드 파일을 추가합니다.

  2. 솔루션 탐색기에서 SharePointCommands 프로젝트 노드를 클릭합니다.

  3. 프로젝트 메뉴에서 참조 추가를 클릭합니다.

  4. .NET 탭에서 Ctrl 키를 누르고 다음 어셈블리를 선택한 다음 확인을 클릭합니다.

    • Microsoft.SharePoint

    • Microsoft.VisualStudio.SharePoint.Commands

사용자 지정 배포 단계 정의

업그레이드 배포 단계를 정의하는 클래스를 만듭니다. 배포 단계를 정의하기 위해 클래스에서는 IDeploymentStep 인터페이스를 구현합니다. 사용자 지정 배포 단계를 정의하려는 경우 이 인터페이스를 구현합니다.

사용자 지정 배포 단계를 정의하려면

  1. DeploymentStepExtension 프로젝트에서 UpgradeStep 코드 파일을 두 번 클릭합니다.

  2. 이 파일에 다음 코드를 붙여 넣습니다.

    참고

    이 코드를 추가하면 프로젝트에서 컴파일 오류가 발생합니다. 이러한 오류는 이후 단계에서 코드를 추가하면 사라집니다.

    Imports System
    Imports Microsoft.VisualStudio.SharePoint
    Imports Microsoft.VisualStudio.SharePoint.Deployment
    Imports System.ComponentModel.Composition
    
    Namespace Contoso.DeploymentSteps.Upgrade
    
        ' Export attribute: Enables Visual Studio to discover and load this deployment step.
        ' DeploymentStep attribute: Specifies the ID for this new deployment step.
        ' UpgradeStep class: Defines a new deployment step that can be used to upgrade a solution 
        '     on a SharePoint site.
        <Export(GetType(IDeploymentStep))> _
        <DeploymentStep("Contoso.DeploymentSteps.UpgradeSolution")> _
        Friend Class UpgradeStep
            Implements IDeploymentStep
    
            Private solutionName As String
            Private solutionFullPath As String
    
            Private Sub Initialize(ByVal stepInfo As IDeploymentStepInfo) _
                Implements IDeploymentStep.Initialize
                stepInfo.Name = "Upgrade solution"
                stepInfo.StatusBarMessage = "Upgrading solution..."
                stepInfo.Description = "Upgrades the solution on the local machine."
            End Sub
    
            ' Specifies whether the solution can be upgraded.
            Private Function CanExecute(ByVal context As IDeploymentContext) As Boolean _
                Implements IDeploymentStep.CanExecute
    
                ' SharePoint returns all the installed solutions names in lower case.
                solutionName = (context.Project.Package.Model.Name & ".wsp").ToLower()
                solutionFullPath = context.Project.Package.OutputPath
                Dim solutionExists As Boolean = _
                    context.Project.SharePointConnection.ExecuteCommand(Of String, Boolean)(
                    "Contoso.Commands.IsSolutionDeployed", solutionName)
    
                ' Throw exceptions in error cases because deployment cannot proceed.
                If context.Project.IsSandboxedSolution = True Then
                    Dim sandboxMessage As String = "Cannot upgrade the solution. Upgrade deployment " & _
                        "configuration does not support Sandboxed solutions."
                    context.Logger.WriteLine(sandboxMessage, LogCategory.Error)
                    Throw New InvalidOperationException()
                ElseIf solutionExists = False Then
                    Dim notDeployedMessage As String = String.Format("Cannot upgrade the solution. The IsSolutionDeployed " & _
                        "command cannot find the following solution on the SharePoint site: {0}.", solutionName)
                    context.Logger.WriteLine(notDeployedMessage, LogCategory.Error)
                    Throw New InvalidOperationException(notDeployedMessage)
                End If
    
                ' Execute step and continue with deployment.
                Return True
            End Function
    
            Private Sub Execute(ByVal context As IDeploymentContext) _
                Implements IDeploymentStep.Execute
                context.Logger.WriteLine("Upgrading solution: " & solutionName, LogCategory.Status)
                context.Project.SharePointConnection.ExecuteCommand("Contoso.Commands.UpgradeSolution", _
                    solutionFullPath)
            End Sub
    
        End Class
    End Namespace
    
    using System;
    using Microsoft.VisualStudio.SharePoint;
    using Microsoft.VisualStudio.SharePoint.Deployment;
    using System.ComponentModel.Composition;
    
    namespace Contoso.DeploymentSteps.Upgrade
    {
        // Enables Visual Studio to discover and load this deployment step.
        [Export(typeof(IDeploymentStep))]
    
        // Specifies the ID for this new deployment step.
        [DeploymentStep("Contoso.DeploymentSteps.UpgradeSolution")]
    
        // Defines a new deployment step that can be used to upgrade a solution on a SharePoint site.
        internal class UpgradeStep : IDeploymentStep
        {
            private string solutionName;
            private string solutionFullPath;
    
            // Implements IDeploymentStep.Initialize.
            public void Initialize(IDeploymentStepInfo stepInfo)
            {
                stepInfo.Name = "Upgrade solution";
                stepInfo.StatusBarMessage = "Upgrading solution...";
                stepInfo.Description = "Upgrades the solution on the local machine.";
            }
    
            // Implements IDeploymentStep.CanExecute. Specifies whether the solution can be upgraded.
            public bool CanExecute(IDeploymentContext context)
            {
                // SharePoint returns all the installed solutions names in lower case.
                solutionName = (context.Project.Package.Model.Name + ".wsp").ToLower();
                solutionFullPath = context.Project.Package.OutputPath;
                bool solutionExists = context.Project.SharePointConnection.ExecuteCommand<string, bool>(
                    "Contoso.Commands.IsSolutionDeployed", solutionName);
    
                // Throw exceptions in error cases because deployment cannot proceed.
                if (context.Project.IsSandboxedSolution)
                {
                    string sandboxMessage = "Cannot upgrade the solution. The upgrade deployment configuration " +
                        "does not support Sandboxed solutions.";
                    context.Logger.WriteLine(sandboxMessage, LogCategory.Error);
                    throw new InvalidOperationException(sandboxMessage);
                }
                else if (!solutionExists)
                {
                    string notDeployedMessage = string.Format("Cannot upgrade the solution. The IsSolutionDeployed " +
                        "command cannot find the following solution: {0}.", solutionName);
                    context.Logger.WriteLine(notDeployedMessage, LogCategory.Error);
                    throw new InvalidOperationException(notDeployedMessage);
                }
    
                // Execute step and continue with deployment.
                return true;
            }
    
            // Implements IDeploymentStep.Execute.
            public void Execute(IDeploymentContext context)
            {
                context.Logger.WriteLine("Upgrading solution: " + solutionName, LogCategory.Status);
                context.Project.SharePointConnection.ExecuteCommand("Contoso.Commands.UpgradeSolution",
                    solutionFullPath);
            }
        }
    }
    

사용자 지정 배포 단계가 포함된 배포 구성 만들기

새 배포 구성에 대한 프로젝트 확장을 만듭니다. 새 배포 구성에는 여러 개의 기본 제공 배포 단계와 새로운 업그레이드 배포 단계가 포함됩니다. SharePoint 개발자는 이 배포 구성을 통해 SharePoint 프로젝트에서 쉽게 업그레이드 배포 단계를 사용할 수 있습니다.

배포 구성을 만들기 위해 클래스에서 ISharePointProjectExtension 인터페이스를 구현합니다. SharePoint 프로젝트 확장을 만들려는 경우 이 인터페이스를 구현합니다.

배포 구성을 만들려면

  1. DeploymentStepExtension 프로젝트에서 DeploymentConfigurationExtension 코드 파일을 두 번 클릭합니다.

  2. 이 파일에 다음 코드를 붙여 넣습니다.

    Imports Microsoft.VisualStudio.SharePoint
    Imports Microsoft.VisualStudio.SharePoint.Deployment
    Imports System.ComponentModel.Composition
    
    Namespace Contoso.DeploymentSteps.Upgrade
    
        ' Export attribute: Enables Visual Studio to discover and load this project-level extension.
        ' DeploymentConfigurationExtension class: Defines a project-level extension. The extension creates 
        '     a new deployment configuration that includes the upgrade deployment step.
        <Export(GetType(ISharePointProjectExtension))> _
        Friend Class DeploymentConfigurationExtension
            Implements ISharePointProjectExtension
    
            Private Sub Initialize(ByVal projectService As ISharePointProjectService) _
                Implements ISharePointProjectExtension.Initialize
                AddHandler projectService.ProjectInitialized, AddressOf ProjectInitialized
            End Sub
    
            ' Creates the new deployment configuration.
            Private Sub ProjectInitialized(ByVal Sender As Object, ByVal e As SharePointProjectEventArgs)
                Dim deploymentSteps As String() = New String() _
                {
                    DeploymentStepIds.PreDeploymentCommand, _
                    DeploymentStepIds.RecycleApplicationPool, _
                    "Contoso.DeploymentSteps.UpgradeSolution", _
                    DeploymentStepIds.PostDeploymentCommand _
                }
                Dim retractionSteps As String() = New String() _
                {
                    DeploymentStepIds.RecycleApplicationPool, _
                    DeploymentStepIds.RetractSolution
                }
                Dim configuration As IDeploymentConfiguration = e.Project.DeploymentConfigurations.Add( _
                    "Upgrade", deploymentSteps, retractionSteps)
                configuration.Description = "This is the upgrade deployment configuration"
            End Sub
    
        End Class
    End Namespace
    
    using Microsoft.VisualStudio.SharePoint;
    using Microsoft.VisualStudio.SharePoint.Deployment;
    using System.ComponentModel.Composition;
    
    namespace Contoso.DeploymentSteps.Upgrade
    {
        // Enables Visual Studio to discover and load this project-level extension.
        [Export(typeof(ISharePointProjectExtension))]
    
        // Defines a project-level extension. The extension creates a new deployment configuration that includes the
        // upgrade deployment step.
        internal class DeploymentConfigurationExtension : ISharePointProjectExtension
        {
            // Implements ISharePointProjectExtension.Initialize.
            public void Initialize(ISharePointProjectService projectService)
            {
                projectService.ProjectInitialized += ProjectInitialized;
            }
    
            // Creates the new deployment configuration.
            private void ProjectInitialized(object sender, SharePointProjectEventArgs e)
            {
                string[] deploymentSteps = new string[] 
                {
                    DeploymentStepIds.PreDeploymentCommand,
                    DeploymentStepIds.RecycleApplicationPool,
                    "Contoso.DeploymentSteps.UpgradeSolution",
                    DeploymentStepIds.PostDeploymentCommand 
                };
    
                string[] retractionSteps = new string[] 
                {
                    DeploymentStepIds.RecycleApplicationPool,
                    DeploymentStepIds.RetractSolution                
                };
    
                IDeploymentConfiguration configuration = e.Project.DeploymentConfigurations.Add(
                    "Upgrade", deploymentSteps, retractionSteps);
                configuration.Description = "This is the upgrade deployment configuration";
            }
        }
    }
    

사용자 지정 SharePoint 명령 만들기

SharePoint 서버 개체 모델을 호출하는 두 개의 사용자 지정 명령을 만듭니다. 한 명령은 솔루션이 이미 배포되었는지 여부를 확인하고, 다른 명령은 솔루션을 업그레이드합니다.

SharePoint 명령을 정의하려면

  1. SharePointCommands 프로젝트에서 Commands 코드 파일을 두 번 클릭합니다.

  2. 이 파일에 다음 코드를 붙여 넣습니다.

    Imports System
    Imports System.IO
    Imports Microsoft.SharePoint
    Imports Microsoft.SharePoint.Administration
    Imports Microsoft.VisualStudio.SharePoint.Commands
    
    Namespace Contoso.DeploymentSteps.Upgrade
    
        Friend Class Commands
    
            ' Determines whether the specified solution has been deployed to the local SharePoint server.
            <SharePointCommand("Contoso.Commands.IsSolutionDeployed")> _
            Private Function IsSolutionDeployed(ByVal context As ISharePointCommandContext, ByVal solutionName As String) As Boolean
                Dim solution As SPSolution = SPFarm.Local.Solutions(solutionName)
                Return solution IsNot Nothing
            End Function
    
            ' Upgrades the specified solution to the local SharePoint server.
            <SharePointCommand("Contoso.Commands.UpgradeSolution")> _
            Private Sub UpgradeSolution(ByVal context As ISharePointCommandContext, ByVal fullWspPath As String)
                Dim solution As SPSolution = SPFarm.Local.Solutions(Path.GetFileName(fullWspPath))
                If solution Is Nothing Then
                    Throw New InvalidOperationException("The solution has not been deployed.")
                End If
                solution.Upgrade(fullWspPath)
            End Sub
    
        End Class
    End Namespace
    
    using System;
    using System.IO;
    using Microsoft.SharePoint;
    using Microsoft.SharePoint.Administration;
    using Microsoft.VisualStudio.SharePoint.Commands;
    
    namespace Contoso.DeploymentSteps.Upgrade
    {
        internal class Commands
        {
            // Determines whether the specified solution has been deployed to the local SharePoint server.
            [SharePointCommand("Contoso.Commands.IsSolutionDeployed")]
            private bool IsSolutionDeployed(ISharePointCommandContext context, string solutionName)
            {
                SPSolution solution = SPFarm.Local.Solutions[solutionName];
                return solution != null;
            }
    
            // Upgrades the specified solution to the local SharePoint server.
            [SharePointCommand("Contoso.Commands.UpgradeSolution")]
            private void UpgradeSolution(ISharePointCommandContext context, string fullWspPath)
            {
                SPSolution solution = SPFarm.Local.Solutions[Path.GetFileName(fullWspPath)];
    
                if (solution == null)
                {
                    throw new InvalidOperationException("The solution has not been deployed.");
                }
    
                solution.Upgrade(fullWspPath);
            }
        }
    }
    

검사점

이 연습의 이전 단계를 통해 사용자 지정 배포 단계와 SharePoint 명령을 위한 모든 코드가 프로젝트에 포함되었습니다. 솔루션을 빌드하여 두 프로젝트가 오류 없이 컴파일되는지 확인합니다.

솔루션을 빌드하려면

  • 빌드 메뉴에서 솔루션 빌드를 선택합니다.

확장을 배포하기 위한 VSIX 패키지 만들기

확장을 배포하려면 솔루션에서 VSIX 프로젝트를 사용하여 VSIX 패키지를 만듭니다. 먼저 VSIX 프로젝트에 포함된 source.extension.vsixmanifest 파일을 수정하여 VSIX 패키지를 구성합니다. 그런 다음 솔루션을 빌드하여 VSIX 패키지를 만듭니다.

VSIX 패키지를 구성하고 만들려면

  1. 솔루션 탐색기UpgradeDeploymentStep 프로젝트에서 source.extension.vsixmanifest 파일을 두 번 클릭합니다.

    매니페스트 편집기에서 파일이 열립니다. source.extension.vsixmanifest 파일은 모든 VSIX 패키지에서 필요한 extension.vsixmanifest 파일의 기초를 제공합니다. 이 파일에 대한 자세한 내용은 VSIX Extension Schema Reference를 참조하십시오.

  2. 제품 이름 상자에 Upgrade Deployment Step for SharePoint Projects를 입력합니다.

  3. 만든 이 상자에 Contoso를 입력합니다.

  4. 설명 상자에 SharePoint 프로젝트에 사용할 수 있는 사용자 지정 업그레이드 배포 단계 제공을 입력합니다.

  5. 편집기의 콘텐츠 섹션에서 콘텐츠 추가 단추를 클릭합니다.

  6. 콘텐츠 추가 대화 상자의 콘텐츠 형식 선택 목록 상자에서 MEF Component를 선택합니다.

    참고

    이 값은 extension.vsixmanifest 파일의 MefComponent 요소에 해당합니다. 이 요소는 VSIX 패키지의 확장 어셈블리 이름을 지정합니다. 자세한 내용은 MEFComponent Element (VSX Schema)를 참조하십시오.

  7. 소스 선택에서 프로젝트 라디오 단추를 클릭하고 그 옆에 있는 목록 상자에서 DeploymentStepExtension을 선택합니다.

  8. 확인을 클릭합니다.

  9. 매니페스트 편집기에서 콘텐츠 추가 단추를 다시 클릭합니다.

  10. 콘텐츠 추가 대화 상자의 콘텐츠 형식을 선택하십시오. 목록 상자에서 사용자 지정 확장 형식을 선택합니다.

    참고

    이 값은 extension.vsixmanifest 파일의 CustomExtension 요소에 해당합니다. 이 요소는 Visual Studio 확장에 포함할 사용자 지정 확장을 지정합니다. 자세한 내용은 CustomExtension Element (VSX Schema)를 참조하십시오.

  11. 형식 텍스트 상자에 SharePoint.Commands.v4를 입력합니다.

    참고

    이 값은 extension.vsixmanifest 파일에 있는 CustomExtension 요소의 Type 특성에 해당합니다. 사용자 지정 SharePoint 명령이 포함된 모든 사용자 지정 확장 어셈블리에 값 Sharepoint.Commands.v4가 필요합니다.

  12. 소스 선택에서 프로젝트 라디오 단추를 클릭하고 그 옆에 있는 목록 상자에서 SharePointCommands를 선택합니다.

  13. 확인을 클릭합니다.

  14. 빌드 메뉴에서 솔루션 빌드를 클릭합니다. 솔루션이 오류 없이 컴파일되는지 확인합니다.

  15. UpgradeDeploymentStep 프로젝트의 빌드 출력 폴더를 엽니다. 이제 이 폴더에 UpgradeDeploymentStep.vsix 파일이 들어 있습니다.

    기본적으로 빌드 출력 경로는 프로젝트 파일이 포함된 폴더 아래에 있는 .. \bin\Debug 폴더입니다.

업그레이드 배포 단계 테스트 준비

업그레이드 배포 단계를 테스트하려면 먼저 SharePoint 사이트에 샘플 솔루션을 배포해야 합니다. 제일 먼저 실험 모드의 Visual Studio 인스턴스에서 확장을 디버깅합니다. 그런 다음 배포 단계를 테스트하는 데 사용할 목록 정의와 목록 인스턴스를 만들고 이를 SharePoint 사이트에 배포합니다. 그런 다음 목록 정의와 목록 인스턴스를 수정하고 다시 배포하여 기본 배포 프로세스에서 SharePoint 사이트의 솔루션을 어떻게 덮어쓰는지 확인합니다.

이 연습의 뒷부분에서는 목록 정의와 목록 인스턴스를 수정한 다음 이를 SharePoint 사이트에서 업그레이드할 것입니다.

확장 디버깅을 시작하려면

  1. 관리자 권한으로 Visual Studio를 다시 시작하고 UpgradeDeploymentStep 솔루션을 엽니다.

  2. DeploymentStepExtension 프로젝트에서 UpgradeStep 코드 파일을 열고 CanExecute 및 Execute 메서드의 코드 첫 줄에 중단점을 추가합니다.

  3. F5 키를 눌러 디버깅을 시작합니다.

  4. Visual Studio에서는 확장을 %UserProfile%\AppData\Local\Microsoft\VisualStudio\10.0Exp\Extensions\Contoso\Upgrade Deployment Step for SharePoint Projects\1.0에 설치하고 실험 모드의 Visual Studio 인스턴스를 시작합니다. 이 Visual Studio 인스턴스에서 업그레이드 배포 단계를 테스트합니다.

목록 정의와 목록 인스턴스를 만들려면

  1. 실험 모드의 Visual Studio 인스턴스에서 파일 메뉴의 새로 만들기를 가리킨 다음 프로젝트를 클릭합니다.

  2. 새 프로젝트 대화 상자에서 Visual C#, SharePoint를 차례로 확장한 다음 2010을 클릭합니다.

  3. 대화 상자 맨 위의 콤보 상자에서 .NET Framework 3.5가 선택되어 있는지 확인합니다. Microsoft SharePoint Foundation 2010 및 Microsoft SharePoint Server 2010용 프로젝트에는 이 .NET Framework 버전이 필요합니다.

  4. 프로젝트 템플릿 목록에서 목록 정의를 클릭합니다.

  5. 이름 상자에 EmployeesListDefinition을 입력합니다.

  6. 확인을 클릭합니다.

  7. SharePoint 사용자 지정 마법사에서 디버깅에 사용할 사이트의 URL을 입력합니다.

  8. **이 SharePoint 솔루션의 신뢰 수준을 선택하십시오.**에서 팜 솔루션으로 배포를 클릭합니다.

    참고

    샌드박스가 적용된 솔루션은 업그레이드 배포 단계에서 지원하지 않습니다.

  9. 다음을 클릭합니다.

  10. 목록 정의 설정 선택 페이지의 목록 정의의 표시 이름을 선택하십시오. 아래에 Employees List를 입력합니다.

  11. **목록 정의 유형을 선택하십시오.**에서 연락처를 선택합니다.

  12. 이 목록 정의에 대해 목록 인스턴스 추가 확인란이 선택되었는지 확인합니다.

  13. 마침을 클릭합니다.

    프로젝트가 만들어지고 목록 정의에 대한 Elements.xml 파일이 편집기에서 열립니다.

  14. 솔루션 탐색기에서 EmployeesListDefinition 프로젝트 노드를 마우스 오른쪽 단추로 클릭하고 속성을 클릭합니다.

  15. 프로젝트 속성의 SharePoint 탭에서 디버깅 후 자동 취소 확인란의 선택을 취소합니다.

  16. 솔루션 탐색기에서 ListDefinition1 노드를 확장하고 자식 ListInstance1 노드를 확장합니다.

  17. ListInstance1 노드의 자식인 Elements.xml 파일을 두 번 클릭합니다. Elements.xml 파일이 편집기에서 열립니다.

  18. 이 파일의 기본 XML을 다음 XML로 바꿉니다. 이 XML에서는 목록의 이름을 Employees로 변경합니다. 또한 이름이 Jim Hance인 직원에 대한 항목을 추가합니다.

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="https://schemas.microsoft.com/sharepoint/">
      <ListInstance Title="Employees"
                    OnQuickLaunch="TRUE"
                    TemplateType="10000"
                    Url="Lists/Employees"
                    Description="Simple list to test upgrade deployment step">
        <Data>
          <Rows>
            <Row>
              <Field Name="Title">Hance</Field>
              <Field Name="FirstName">Jim</Field>
              <Field Name="Company">Contoso</Field>
            </Row>
          </Rows>
        </Data>
      </ListInstance>
    </Elements>
    

목록 정의와 목록 인스턴스를 배포하려면

  1. 솔루션 탐색기에서 EmployeesListDefinition 프로젝트 노드를 클릭합니다.

  2. 속성 창에서 활성 배포 구성 속성이 기본값으로 설정되어 있는지 확인합니다.

  3. F5 키를 누릅니다.

  4. 프로젝트가 성공적으로 빌드되고 SharePoint 사이트에 새 Employees 목록이 열리고 이 목록에 Jim Hance의 항목이 포함되었는지 확인합니다.

  5. 웹 브라우저를 닫습니다.

목록 정의와 목록 인스턴스를 수정하고 다시 배포하려면

  1. EmployeesListDefinition 프로젝트에서 ListInstance1 프로젝트 항목의 자식인 Elements.xml 파일을 두 번 클릭합니다.

  2. Data 요소와 해당 자식 요소를 제거하여 목록에서 Jim Hance의 항목을 제거합니다. 작업을 마치면 파일에 다음 XML이 포함됩니다.

    <?xml version="1.0" encoding="utf-8"?>
    <Elements xmlns="https://schemas.microsoft.com/sharepoint/">
      <ListInstance Title="Employees"
                    OnQuickLaunch="TRUE"
                    TemplateType="10000"
                    Url="Lists/Employees"
                    Description="Simple list to test upgrade deployment step">
      </ListInstance>
    </Elements>
    
  3. ListDefinition1 프로젝트 항목의 자식인 Schema.xml 파일을 두 번 클릭합니다.

  4. 이 파일에서 문자열 BaseViewID="1"을 검색합니다. 이 문자열은 다음 단계에서 수정할 View 요소의 특성입니다.

  5. 이 View 요소 아래에서 자식 ViewFields 요소를 찾습니다.

  6. ViewFields 요소 아래에서 Name 특성이 Attachments 및 HomePhone으로 설정된 두 개의 자식 FieldRef 요소를 제거합니다. 이 작업을 수행하면 SharePoint 사이트에 있는 Employees 목록의 기본 뷰에서 해당 필드가 제거됩니다. 작업을 마치면 ViewFields 요소에 다음 내용이 포함됩니다.

    <ViewFields>
      <FieldRef Name="LinkTitle" />
      <FieldRef Name="FirstName" />
      <FieldRef Name="Company" />
      <FieldRef Name="WorkPhone" />
      <FieldRef Name="Email" />
    </ViewFields>
    
  7. F5 키를 누릅니다. 배포 충돌 대화 상자가 나타나는지 확인합니다. 이 대화 상자는 Visual Studio에서 솔루션이 이미 배포되어 있는 SharePoint 사이트에 해당 솔루션(목록 인스턴스)을 배포하려고 할 때 나타납니다.

    이 연습의 뒷부분에서 업그레이드 배포 단계를 실행하면 이 대화 상자가 사라지는 것을 확인합니다.

  8. 자동으로 해결을 클릭합니다. SharePoint 사이트에서 목록 인스턴스가 삭제되고 프로젝트에 목록 항목이 배포된 다음 SharePoint 사이트에 Employees 목록이 열립니다.

  9. 다음 세부 정보를 확인합니다.

    • 이 목록 뷰에는 첨부 파일집 전화 열이 표시되지 않습니다.

    • 이제 목록이 비어 있습니다. 기본 배포 구성을 사용하여 솔루션을 다시 배포한 경우 Employees 목록이 프로젝트의 새로운 빈 목록으로 바뀌었습니다.

배포 단계 테스트

이제 업그레이드 배포 단계를 테스트할 준비가 되었습니다. 제일 먼저 SharePoint의 목록 인스턴스에 항목을 추가합니다. 그런 다음 목록 정의와 목록 인스턴스를 변경하고 이를 SharePoint 사이트에서 업그레이드하여 업그레이드 배포 단계를 통해 새 항목을 덮어쓰지 않는지 확인합니다.

목록에 항목을 수동으로 추가하려면

  1. SharePoint 사이트의 리본 메뉴에서 항목 탭을 클릭합니다.

  2. 새로 만들기 그룹에서 새 항목을 클릭합니다.

  3. 필드에 Ruth를 입력합니다.

  4. 이름 필드에 Andy를 입력합니다.

  5. 회사 필드에 Contoso를 입력합니다.

  6. 저장을 클릭합니다. 새 항목이 목록에 표시되는지 확인합니다. 이 연습의 뒷부분에서 이 항목을 사용하여 업그레이드 배포 단계에서 이 목록의 내용을 덮어쓰지 않는 것을 확인합니다.

  7. 웹 브라우저를 닫습니다.

업그레이드 배포 단계를 테스트하려면

  1. 실험 모드의 Visual Studio 인스턴스에서 솔루션 탐색기EmployeesListDefinition 프로젝트 노드를 클릭합니다.

  2. 속성 창에서 활성 배포 구성 속성을 업그레이드로 설정합니다. 이 구성은 새 업그레이드 배포 단계가 포함된 사용자 지정 배포 구성입니다.

  3. ListDefinition1 프로젝트 항목의 자식인 Schema.xml 파일을 두 번 클릭합니다.

  4. 앞서 수정한 ViewFields 요소를 찾습니다.

  5. ViewFields 요소 아래에서 Name 특성이 WorkPhone 및 Email로 설정된 두 개의 자식 FieldRef 요소를 제거합니다. 이 작업을 수행하면 SharePoint 사이트에 있는 Employees 목록의 기본 뷰에서 해당 필드가 제거됩니다. 작업을 마치면 ViewFields 요소에 다음 내용이 포함됩니다.

    <ViewFields>
      <FieldRef Name="LinkTitle" />
      <FieldRef Name="FirstName" />
      <FieldRef Name="Company" />
    </ViewFields>
    
  6. F5 키를 누릅니다. 다른 Visual Studio 인스턴스의 코드가 이전에 CanExecute 메서드에 설정한 중단점에서 중지하는지 확인합니다.

  7. F5 키를 다시 누릅니다. 코드가 이전에 Execute 메서드에 설정한 중단점에서 중지하는지 확인합니다.

  8. F5 키를 마지막으로 누릅니다. SharePoint 사이트에 Employees 목록이 열립니다.

  9. 빠른 실행 영역에서 Employees 목록을 클릭합니다.

  10. 다음 세부 정보를 확인합니다.

    • 앞에서 수동으로 추가한 Andy Ruth 항목이 아직 목록에 있습니다.

    • 이 목록 뷰에는 회사 전화전자 메일 주소 열이 표시되지 않습니다.

    업그레이드 배포 구성은 SharePoint 사이트의 기존 Employees 목록 인스턴스를 수정합니다. 업그레이드 구성 대신 기본 배포 구성을 사용한 경우 배포 충돌이 발생합니다. Visual Studio에서는 Employees 목록을 바꾸어 충돌을 해결하며 Andy Ruth 항목이 삭제됩니다.

개발 컴퓨터 정리

업그레이드 배포 단계의 테스트를 마쳤으면 SharePoint 사이트에서 목록 인스턴스와 목록 정의를 제거하고 Visual Studio에서 배포 단계 확장을 제거합니다.

SharePoint 사이트에서 목록 인스턴스를 제거하려면

  1. SharePoint 사이트에 Employees 목록이 열려 있지 않으면 이 목록을 엽니다.

  2. SharePoint 사이트의 리본 메뉴에서 목록 탭을 클릭합니다.

  3. 목록 탭의 설정 그룹에서 목록 설정을 클릭합니다.

  4. 사용 권한 및 관리에서 이 목록 삭제를 클릭합니다. 확인을 클릭하여 목록을 휴지통으로 보냅니다.

  5. 웹 브라우저를 닫습니다.

SharePoint 사이트에서 목록 정의를 제거하려면

  • 실험 모드의 Visual Studio 인스턴스에서 빌드 메뉴의 제거를 선택합니다.

    SharePoint 사이트에서 목록 정의가 제거됩니다.

확장을 제거하려면

  1. 실험 모드의 Visual Studio 인스턴스에서 도구 메뉴의 확장 관리자를 클릭합니다.

    확장 관리자 대화 상자가 열립니다.

  2. 확장 목록에서 Deployment Step for SharePoint Projects를 클릭하고 제거를 클릭합니다.

  3. 나타나는 대화 상자에서 를 클릭하여 확장을 제거합니다.

  4. 지금 다시 시작을 클릭하여 제거를 완료합니다.

  5. Visual Studio의 두 인스턴스, 즉 실험 모드의 인스턴스와 UpgradeDeploymentStep 솔루션이 열려 있는 Visual Studio 인스턴스를 모두 닫습니다.

참고 항목

기타 리소스

SharePoint 패키징 및 배포 확장