This repository demonstrates developing a CLI-based hello world console app with .NET 5.0 using VS Code and Development Containers.
With Temninal:
#!/bin/zsh
# Greet someone
hwld greet -n "Angry Haslett"
# > Hello Angry Haslett!
#!/bin/zsh
# Say something to echo
hwld echo -m "Sad Lamarr" -t 2
# > Starting to Sad Lamarr 2 times ...
# > Sad Lamarr for the 1 time ...
# > Sad Lamarr for the 2 time ...
- Uses .NET 5.0 development container found in @kosalanuwan/devcontainers
- Uses Microsoft.Extensions.Hosting package for Generic Hosting and Dependency Injection
- Uses System.CommandLine package for CLI options, args, and commands
- Configured to build and run from the VS Code tasks
If you want to understand how development containers work or want to build your own development container, you want to have a look at the dev container page for full-blown instructions.
First, you want to fork or clone the repo locally, then open up the source code in VS Code.
#!/bin/zsh
gh repo clone kosalanuwan/vscode-remote-try-cli
cd vscode-remote-try-cli && code .
Then, re-open the source in the development container to install minimal runtime tools, plugins, extensions et al.
With VS Code:
- Run task:
Reopen in Container
- Run task:
build
to clean, restore, and build the project - Run task:
watch
to run project in watch mode
#!/bin/zsh
# Greet someone
dotnet watch --project Cli/HelloWorld.Cli.csproj run greet -n "Angry Haslett"
# Say something to echo
dotnet watch --project Cli/HelloWorld.Cli.csproj run echo -m "Sad Lamarr" -t 2
Occasionally, you will want to repeat below steps to create a console project, add dependencies, and write your own CLI tool.
With VS Code:
#!/bin/zsh
# Create a new console project
dotnet new console -n Weather.Cli -o Cli
#!/bin/zsh
# Create a new solution to add the project
dotnet new sln -n Cli
dotnet sln add Cli/
#!/bin/zsh
# Add useful dependencies
dotnet add Cli/ package Microsoft.Extensions.Hosting --prerelease
dotnet add Cli/ package System.CommandLine --prerelease
#!/bin/zsh
# Run in watch mode
dotnet watch --project Cli/Weather.Cli.csproj run
- @dotnet/command-line-api for implemnting commands and args
- A flavor of Carmel Eve's DI approach using the Genric Host.
If you have any technical problems with VS Code or Development Containers, you are better off asking VS Code Support directly, since you'll end up getting a much faster response back that way.
The official repo to contribute would be @microsoft/vscode-dev-containers.
Have a suggestion or a bug fix? Just open a pull request or an issue. Include the development container with a clear folder name and the simplest instructions possible.
The source code is license under the MIT