Skip to content

Sample hello-world CLI project in .NET 6.0 for trying out VS Code Remote - Containers

License

Notifications You must be signed in to change notification settings

kosperera/vscode-remote-try-cli

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

26 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Try out CLI-based console app (C#)

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 ...

What's included:

Quick Start

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.

Build and run from source

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

Useful Commands

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

Related Projects

Feedback

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.

Contributing

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.

License

The source code is license under the MIT