Utiliser l’interface CLI LibMan avec ASP.NET CoreUse the LibMan CLI with ASP.NET Core
Par Scott AddieBy Scott Addie
L’interface CLI LibMan est un outil multiplateforme qui est pris en charge partout où .net Core est pris en charge.The LibMan CLI is a cross-platform tool that's supported everywhere .NET Core is supported.
Conditions préalables requisesPrerequisites
InstallationInstallation
Pour installer l’interface CLI LibMan :To install the LibMan CLI:
dotnet tool install -g Microsoft.Web.LibraryManager.Cli
Un outil Global .net Core est installé à partir du package NuGet Microsoft. Web. librarymanager. CLI .A .NET Core Global Tool is installed from the Microsoft.Web.LibraryManager.Cli NuGet package.
Pour installer l’interface CLI LibMan à partir d’une source de package NuGet spécifique :To install the LibMan CLI from a specific NuGet package source:
dotnet tool install -g Microsoft.Web.LibraryManager.Cli --version 1.0.94-g606058a278 --add-source C:\Temp\
Dans l’exemple précédent, un outil Global .NET Core est installé à partir du fichier C:\Temp\Microsoft.Web.librarymanager.cli.1.0.94-g606058a278.nupkg de l’ordinateur Windows local.In the preceding example, a .NET Core Global Tool is installed from the local Windows machine's C:\Temp\Microsoft.Web.LibraryManager.Cli.1.0.94-g606058a278.nupkg file.
UsageUsage
Une fois l’installation de l’interface CLI réussie, vous pouvez utiliser la commande suivante :After successful installation of the CLI, the following command can be used:
libman
Pour afficher la version installée de l’interface de commande :To view the installed CLI version:
libman --version
Pour afficher les commandes CLI disponibles :To view the available CLI commands:
libman --help
La commande précédente affiche une sortie similaire à ce qui suit :The preceding command displays output similar to the following:
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.
Les sections suivantes décrivent les commandes CLI disponibles.The following sections outline the available CLI commands.
Initialiser LibMan dans le projetInitialize LibMan in the project
La libman init
commande crée un libman.jssur le fichier s’il n’en existe pas.The libman init
command creates a libman.json file if one doesn't exist. Le fichier est créé avec le contenu du modèle d’élément par défaut.The file is created with the default item template content.
SynopsisSynopsis
libman init [-d|--default-destination] [-p|--default-provider] [--verbosity]
libman init [-h|--help]
OptionsOptions
Les options suivantes sont disponibles pour la commande libman init
:The following options are available for the libman init
command:
-d|--default-destination <PATH>
Chemin d’accès relatif au dossier actif.A path relative to the current folder. Les fichiers de bibliothèque sont installés à cet emplacement si aucune
destination
propriété n’est définie pour une bibliothèque dans libman.jssur.Library files are installed in this location if nodestination
property is defined for a library in libman.json. La<PATH>
valeur est écrite dans ladefaultDestination
propriété de libman.js.The<PATH>
value is written to thedefaultDestination
property of libman.json.-p|--default-provider <PROVIDER>
Fournisseur à utiliser si aucun fournisseur n’est défini pour une bibliothèque donnée.The provider to use if no provider is defined for a given library. La
<PROVIDER>
valeur est écrite dans ladefaultProvider
propriété de libman.js.The<PROVIDER>
value is written to thedefaultProvider
property of libman.json. Remplacez<PROVIDER>
par l’une des valeurs suivantes :Replace<PROVIDER>
with one of the following values:cdnjs
filesystem
jsdelivr
unpkg
-h|--help
Affichez les informations d’aide.Show help information.
--verbosity <LEVEL>
Définissez le niveau de détail de la sortie.Set the verbosity of the output. Remplacez
<LEVEL>
par l’une des valeurs suivantes :Replace<LEVEL>
with one of the following values:quiet
normal
detailed
ExemplesExamples
Pour créer un libman.jssur un fichier dans un projet ASP.net Core :To create a libman.json file in an ASP.NET Core project:
Accédez à la racine du projet.Navigate to the project root.
Exécutez la commande suivante :Run the following command:
libman init
Tapez le nom du fournisseur par défaut ou appuyez sur
Enter
pour utiliser le fournisseur CDNJS par défaut.Type the name of the default provider, or pressEnter
to use the default CDNJS provider. Les valeurs valides sont les suivantes :Valid values include:cdnjs
filesystem
jsdelivr
unpkg
Un libman.jssur le fichier est ajouté à la racine du projet avec le contenu suivant :A libman.json file is added to the project root with the following content:
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": []
}
Ajouter des fichiers de bibliothèqueAdd library files
La libman install
commande télécharge et installe les fichiers de bibliothèque dans le projet.The libman install
command downloads and installs library files into the project. Un libman.jssur le fichier est ajouté s’il n’en existe pas.A libman.json file is added if one doesn't exist. La libman.jssur le fichier est modifiée pour stocker les détails de configuration des fichiers de la bibliothèque.The libman.json file is modified to store configuration details for the library files.
SynopsisSynopsis
libman install <LIBRARY> [-d|--destination] [--files] [-p|--provider] [--verbosity]
libman install [-h|--help]
ArgumentsArguments
LIBRARY
Nom de la bibliothèque à installer.The name of the library to install. Ce nom peut inclure la notation du numéro de version (par exemple, @1.2.0
).This name may include version number notation (for example, @1.2.0
).
OptionsOptions
Les options suivantes sont disponibles pour la commande libman install
:The following options are available for the libman install
command:
-d|--destination <PATH>
Emplacement d’installation de la bibliothèque.The location to install the library. S’il n’est pas spécifié, l’emplacement par défaut est utilisé.If not specified, the default location is used. Si aucune
defaultDestination
propriété n’est spécifiée dans libman.jssur, cette option est obligatoire.If nodefaultDestination
property is specified in libman.json, this option is required.--files <FILE>
Spécifiez le nom du fichier à installer à partir de la bibliothèque.Specify the name of the file to install from the library. S’il n’est pas spécifié, tous les fichiers de la bibliothèque sont installés.If not specified, all files from the library are installed. Fournissez une
--files
option par fichier à installer.Provide one--files
option per file to be installed. Les chemins d’accès relatifs sont également pris en charge.Relative paths are supported too. Par exemple :--files dist/browser/signalr.js
.For example:--files dist/browser/signalr.js
.-p|--provider <PROVIDER>
Nom du fournisseur à utiliser pour l’acquisition de la bibliothèque.The name of the provider to use for the library acquisition. Remplacez
<PROVIDER>
par l’une des valeurs suivantes :Replace<PROVIDER>
with one of the following values:cdnjs
filesystem
jsdelivr
unpkg
S’il n’est pas spécifié, la
defaultProvider
propriété de libman.jssur est utilisée.If not specified, thedefaultProvider
property in libman.json is used. Si aucunedefaultProvider
propriété n’est spécifiée dans libman.jssur, cette option est obligatoire.If nodefaultProvider
property is specified in libman.json, this option is required.
-h|--help
Affichez les informations d’aide.Show help information.
--verbosity <LEVEL>
Définissez le niveau de détail de la sortie.Set the verbosity of the output. Remplacez
<LEVEL>
par l’une des valeurs suivantes :Replace<LEVEL>
with one of the following values:quiet
normal
detailed
ExemplesExamples
Prenez en compte les libman.jssuivantes sur le fichier :Consider the following libman.json file:
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": []
}
Pour installer le fichier de jquery.min.js jQuery version 3.2.1 dans le dossier wwwroot/scripts/jQuery à l’aide du fournisseur CDNJS :To install the jQuery version 3.2.1 jquery.min.js file to the wwwroot/scripts/jquery folder using the CDNJS provider:
libman install jquery@3.2.1 --provider cdnjs --destination wwwroot/scripts/jquery --files jquery.min.js
Le libman.jssur le fichier ressemble à ce qui suit :The libman.json file resembles the following:
{
"version": "1.0",
"defaultProvider": "cdnjs",
"libraries": [
{
"library": "jquery@3.2.1",
"destination": "wwwroot/scripts/jquery",
"files": [
"jquery.min.js"
]
}
]
}
Pour installer les fichiers calendar.js et Calendar. CSS à partir de C : \ temp \ contosoCalendar \ à l’aide du fournisseur de système de fichiers :To install the calendar.js and calendar.css files from C:\temp\contosoCalendar\ using the file system provider:
libman install C:\temp\contosoCalendar\ --provider filesystem --files calendar.js --files calendar.css
L’invite suivante s’affiche pour deux raisons :The following prompt appears for two reasons:
- Le libman.jssur le fichier ne contient pas de
defaultDestination
propriété.The libman.json file doesn't contain adefaultDestination
property. - La
libman install
commande ne contient pas l'-d|--destination
option.Thelibman install
command doesn't contain the-d|--destination
option.
Après avoir accepté la destination par défaut, le libman.jssur le fichier ressemble à ce qui suit :After accepting the default destination, the libman.json file resembles the following:
{
"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"
]
}
]
}
Restaurer les fichiers de bibliothèqueRestore library files
La libman restore
commande installe les fichiers de bibliothèque définis dans libman.jssur.The libman restore
command installs library files defined in libman.json. Les règles suivantes s’appliquent :The following rules apply:
- S’il n’existe aucun libman.jssur le fichier dans la racine du projet, une erreur est retournée.If no libman.json file exists in the project root, an error is returned.
- Si une bibliothèque spécifie un fournisseur, la
defaultProvider
propriété de libman.jssur est ignorée.If a library specifies a provider, thedefaultProvider
property in libman.json is ignored. - Si une bibliothèque spécifie une destination, la
defaultDestination
propriété de libman.jssur est ignorée.If a library specifies a destination, thedefaultDestination
property in libman.json is ignored.
SynopsisSynopsis
libman restore [--verbosity]
libman restore [-h|--help]
OptionsOptions
Les options suivantes sont disponibles pour la commande libman restore
:The following options are available for the libman restore
command:
-h|--help
Affichez les informations d’aide.Show help information.
--verbosity <LEVEL>
Définissez le niveau de détail de la sortie.Set the verbosity of the output. Remplacez
<LEVEL>
par l’une des valeurs suivantes :Replace<LEVEL>
with one of the following values:quiet
normal
detailed
ExemplesExamples
Pour restaurer les fichiers de bibliothèque définis dans libman.jssur:To restore the library files defined in libman.json:
libman restore
Supprimer les fichiers de bibliothèqueDelete library files
La libman clean
commande supprime les fichiers de bibliothèque précédemment restaurés via LibMan.The libman clean
command deletes library files previously restored via LibMan. Dossiers qui deviennent vides après la suppression de cette opération.Folders that become empty after this operation are deleted. Les configurations associées aux fichiers de bibliothèque dans la libraries
propriété de libman.jssur ne sont pas supprimées.The library files' associated configurations in the libraries
property of libman.json aren't removed.
SynopsisSynopsis
libman clean [--verbosity]
libman clean [-h|--help]
OptionsOptions
Les options suivantes sont disponibles pour la commande libman clean
:The following options are available for the libman clean
command:
-h|--help
Affichez les informations d’aide.Show help information.
--verbosity <LEVEL>
Définissez le niveau de détail de la sortie.Set the verbosity of the output. Remplacez
<LEVEL>
par l’une des valeurs suivantes :Replace<LEVEL>
with one of the following values:quiet
normal
detailed
ExemplesExamples
Pour supprimer les fichiers de bibliothèque installés via LibMan :To delete library files installed via LibMan:
libman clean
Désinstaller les fichiers de bibliothèqueUninstall library files
libman uninstall
Commande :The libman uninstall
command:
- Supprime de la destination tous les fichiers associés à la bibliothèque spécifiée dans libman.js.Deletes all files associated with the specified library from the destination in libman.json.
- Supprime la configuration de bibliothèque associée de libman.js.Removes the associated library configuration from libman.json.
Une erreur se produit dans les cas suivants :An error occurs when:
- Il n’existe aucun libman.jssur le fichier dans la racine du projet.No libman.json file exists in the project root.
- La bibliothèque spécifiée n’existe pas.The specified library doesn't exist.
Si plusieurs bibliothèques portant le même nom sont installées, vous êtes invité à en choisir une.If more than one library with the same name is installed, you're prompted to choose one.
SynopsisSynopsis
libman uninstall <LIBRARY> [--verbosity]
libman uninstall [-h|--help]
ArgumentsArguments
LIBRARY
Nom de la bibliothèque à désinstaller.The name of the library to uninstall. Ce nom peut inclure la notation du numéro de version (par exemple, @1.2.0
).This name may include version number notation (for example, @1.2.0
).
OptionsOptions
Les options suivantes sont disponibles pour la commande libman uninstall
:The following options are available for the libman uninstall
command:
-h|--help
Affichez les informations d’aide.Show help information.
--verbosity <LEVEL>
Définissez le niveau de détail de la sortie.Set the verbosity of the output. Remplacez
<LEVEL>
par l’une des valeurs suivantes :Replace<LEVEL>
with one of the following values:quiet
normal
detailed
ExemplesExamples
Prenez en compte les libman.jssuivantes sur le fichier :Consider the following libman.json file:
{
"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/"
}
]
}
Pour désinstaller jQuery, l’une des commandes suivantes est réussie :To uninstall jQuery, either of the following commands succeed:
libman uninstall jquery
libman uninstall jquery@3.3.1
Pour désinstaller les fichiers Lodash installés via le
filesystem
fournisseur :To uninstall the Lodash files installed via thefilesystem
provider:libman uninstall C:\temp\lodash\
Version de la bibliothèque de mises à jourUpdate library version
La libman update
commande met à jour une bibliothèque installée via LibMan avec la version spécifiée.The libman update
command updates a library installed via LibMan to the specified version.
Une erreur se produit dans les cas suivants :An error occurs when:
- Il n’existe aucun libman.jssur le fichier dans la racine du projet.No libman.json file exists in the project root.
- La bibliothèque spécifiée n’existe pas.The specified library doesn't exist.
Si plusieurs bibliothèques portant le même nom sont installées, vous êtes invité à en choisir une.If more than one library with the same name is installed, you're prompted to choose one.
SynopsisSynopsis
libman update <LIBRARY> [-pre] [--to] [--verbosity]
libman update [-h|--help]
ArgumentsArguments
LIBRARY
Nom de la bibliothèque à mettre à jour.The name of the library to update.
OptionsOptions
Les options suivantes sont disponibles pour la commande libman update
:The following options are available for the libman update
command:
-pre
Obtenez la dernière version préliminaire de la bibliothèque.Obtain the latest prerelease version of the library.
--to <VERSION>
Obtenez une version spécifique de la bibliothèque.Obtain a specific version of the library.
-h|--help
Affichez les informations d’aide.Show help information.
--verbosity <LEVEL>
Définissez le niveau de détail de la sortie.Set the verbosity of the output. Remplacez
<LEVEL>
par l’une des valeurs suivantes :Replace<LEVEL>
with one of the following values:quiet
normal
detailed
ExemplesExamples
Pour mettre à jour jQuery vers la dernière version :To update jQuery to the latest version:
libman update jquery
Pour mettre à jour jQuery vers la version 3.3.1 :To update jQuery to version 3.3.1:
libman update jquery --to 3.3.1
Pour mettre à jour jQuery vers la dernière version préliminaire :To update jQuery to the latest prerelease version:
libman update jquery -pre
Gérer le cache de bibliothèqueManage library cache
La libman cache
commande gère le cache de la bibliothèque LibMan.The libman cache
command manages the LibMan library cache. Le filesystem
fournisseur n’utilise pas le cache de bibliothèque.The filesystem
provider doesn't use the library cache.
SynopsisSynopsis
libman cache clean [<PROVIDER>] [--verbosity]
libman cache list [--files] [--libraries] [--verbosity]
libman cache [-h|--help]
ArgumentsArguments
PROVIDER
Utilisé uniquement avec la clean
commande.Only used with the clean
command. Spécifie le cache du fournisseur à nettoyer.Specifies the provider cache to clean. Les valeurs valides sont les suivantes :Valid values include:
cdnjs
filesystem
jsdelivr
unpkg
OptionsOptions
Les options suivantes sont disponibles pour la commande libman cache
:The following options are available for the libman cache
command:
--files
Répertoriez les noms des fichiers qui sont mis en cache.List the names of files that are cached.
--libraries
Répertoriez les noms des bibliothèques mises en cache.List the names of libraries that are cached.
-h|--help
Affichez les informations d’aide.Show help information.
--verbosity <LEVEL>
Définissez le niveau de détail de la sortie.Set the verbosity of the output. Remplacez
<LEVEL>
par l’une des valeurs suivantes :Replace<LEVEL>
with one of the following values:quiet
normal
detailed
ExemplesExamples
Pour afficher les noms des bibliothèques mises en cache par fournisseur, utilisez l’une des commandes suivantes :To view the names of cached libraries per provider, use one of the following commands:
libman cache list
libman cache list --libraries
Une sortie similaire à la suivante s’affiche à l’écran :Output similar to the following is displayed:
Cache contents: --------------- unpkg: knockout react vue cdnjs: font-awesome jquery knockout lodash.js react
Pour afficher les noms des fichiers de bibliothèque mis en cache par fournisseur :To view the names of cached library files per provider:
libman cache list --files
Une sortie similaire à la suivante s’affiche à l’écran :Output similar to the following is displayed:
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
Notez que la sortie précédente montre que les versions 3.2.1 et 3.3.1 de jQuery sont mises en cache sous le fournisseur CDNJS.Notice the preceding output shows that jQuery versions 3.2.1 and 3.3.1 are cached under the CDNJS provider.
Pour vider le cache de bibliothèque pour le fournisseur CDNJS :To empty the library cache for the CDNJS provider:
libman cache clean cdnjs
Une fois le cache du fournisseur CDNJS vidé, la
libman cache list
commande affiche ce qui suit :After emptying the CDNJS provider cache, thelibman cache list
command displays the following:Cache contents: --------------- unpkg: knockout react vue cdnjs: (empty)
Pour vider le cache pour tous les fournisseurs pris en charge :To empty the cache for all supported providers:
libman cache clean
Après avoir vidé tous les caches de fournisseur, la
libman cache list
commande affiche ce qui suit :After emptying all provider caches, thelibman cache list
command displays the following:Cache contents: --------------- unpkg: (empty) cdnjs: (empty)