-
Notifications
You must be signed in to change notification settings - Fork 90
Using LibMan in a CI Build
There are two ways to restore files during CI builds:
- Using the LibMan MSBuild package
- Using the LibMan CLI tool
Simply install the Microsoft.Web.LibraryManager.Build package in your project. This package includes a build task that will restore the libman.json manifest during the build. Note that package only supports when your libman.json file is in the same directory as your .csproj file.
See LibMan MSBuild Reference for details.
You can run the CLI tool as a step before building your .NET project. The CLI tool does not require a .csproj file, so you can use this to restore files anywhere you have a libman.json file.
See LibMan CLI Reference for details about the CLI tool.
Example using Azure Pipelines:
# Install the CLI tool
- task: DotNetCoreCLI@2
displayName: 'Install LibMan CLI'
inputs:
command: custom
custom: tool
arguments: 'install -g Microsoft.Web.LibraryManager.Cli'
# Restore
- task: CmdLine@2
displayName: 'Run LibMan Restore'
inputs:
script: 'libman restore'
workingDirectory: '<path to the directory where your libman.json is located>'
Example using GitHub Actions:
# Install LibMan CLI globally
- name: Install LibMan CLI
run: dotnet tool install -g Microsoft.Web.LibraryManager.Cli
# Restore libraries using LibMan
- name: Run LibMan Restore
run: libman restore
working-directory: '<path to the directory where your libman.json is located>'
In order to speed up CI builds, you may want to store the LibMan cache for reuse in your CI pipeline. Some CI platforms allow this, such as Azure Pipelines' cache@v2 task (docs), or GitHub Actions' cache action (docs).