.Net Core Global Tools: A fresh start for distributing command line apps in dotnet
TL;DR: The Microsoft ecosystem now allows easy distribution of .net core tools with a npm-style approach.
Recently I have been revamping a pet project of mine that is a dotnet cli application. Previously, it was quite pain to roll it out new versions in any machine I wanted to use it.
Using the dotnet cli extensibility model, I had to add a reference to it inside a project file (.csproj) to use it in that project’s context. Or had to download it and add its path to the PATH environment, so I could use it across the machine. So technically, it was a bit of a faff.
Now, with .Net Core Global tools, you can deploy CLI apps in the same way as you can do with npm for NodeJs applications. A single command allows you to download and install compatible applications:
dotnet tool install -g NugetPackageName
Note that, this is only supported on .Net Core SDK 2.1.300 and above. Therefore, make sure you have that in your machine before trying it. ;)
Producing your own Global Tool
To make your console applications compatible, you need to add the entry <IsTool>true</IsTool> in your .csproj. It is also important that you target netcoreapp2.1 and above.
You could test it locally by:
dotnet pack src\dotnet-ildasm\dotnet-ildasm.csproj -c Debugdotnet tool install -g dotnet-ildasm --add-source C:\git\dotnet-ildasm\src\dotnet-ildasm\bin\Debug\
Or getting a specific version from an alternative nuget feed:
dotnet tool install -g dotnet-ildasm --version 0.9.1-beta-build-0005 --add-source https://www.myget.org/F/pjbgf/api/v3/index.json
Wrapping up….
As everything, there are down sides to it. For example, this feature is a breaking change on .Net Core, so by default you won’t be able to target multiples framework when compiling.
However, we now got a really easy way to create and distribute cli tools, which should help with the growth of .net apps in that space.