question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

dotnet tool install should return exit code 0 if tool is already installed

See original GitHub issue

I’m trying to write a script that will install global tools if necessary. I would like to just run “dotnet tool install”, but this returns exit code 0 if the tool is already present, so I have to first execute dotnet tool list and grep the output.

Expected behavior

Calling dotnet tool install should no-op AND exit code 0 if the tool is already installed

Actual behavior

Running dotnet tool install twice fails scripts because the second time it runs it will exit code 0

PS> & dotnet tool install --tool-path "$(pwd)/.tools" sleet --version 2.3.25 --add-source https://api.nuget.org/v3/index.json
You can invoke the tool using the following command: sleet
Tool 'sleet' (version '2.3.25') was successfully installed.
PS> $lastexitcode
0
PS>  & dotnet tool install --tool-path "$(pwd)/.tools" sleet --version 2.3.25 --add-source https://api.nuget.org/v3/index.json
Tool 'sleet' is already installed.
PS>  $lastexitcode
1

The result of this is that I have write more complicate code like this:

if (& $dotnet tool list --tool-path "$PSScriptRoot/.tools" | Select-String "sleet") {
    Write-Host -f Yellow 'Skipping install of sleet. It''s already installed'
}
else {
    Invoke-Block { & $dotnet tool install --tool-path "$PSScriptRoot/.tools" sleet --version 2.3.25 --add-source https://api.nuget.org/v3/index.json }
}

Environment data

dotnet --info output:

.NET Core SDK (reflecting any global.json):
 Version:   2.1.300
 Commit:    adab45bf0c

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.17134
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\dev\aspnet\Universe20\.dotnet\sdk\2.1.300\

Host (useful for support):
  Version: 2.1.0
  Commit:  caa7b7e2ba

.NET Core SDKs installed:
  2.1.300 [C:\dev\aspnet\Universe20\.dotnet\sdk]

.NET Core runtimes installed:
  Microsoft.AspNetCore.All 2.1.0 [C:\dev\aspnet\Universe20\.dotnet\shared\Microsoft.AspNetCore.All]
  Microsoft.AspNetCore.App 2.1.0 [C:\dev\aspnet\Universe20\.dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 2.1.0 [C:\dev\aspnet\Universe20\.dotnet\shared\Microsoft.NETCore.App]

Issue Analytics

  • State:open
  • Created 5 years ago
  • Reactions:67
  • Comments:42 (6 by maintainers)

github_iconTop GitHub Comments

43reactions
tmdscommented, Jun 14, 2018

npm install returns 1 when it can’t change to the specified version. npm install returns 0 when the version is already installed.

npm install without a version specified will update to the latest version when the package is already installed.

This matches my expectations as a user.

37reactions
cottsakcommented, Jan 30, 2019

@KathleenDollard It’s not a “bad” choice. But IMO, it’s less than ideal. When scripting something it would be great to simply use dotnet install as an idempotent command meaning that it will implicitly “install” if not present, or return 0 if it’s already installed. It just makes life easier, and seems to be an established convention.

Read more comments on GitHub >

github_iconTop Results From Across the Web

Installing .NET Core tools: Preventing errors in your Azure ...
At least it will return an exit code of 0 and we can move along. If you run the command again, the tool...
Read more >
`dotnet tool install` returns error code 1 when tool is ...
The main scenario that requires an exit code being 0 is to ensure a tool is present on a machine and it is...
Read more >
How to ensure a "dotnet tool" is installed in an Azure ...
Try running the script as dotnet tool update dotnet-project-licenses -g. If the tool isn't installed this command should install it, and if ......
Read more >
Troubleshoot .NET tool usage issues
Discover the common issues when running .NET tools and possible solutions.
Read more >
Install .NET on Windows
The installer returns an exit code of 0 for success and an exit code of 3010 to indicate that a restart is required....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found