Search code examples
.net-corenugetazure-devopsazure-pipelines-build-taskazure-devops-extensions

How to install and use dotnet core tool (CLI) in Azure Pipelines (VSTS) Build Task?


I want to create custom build task, that would do invoke dotnet core CLI tool. I've used VSTS DevOps Task SDK/node to get or install the tool:

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);
}

However, when I use the tool in Build Pipeline: enter image description here

I'm getting following error:

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.

It look like when I install .NET Core SDK in the pipleline, it is unable to find the dotnet tool

Question:

How do I install and then safely use the dotnet core tool? Is the any way to workaround following?

Since you just installed the .NET Core SDK, you will need to reopen the Command Prompt window before running the tool you installed


Solution

  • There isn't any workaround to avoid reopening the CMD as far as I know.

    To get it work, you could specify the install path when installing the package and then call the full path to the liman.exe. Or if you want to install it globally with "-g", then the path to the liman.exe should be "%USERPROFILE%\.dotnet\tools\liman.exe".