Why does my dotnet tool run when installed locally, but not when installed globally?

553 Views Asked by At

I've written a dotnet tool following the documentation, targeting .NET 6.

I can install and run it as a local tool. It works fine.

I can install it as a global tool also, but when I run it, the executable acts like no version of .NET runtime is installed.

Here's the exerpt from my csproj:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>net6.0</TargetFramework>
    <PackAsTool>true</PackAsTool>
    <ToolCommandName>mytool</ToolCommandName>
    <PackageId>$(MSBuildProjectName)</PackageId>
    <AssemblyName>mytool</AssemblyName>

I can install it and run it fine as a local tool:

user@computer:~$ dotnet new tool-manifest
The template "Dotnet local tool manifest file" was created successfully.

user@computer:~$ dotnet tool install my.package.mytool --prerelease
You can invoke the tool from this directory using the following commands: 'dotnet tool run mytool' or 'dotnet mytool'.

user@computer:~$ dotnet mytool
[hello world, etc etc]

If I instead try to use it as a global tool (assuming I uninstalled the local version first)

user@computer:~$ dotnet tool install -g my.package.mytool
You can invoke the tool using the following command: mytool

it installs fine, but when I try to run it, it acts like .NET is not even installed.

user@COMPUTER:~$ mytool
You must install .NET to run this application.

App: /home/user/.dotnet/tools/mytool
Architecture: x64
App host version: 7.0.1
.NET location: Not found

Learn about runtime installation:
https://aka.ms/dotnet/app-launch-failed

Download the .NET runtime:
https://aka.ms/dotnet-core-applaunch?missing_runtime=true&arch=x64&rid=linuxmint.21.1-x64&apphost_version=7.0.1

I'm certain that it is installed correctly (I can find the file). I'm certain that the application can run, since it works as a local tool.

I have both .NET 6 and .NET 7 runtimes installed:

user@computer:~$ dotnet --list-runtimes
Microsoft.AspNetCore.App 6.0.12 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.AspNetCore.App 7.0.1 [/usr/share/dotnet/shared/Microsoft.AspNetCore.App]
Microsoft.NETCore.App 6.0.12 [/usr/share/dotnet/shared/Microsoft.NETCore.App]
Microsoft.NETCore.App 7.0.1 [/usr/share/dotnet/shared/Microsoft.NETCore.App]

So, why can the tool not run as a global tool? Have I targeted an inappropriate framework? Built with the wrong SDK? Invoked with the wrong runtime?

1

There are 1 best solutions below

3
On BEST ANSWER

Turns out the DOTNET_ROOT environment variable was misconfigured, due to me installing the SDK from the Debian repository initially, then (when .NET 7 was released) uninstalling from debian and using Microsoft's PPA.