ASP.NET Core에서 LibMan CLI 사용

작성자: Scott Addie

LibMan CLI는 .NET Core가 지원되는 플랫폼 간 도구입니다.

사전 요구 사항

설치

LibMan CLI를 설치하려면 다음을 수행합니다.

dotnet tool install -g Microsoft.Web.LibraryManager.Cli

.NET Core 전역 도구Microsoft.Web.LibraryManager.Cli NuGet 패키지에서 설치됩니다.

특정 NuGet 패키지 원본에서 LibMan CLI를 설치하려면 다음을 수행합니다.

dotnet tool install -g Microsoft.Web.LibraryManager.Cli --version 1.0.94-g606058a278 --add-source C:\Temp\

위의 예제에서 .NET Core 전역 도구는 로컬 Windows 머신의 C:\Temp\Microsoft.Web.LibraryManager.Cli.1.0.94-g606058a278.nupkg 파일에서 설치됩니다.

사용법

CLI를 성공적으로 설치한 후에는 다음 명령을 사용할 수 있습니다.

libman

설치된 CLI 버전을 보려면 다음을 수행합니다.

libman --version

사용 가능한 CLI 명령을 보려면 다음을 수행합니다.

libman --help

위의 명령은 다음과 유사한 출력을 표시합니다.

 1.0.163+g45474d37ed

Usage: libman [options] [command]

Options:
  --help|-h  Show help information
  --version  Show version information

Commands:
  cache      List or clean libman cache contents
  clean      Deletes all library files defined in libman.json from the project
  init       Create a new libman.json
  install    Add a library definition to the libman.json file, and download the 
             library to the specified location
  restore    Downloads all files from provider and saves them to specified 
             destination
  uninstall  Deletes all files for the specified library from their specified 
             destination, then removes the specified library definition from 
             libman.json
  update     Updates the specified library

Use "libman [command] --help" for more information about a command.

다음 섹션에서는 사용 가능한 CLI 명령에 대해 간략하게 설명합니다.

프로젝트에서 LibMan 초기화

libman init 명령은 libman.json 파일이 없는 경우 새로 만듭니다. 이 파일은 기본 항목 템플릿 콘텐츠를 사용하여 만들어집니다.

개요

libman init [-d|--default-destination] [-p|--default-provider] [--verbosity]
libman init [-h|--help]

옵션

다음 옵션은 libman init 명령에 사용할 수 있습니다.

  • -d|--default-destination <PATH>

    현재 폴더에 상대적인 경로입니다. libman.json의 라이브러리에 대해 destination 속성이 정의되지 않으면 라이브러리 파일이 이 위치에 설치됩니다. <PATH> 값은 libman.jsondefaultDestination 속성에 기록됩니다.

  • -p|--default-provider <PROVIDER>

    지정된 라이브러리에 대해 공급자를 지정하지 않은 경우 사용할 공급자입니다. <PROVIDER> 값은 libman.jsondefaultProvider 속성에 기록됩니다. <PROVIDER>을 다음 값 중 하나로 바꿉니다.

    • cdnjs
    • filesystem
    • jsdelivr
    • unpkg
  • -h|--help

    도움말 정보를 표시합니다.

  • --verbosity <LEVEL>

    출력의 자세한 정도를 설정합니다. <LEVEL>을 다음 값 중 하나로 바꿉니다.

    • quiet
    • normal
    • detailed

ASP.NET Core 프로젝트에서 libman.json 파일을 만들려면 다음을 수행합니다.

  • 프로젝트 루트로 이동합니다.

  • 다음 명령을 실행합니다.

    libman init
    
  • 기본 공급자의 이름을 입력하거나 Enter 키를 눌러 기본 CDNJS 공급자를 사용합니다. 유효한 값은 다음과 같습니다.

    • cdnjs
    • filesystem
    • jsdelivr
    • unpkg

    libman init 명령 - 기본 공급자

다음 콘텐츠를 사용하여 libman.json 파일이 프로젝트 루트에 추가됩니다.

{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "libraries": []
}

라이브러리 파일 추가

libman install 명령은 라이브러리 파일을 다운로드하여 프로젝트에 설치합니다. libman.json 파일이 없는 경우 추가됩니다. 라이브러리 파일에 대한 구성 세부 정보를 저장하도록 libman.json 파일이 수정됩니다.

개요

libman install <LIBRARY> [-d|--destination] [--files] [-p|--provider] [--verbosity]
libman install [-h|--help]

인수

LIBRARY

설치할 라이브러리의 이름입니다. 이 이름에는 버전 번호 표기법(예: @1.2.0)이 포함될 수 있습니다.

옵션

다음 옵션은 libman install 명령에 사용할 수 있습니다.

  • -d|--destination <PATH>

    라이브러리를 설치할 위치입니다. 이 값을 지정하지 않으면 기본 위치가 사용됩니다. libman.jsondefaultDestination 속성이 지정되지 않은 경우 이 옵션은 필수입니다.

  • --files <FILE>

    라이브러리에서 설치할 파일의 이름을 지정합니다. 지정하지 않으면 라이브러리의 모든 파일이 설치됩니다. 설치할 파일마다 하나의 --files 옵션을 제공합니다. 상대 경로도 지원됩니다. 예를 들어 --files dist/browser/signalr.js을 참조하십시오.

  • -p|--provider <PROVIDER>

    라이브러리 획득에 사용할 공급자의 이름입니다. <PROVIDER>을 다음 값 중 하나로 바꿉니다.

    • cdnjs
    • filesystem
    • jsdelivr
    • unpkg

    지정하지 않으면 libman.jsondefaultProvider 속성이 사용됩니다. libman.jsondefaultProvider 속성이 지정되지 않은 경우 이 옵션은 필수입니다.

  • -h|--help

    도움말 정보를 표시합니다.

  • --verbosity <LEVEL>

    출력의 자세한 정도를 설정합니다. <LEVEL>을 다음 값 중 하나로 바꿉니다.

    • quiet
    • normal
    • detailed

다음 libman.json 파일을 살펴보세요.

{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "libraries": []
}

CDNJS 공급자를 사용하여 jQuery 버전 3.2.1 jquery.min.js 파일을 wwwroot/scripts/jquery 폴더에 설치하려면 다음을 수행합니다.

libman install jquery@3.2.1 --provider cdnjs --destination wwwroot/scripts/jquery --files jquery.min.js

libman.json 파일은 다음과 유사합니다.

{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "libraries": [
    {
      "library": "jquery@3.2.1",
      "destination": "wwwroot/scripts/jquery",
      "files": [
        "jquery.min.js"
      ]
    }
  ]
}

파일 시스템 공급자를 사용하여 C:\temp\contosoCalendar\에서 calendar.jscalendar.css 파일을 설치하려면 다음을 수행합니다.

libman install C:\temp\contosoCalendar\ --provider filesystem --files calendar.js --files calendar.css

다음과 같은 두 가지 이유로 다음 프롬프트가 표시됩니다.

  • libman.json 파일에는 defaultDestination 속성이 포함되어 있지 않습니다.
  • libman install 명령에는 -d|--destination 옵션이 포함되어 있지 않습니다.

libman install 명령 - 대상

기본 대상을 승인한 후에 libman.json 파일은 다음과 유사합니다.

{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "libraries": [
    {
      "library": "jquery@3.2.1",
      "destination": "wwwroot/scripts/jquery",
      "files": [
        "jquery.min.js"
      ]
    },
    {
      "library": "C:\\temp\\contosoCalendar\\",
      "provider": "filesystem",
      "destination": "wwwroot/lib/contosoCalendar",
      "files": [
        "calendar.js",
        "calendar.css"
      ]
    }
  ]
}

라이브러리 파일 복원

libman restore 명령은 libman.json에 정의된 라이브러리 파일을 설치합니다. 다음 규칙이 적용됩니다.

  • 프로젝트 루트에 libman.json 파일이 없으면 오류가 반환됩니다.
  • 라이브러리가 공급자를 지정하는 경우 libman.jsondefaultProvider 속성이 무시됩니다.
  • 라이브러리가 대상을 지정하는 경우 libman.jsondefaultDestination 속성이 무시됩니다.

개요

libman restore [--verbosity]
libman restore [-h|--help]

옵션

다음 옵션은 libman restore 명령에 사용할 수 있습니다.

  • -h|--help

    도움말 정보를 표시합니다.

  • --verbosity <LEVEL>

    출력의 자세한 정도를 설정합니다. <LEVEL>을 다음 값 중 하나로 바꿉니다.

    • quiet
    • normal
    • detailed

libman.json 파일에 정의된 라이브러리 파일을 복원하려면 다음을 수행합니다.

libman restore

라이브러리 폴더 삭제

libman clean 명령은 LibMan을 통해 이전에 복원한 라이브러리 파일을 삭제합니다. 이 작업 후 삭제된 후에 비어 있게 되는 폴더입니다. libman.jsonlibraries 속성에 있는 라이브러리 파일의 연결된 구성은 제거되지 않습니다.

개요

libman clean [--verbosity]
libman clean [-h|--help]

옵션

다음 옵션은 libman clean 명령에 사용할 수 있습니다.

  • -h|--help

    도움말 정보를 표시합니다.

  • --verbosity <LEVEL>

    출력의 자세한 정도를 설정합니다. <LEVEL>을 다음 값 중 하나로 바꿉니다.

    • quiet
    • normal
    • detailed

LibMan을 통해 설치된 라이브러리 파일을 삭제하려면 다음을 수행합니다.

libman clean

라이브러리 파일 제거

libman uninstall 명령은 다음을 수행합니다.

  • 지정된 라이브러리와 연결된 모든 파일을 libman.json의 대상에서 삭제합니다.
  • 연결된 라이브러리 구성을 libman.json에서 제거합니다.

다음 경우에 오류가 발생합니다.

  • 프로젝트 루트에는 libman.json 파일이 없습니다.
  • 지정된 라이브러리가 없습니다.

이름이 같은 라이브러리가 2개 이상 설치되어 있으면 하나를 선택하라는 메시지가 표시됩니다.

개요

libman uninstall <LIBRARY> [--verbosity]
libman uninstall [-h|--help]

인수

LIBRARY

제거할 라이브러리의 이름입니다. 이 이름에는 버전 번호 표기법(예: @1.2.0)이 포함될 수 있습니다.

옵션

다음 옵션은 libman uninstall 명령에 사용할 수 있습니다.

  • -h|--help

    도움말 정보를 표시합니다.

  • --verbosity <LEVEL>

    출력의 자세한 정도를 설정합니다. <LEVEL>을 다음 값 중 하나로 바꿉니다.

    • quiet
    • normal
    • detailed

다음 libman.json 파일을 살펴보세요.

{
  "version": "1.0",
  "defaultProvider": "cdnjs",
  "libraries": [
    {
      "library": "jquery@3.3.1",
      "files": [
        "jquery.min.js",
        "jquery.js",
        "jquery.min.map"
      ],
      "destination": "wwwroot/lib/jquery/"
    },
    {
      "provider": "unpkg",
      "library": "bootstrap@4.1.3",
      "destination": "wwwroot/lib/bootstrap/"
    },
    {
      "provider": "filesystem",
      "library": "C:\\temp\\lodash\\",
      "files": [
        "lodash.js",
        "lodash.min.js"
      ],
      "destination": "wwwroot/lib/lodash/"
    }
  ]
}
  • jQuery를 제거하려면 다음 명령 중 하나를 수행합니다.

    libman uninstall jquery
    
    libman uninstall jquery@3.3.1
    
  • filesystem 공급자를 통해 설치된 Lodash 파일을 제거하려면 다음을 수행합니다.

    libman uninstall C:\temp\lodash\
    

라이브러리 버전 업데이트

libman update 명령은 LibMan을 통해 설치된 라이브러리를 지정된 버전으로 업데이트합니다.

다음 경우에 오류가 발생합니다.

  • 프로젝트 루트에는 libman.json 파일이 없습니다.
  • 지정된 라이브러리가 없습니다.

이름이 같은 라이브러리가 2개 이상 설치되어 있으면 하나를 선택하라는 메시지가 표시됩니다.

개요

libman update <LIBRARY> [-pre] [--to] [--verbosity]
libman update [-h|--help]

인수

LIBRARY

업데이트할 라이브러리의 이름입니다.

옵션

다음 옵션은 libman update 명령에 사용할 수 있습니다.

  • -pre

    라이브러리의 최신 시험판 버전을 가져옵니다.

  • --to <VERSION>

    라이브러리의 특정 버전을 가져옵니다.

  • -h|--help

    도움말 정보를 표시합니다.

  • --verbosity <LEVEL>

    출력의 자세한 정도를 설정합니다. <LEVEL>을 다음 값 중 하나로 바꿉니다.

    • quiet
    • normal
    • detailed

  • jQuery를 최신 버전으로 업데이트하려면 다음을 수행합니다.

    libman update jquery
    
  • jQuery를 버전 3.3.1로 업데이트하려면 다음을 수행합니다.

    libman update jquery --to 3.3.1
    
  • jQuery를 최신 시험판 버전으로 업데이트하려면 다음을 수행합니다.

    libman update jquery -pre
    

라이브러리 캐시 관리

libman cache 명령은 LibMan 라이브러리 캐시를 관리합니다. filesystem 공급자는 라이브러리 캐시를 사용하지 않습니다.

개요

libman cache clean [<PROVIDER>] [--verbosity]
libman cache list [--files] [--libraries] [--verbosity]
libman cache [-h|--help]

인수

PROVIDER

clean 명령에서만 사용됩니다. 정리할 공급자 캐시를 지정합니다. 유효한 값은 다음과 같습니다.

  • cdnjs
  • filesystem
  • jsdelivr
  • unpkg

옵션

다음 옵션은 libman cache 명령에 사용할 수 있습니다.

  • --files

    캐시된 파일의 이름을 나열합니다.

  • --libraries

    캐시된 라이브러리의 이름을 나열합니다.

  • -h|--help

    도움말 정보를 표시합니다.

  • --verbosity <LEVEL>

    출력의 자세한 정도를 설정합니다. <LEVEL>을 다음 값 중 하나로 바꿉니다.

    • quiet
    • normal
    • detailed

  • 공급자당 캐시된 라이브러리의 이름을 보려면 다음 명령 중 하나를 사용합니다.

    libman cache list
    
    libman cache list --libraries
    

    다음과 비슷한 출력이 표시됩니다.

    Cache contents:
    ---------------
    unpkg:
        knockout
        react
        vue
    cdnjs:
        font-awesome
        jquery
        knockout
        lodash.js
        react
    
  • 공급자당 캐시된 라이브러리 파일의 이름을 보려면 다음을 수행합니다.

    libman cache list --files
    

    다음과 비슷한 출력이 표시됩니다.

    Cache contents:
    ---------------
    unpkg:
        knockout:
            <list omitted for brevity>
        react:
            <list omitted for brevity>
        vue:
            <list omitted for brevity>
    cdnjs:
        font-awesome
            metadata.json
        jquery
            metadata.json
            3.2.1\core.js
            3.2.1\jquery.js
            3.2.1\jquery.min.js
            3.2.1\jquery.min.map
            3.2.1\jquery.slim.js
            3.2.1\jquery.slim.min.js
            3.2.1\jquery.slim.min.map
            3.3.1\core.js
            3.3.1\jquery.js
            3.3.1\jquery.min.js
            3.3.1\jquery.min.map
            3.3.1\jquery.slim.js
            3.3.1\jquery.slim.min.js
            3.3.1\jquery.slim.min.map
        knockout
            metadata.json
            3.4.2\knockout-debug.js
            3.4.2\knockout-min.js
        lodash.js
            metadata.json
            4.17.10\lodash.js
            4.17.10\lodash.min.js
        react
            metadata.json
    

    위의 출력은 jQuery 버전 3.2.1 및 3.3.1이 CDNJS 공급자 아래에 캐시됨을 보여 줍니다.

  • CDNJS 공급자에 대한 라이브러리 캐시를 비우려면 다음을 수행합니다.

    libman cache clean cdnjs
    

    CDNJS 공급자 캐시를 비우면 libman cache list 명령은 다음을 표시합니다.

    Cache contents:
    ---------------
    unpkg:
        knockout
        react
        vue
    cdnjs:
        (empty)
    
  • 지원되는 모든 공급자에 대한 캐시를 비우려면 다음을 수행합니다.

    libman cache clean
    

    모든 공급자 캐시를 비우면 libman cache list 명령은 다음을 표시합니다.

    Cache contents:
    ---------------
    unpkg:
        (empty)
    cdnjs:
        (empty)
    

추가 자료