.Net Core is a powerful tool, but have some limitations, one of them is that ProcessStartInfo over macOS workingDirectory not work and over Windows required credentials in order to create a new terminal.
But you can save the day, using the good parts of ProcessStartInfo as a bridge and call external scripts that can do the job (even without credentials).
Easy Way (Recommended)
I have created ToolBox library, that includes this functionality.
Uses a NotificationSystem by Default, but you can customize it implementing the INotificationSystem interface and send it as a parameter on ShellConfigurator.
To understand how this library works, take a look inside the Sample folder. Better easy to use a guide than words.
Hard Way
In the root project folder, create two scripts (Batch and Bash) that can receive a command and a directory (optional). Internally they will do the job to create the external terminal in a new window:
Bat file for Windows:
Bash file for macOS:
Remember assign execution permissions to this file: chmod +x cmd.mac.sh
Add a better .Net Core OS detection with this class:
Use ProcessStartInfo but understand his limitations. This Class can run command Hidden (run command in the background), Internal (run commands and show stdout and stderr in the same terminal) and External (run commands in external terminal).
Remember add this tags on .csproj file, to copy script file when Publish your project:
Usage (magic comes true)
Term function always returns a Response class with code, stdout and stderr.
Hidden
You can run a command silently. Don’t show anything on console, if you want to print the result, use values on Response return.
Internal
You can run a command and see the result on the same terminal.
External
gulp browserSync needs to stay open in order to have the “web Server” running. This is the main reason to run it in an external window.
Gulp project path is different between Windows and macOS, then I think the better approach is to create an Environment Variable called GULP_PROJECT.
Another use is if you need to run a simultaneous process at the same time, open each one in a new terminal and will don’t need to wait until finish one to run the next one.
Conclusions
Why is better the Easy Way?
Because you don’t need to deal with files, script permission, and project build configuration; NuGet package does it all for you. Plus you can create another shell implementing IBridge (like Zsh, PowerShell, etc) interface and use it on ShellConfigurator as a parameter and… ToolBox library comes with utilities like: command line, files, log, platform, system, transform and validation.
Hard way is good as a study case or if you want a better understanding of how it works, but you will deal with manually with file permission and believe you don’t want and end-user running additional commands. Finally… was not develop using polymorphism, then you will have to deal manually with new additions.
Bonus Track
Take a look inside this library, it's not only to launch external commands:
Top comments (2)
why the GetFileName in Shell class don't have a return statement?
Fixed! Thanks!