연습 - 애플리케이션에서 패키지 참조

완료됨

이 단원에서는 모델 클래스가 제거된 새로운 Tailspin.SpaceGame.Web 코드가 제공됩니다. 모델을 직접 참조하는 대신 코드는 이전 단원에서 만든 패키지의 모델을 참조합니다.

다음은 단계 목록입니다.

  • 원래 Tailspin.SpaceGame.Web 리포지토리의 분기에서 새 코드를 가져옵니다.
  • 새 Models 패키지, 버전 1.0.0을 참조합니다.
  • Azure Artifacts 피드에서 이 패키지를 찾으려면 빌드 파이프라인을 변경합니다.
  • 파이프라인이 앱을 성공적으로 빌드하는지 확인합니다.

GitHub에서 분기 가져오기

여기서는 GitHub에서 models-package 분기를 페치하거나 이 분기로 전환합니다.

이 분기에는 이전 모듈에서 작업한 Space Game 프로젝트가 포함되어 있지만 Models 디렉터리는 제거되었습니다.

  1. Tailspin.SpaceGame.Web 프로젝트를 보여 주는 Visual Studio Code의 복사본으로 전환합니다.

  2. 터미널에서, Microsoft 리포지토리에서 models-package라는 분기를 페치하려면 다음 git 명령을 실행합니다. 그런 다음 해당 분기로 전환합니다.

    git fetch upstream models-package
    git checkout -B models-package upstream/models-package
    

    이러한 명령 형식을 사용하면 upstream이라고 하는 GitHub의 Microsoft 리포지토리에서 시작 코드를 가져올 수 있습니다. 잠시 후에 이 분기를 origin이라는 GitHub 리포지토리로 푸시합니다.

  3. 선택적 단계로 Models 디렉터리가 더 이상 파일 탐색기에 없는지 확인합니다. 대신 컨트롤러, 보기 및 기타 디렉터리가 표시됩니다.

Models 패키지 참조

  1. Tailspin.SpaceGame.Web.csproj 파일을 열고 다음 ItemGroup을 추가합니다.

    <ItemGroup>
      <PackageReference Include="Tailspin.SpaceGame.Web.Models" Version="1.0.0" />
    </ItemGroup>
    

    Project 노드 내부에 ItemGroup을 추가해야 합니다. 파일은 다음과 비슷합니다.

    <Project Sdk="Microsoft.NET.Sdk.Web">
    
      <PropertyGroup>
        <TargetFramework>net6.0</TargetFramework>
        <ProjectGuid>{A0C4E31E-AC75-4F39-9F59-0AA19D9B8F46}</ProjectGuid>
      </PropertyGroup>
    
      <ItemGroup>
        <PackageReference Include="Tailspin.SpaceGame.Web.Models" Version="1.0.0" />
      </ItemGroup>
    
      <ItemGroup>
        <Folder Include="wwwroot\images\avatars\" />
      </ItemGroup>
    </Project>
    
  2. 빌드 프로세스 중에 생성된 시험판 접두사를 포함하려면 버전 번호 "1.0.0"을 수정합니다. 예를 들면 다음과 같습니다.

    <PackageReference Include="Tailspin.SpaceGame.Web.Models" Version="1.0.0-CI-20200610-165738" />
    

    Azure Artifacts에서 만든 Tailspin.SpaceGame.Web.Models 패키지를 참조합니다. 버전 번호, 1.0.0과 시험판 접미사를 확인합니다. 이전 단원에서 Azure Artifacts에 게시한 초기 버전과 일치합니다.

  3. 파일을 저장합니다.

    참고

    파일을 저장할 때 Visual Studio Code에서 종속성을 복원하도록 요청할 수 있습니다. 복원 버튼을 선택하여 종속성을 복원합니다.

파이프라인 구성 수정

models-package 분기는 초기 azure-pipelines.yml 파일을 제공합니다. 여기서는 Azure Artifacts에서 Tailspin.SpaceGame.Web.Models 패키지를 끌어오도록 파이프라인 구성을 수정합니다.

  1. Visual Studio Code에서 azure-pipelines.yml을 엽니다.

  2. 여기에 표시된 것처럼 azure-pipelines.yml을 수정합니다.

    trigger:
    - '*'
    
    pool:
      vmImage: 'ubuntu-20.04'
      demands:
      - npm
    
    variables:
      buildConfiguration: 'Release'
      wwwrootDir: 'Tailspin.SpaceGame.Web/wwwroot'
      dotnetSdkVersion: '6.x'
    
    steps:
    - task: UseDotNet@2
      displayName: 'Use .NET SDK $(dotnetSdkVersion)'
      inputs:
        version: '$(dotnetSdkVersion)'
    
    - task: NuGetToolInstaller@0
      inputs:
        versionSpec: '5.9.1'
    
    - task: Npm@1
      displayName: 'Run npm install'
      inputs:
        verbose: false
    
    - script: './node_modules/.bin/node-sass $(wwwrootDir) --output $(wwwrootDir)'
      displayName: 'Compile Sass assets'
    
    - task: gulp@1
      displayName: 'Run gulp tasks'
    
    - script: 'echo "$(Build.DefinitionName), $(Build.BuildId), $(Build.BuildNumber)" > buildinfo.txt'
      displayName: 'Write build info'
      workingDirectory: $(wwwrootDir)
    
    - task: NuGetCommand@2
      displayName: 'Restore project dependencies'
      inputs:
        command: 'restore'
        restoreSolution: '**/*.sln'
        feedsToUse: 'select'
        vstsFeed: '$(System.TeamProject)/Tailspin.SpaceGame.Web.Models'
    
    - task: DotNetCoreCLI@2
      displayName: 'Build the project - $(buildConfiguration)'
      inputs:
        command: 'build'
        arguments: '--no-restore --configuration $(buildConfiguration)'
        projects: '**/*.csproj'
    
    - task: DotNetCoreCLI@2
      displayName: 'Publish the project - $(buildConfiguration)'
      inputs:
        command: 'publish'
        projects: '**/*.csproj'
        publishWebProjects: false
        arguments: '--no-build --configuration $(buildConfiguration) --output $(Build.ArtifactStagingDirectory)/$(buildConfiguration)'
        zipAfterPublish: true
    
    - task: PublishBuildArtifacts@1
      displayName: 'Publish Artifact: drop'
      condition: succeeded()
    

    강조 표시된 코드는 파이프라인이 종속성을 복원하고 Azure Artifacts 피드에서 잠재적인 종속성을 찾는 위치를 보여 줍니다.

  3. GitHub에 변경 내용을 준비, 커밋, 푸시

    git add .
    git commit -m "Add reference to Models package"
    git push origin models-package
    
  4. Azure Pipelines로 이동하여 빌드 실행을 살펴봅니다. 빌드는 Azure Artifacts에서 Models 패키지를 선택하고 프로젝트를 성공적으로 빌드합니다.