C
C#3y ago
Thinker

Publishing a CLI tool as a single-file app

So I've made a CLI tool (see #showcase) which I would sort of like to be able to distribute without requiring the .NET SDK for people to manually build and install it themselves. I know you can publish projects as single-file distributable applications, although is this possible to do with a CLI tool, or would you have to package it with some kind of installer?
44 Replies
Thinker
ThinkerOP3y ago
Obviously I could just tell people to add it to their PATH themselves, although that sounds kind of dumb.
Angius
Angius3y ago
Single-file self-contained just get released as a single binary So you end up with tool.exe for example
Thinker
ThinkerOP3y ago
yeah that sounds good
Angius
Angius3y ago
No need for any installers or anything. The user can just download the zip, unzip it wherever, and use it just like that
Thinker
ThinkerOP3y ago
Except I would kind of like for users to not have to add it to their PATH themselves The "installation" would just be doing that
Angius
Angius3y ago
That would need an installer of some sort then, yeah Or the tool itself can have some function like that The user can run C:/Whatever/SomeLocation/tool.exe addpath which will add it to PATH, and from then on they can just call it with tool Although setting PATH with C# is wonky IME
Thinker
ThinkerOP3y ago
Didn't know that, that's neat
Angius
Angius3y ago
Well, it's just a suggestion, not a built-in feature lol Something you'd have to make yourself
Thinker
ThinkerOP3y ago
Okay so easiest would just be to publish it as a single-file, then have users manually add it to their PATH
Angius
Angius3y ago
Probably, yeah
Thinker
ThinkerOP3y ago
sounds reasonable I don't really wanna have to make an installer for this or anything
Mayor McCheese
Consider adding a help message for how to add it to the path
Thinker
ThinkerOP3y ago
welp, too late now >_>
mtreit
mtreit3y ago
Is "dotnet tool install" something anyone can publish for? That's the best end-user experience I've seen for installing CLI tools
Thinker
ThinkerOP3y ago
Well you need the .NET SDK to do that
mtreit
mtreit3y ago
<:PES_SadGe:814280618959568896>
realivanjxツ
realivanjxツ3y ago
you dont enable native aot for this tool? im curious abt the output size with native aot enabled
Thinker
ThinkerOP3y ago
eh, I could, but it's not that important it's only 58mb (which I don't think is that big...?)
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
mtreit
mtreit3y ago
Oh dear winget is nice maybe things will improve in the future
Thinker
ThinkerOP3y ago
As a conclusion, I think the thing I've come up with is that I'm gonna have an install command for my tool which adds the directory to the user's PATH, plus this also lets me set up additional configuration and stuff.
Mayor McCheese
so portable by default or install is required?
Thinker
ThinkerOP3y ago
wdym?
Mayor McCheese
Do I need to install to use the tool or can I just set directory and go
Thinker
ThinkerOP3y ago
rn you can plop the exe inside a directory, add it to your path and go I kinda wanna keep it like that, although it unfortunately means I can't do configuration or anything
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Thinker
ThinkerOP3y ago
Well my current setup is this 1. Download latest release from my repo to some directory 2. Open directory in terminal 3. Run ./folder install Which works decently enough imo I've never used Winget so idk how to use it really although to be fair this is kind of risky
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Thinker
ThinkerOP3y ago
hmmmmm
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Thinker
ThinkerOP3y ago
The options I see are kind of these - No automatic installation, user has to manually add executable to PATH - Use install command (bad because running it from literally anywhere would add the current directory to PATH) - Create some kind of an installer, no idea how to do this
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Thinker
ThinkerOP3y ago
It just runs dotnet restore + build + pack + tool install
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Thinker
ThinkerOP3y ago
I mean it's just for a local install so I don't have to run the command(s) manually I could upload it to Nuget I had an idea briefly to create an installer which fetches the latest release from the Github repo, although I'm fairly sure that'd run into multiple issues. Mainly how to get the executable for the correct architecture I mean it could work, although it feels like a hack
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Thinker
ThinkerOP3y ago
I don't really know how you'd automatically create an installer like that. Does the installer contain the executable itself?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Thinker
ThinkerOP3y ago
How do you include the program? as an embedded resource? actually you know what, i kind of see how you'd do that
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Thinker
ThinkerOP3y ago
mind sharing this script?
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View
Thinker
ThinkerOP3y ago
also i have to go to sleep, but i'll be back to check this out later
Unknown User
Unknown User3y ago
Message Not Public
Sign In & Join Server To View

Did you find this page helpful?