One thing thatโ€™s more esoteric than it should be is how to create a good command-line application on macOS, or at least it is for the languages I know, which donโ€™t [really] include C.
 
I did briefly consider writing it in Swift, but it turns out C# is pretty easy but only if you know the right incantation. The key was finding the term `dotnet publish` (a link to which I found here). But then I needed a little more help to know the precise (or at least one precise) string of characters:

When you invoke the dotnet publish command it should end up being similar to the following:

$ dotnet publish -r osx.10.13-x64 /p:PublishSingleFile=true
Microsoft (R) Build Engine version 16.4.0+e901037fe for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.

  Restore completed in 39.77 ms for /usr/local/share/dotnet/myApp/myApp.csproj.
  myApp -> /usr/local/share/dotnet/myApp/bin/Debug/netcoreapp3.1/osx.10.13-x64/myApp.dll
  myApp -> /usr/local/share/dotnet/myApp/bin/Debug/netcoreapp3.1/osx.10.13-x64/publish/

Thank heavens. Thanks again, random StackOverflow answerer.

In case you missed it, that means you type this:

dotnet publish -r osx.10.13-x64 /p:PublishSingleFile=true

...in the same directory as your sln file and then you call the exe that you created (almost certainly without the exe extension) from the publish folder:

/usr/local/share/dotnet/myApp/bin/Debug/netcoreapp3.1/osx.10.13-x64/publish/myApp

And now you've got a self-contained, macOS specific executable.

(I'm doing this to see how much trouble it'd be to write a macOS version of the Chutzpah JavaScript test runner on macOS. The VS Code extension is cross platform, almost by accident, but there's no equivalent for the "real" Windows version of Chutzpah exe that the extension, itself simply a pass-through runner, must call. Shouldn't be tough to recreate, though, at least for the "80%" use cases.)

Labels: , , ,