如何在Azure Pipelines(VSTS)生成任务中安装和使用dotnet核心工具(CLI)?

时间:2018-10-01 07:52:35

标签: .net-core nuget azure-devops azure-pipelines-build-task azure-devops-extensions

我想创建自定义构建任务,该任务确实会调用dotnet核心CLI工具。我已经使用VSTS DevOps Task SDK/node来获取或安装该工具:

import tl = require('vsts-task-lib/task');

async function getLibmanTool() {
    let libmanExePath = tl.which('libman');
    if (!libmanExePath){
        console.log("Libman CLI not found. Installing..")
        var dotnet = tl.tool(tl.which('dotnet', true));
        await dotnet.arg(['tool', 'install', '-g', 'Microsoft.Web.LibraryManager.Cli']).exec();
    }
    libmanExePath = tl.which('libman', true); //this line throws, see output
    return tl.tool(libmanExePath);
}

但是,当我在“构建管道”中使用该工具时: enter image description here

我遇到以下错误:

Libman CLI not found. Installing..
[command]C:\hostedtoolcache\windows\dncs\2.1.105\x64\dotnet.exe tool install -g Microsoft.Web.LibraryManager.Cli
Since you just installed the .NET Core SDK, you will need to reopen the Command Prompt window before running the tool you installed.
You can invoke the tool using the following command: libman
Tool 'microsoft.web.librarymanager.cli' (version '1.0.163') was successfully installed.
##[error]Unable to locate executable file: 'libman'. Please verify either the file path exists or the file can be found within a directory specified by the PATH environment variable. Also verify the file has a valid extension for an executable file.

当我在pipleline中安装.NET Core SDK时,似乎找不到dotnet工具

问题:

如何安装然后安全使用dotnet core工具?有什么解决方法吗?

  

由于您刚刚安装了.NET Core SDK,因此在运行安装的工具之前,您需要重新打开“命令提示符”窗口

1 个答案:

答案 0 :(得分:0)

据我所知,没有任何解决方法可以避免重新打开CMD。

要使其正常运行,可以在安装软件包时指定安装路径,然后调用liman.exe的完整路径。或者,如果要使用“ -g”全局安装,则liman.exe的路径应为“ {%USERPROFILE%\.dotnet\tools\liman.exe”。