This repo is a template for the .NET SDK to make a slightly more batteries included console csproj, subject to my preferences.
This is a companion to A Beginner's Guide to .NET's HostBuilder.
Here are the steps in bash:
template_dir=~/.dotnetTemplates/SawyerCSharpConsole
git clone https://github.com/sawyerwatts/SawyerCSharpConsole.git $template_dir
rm -rf $template_dir/.git
rm $template_dir/.gitignore
rm $template_dir/.editorconfig
rm $template_dir/README.md
rm $template_dir/LICENSE
dotnet new install $template_dir
Here are the steps in PowerShell:
$templateDir="$env:USERPROFILE\.dotnetTemplates\SawyerCSharpConsole"
git clone https://github.com/sawyerwatts/SawyerCSharpConsole.git $templateDir
rm $templateDir\.git -r -force
rm $templateDir\.gitignore
rm $templateDir\.editorconfig
rm $templateDir\README.md
rm $templateDir\LICENSE
dotnet new install $templateDir
Here are the steps in bash:
template_dir=~/.dotnetTemplates/SawyerCSharpConsole
dotnet new uninstall $template_dir
rm -rf $template_dir
Here are the steps in PowerShell:
$templateDir="$env:USERPROFILE\.dotnetTemplates\SawyerCSharpConsole"
dotnet new uninstall $templateDir
rm $templateDir -r -force
- This uses the
Worker
SDK, so it has access to theHostApplicationBuilder
, allowing easy dependency injection and access to theappsettings*.json
files. - This comes pre-baked with Serilog configured as the implementation to the
built in
ILogger<T>
, and these settings are controlled via theappsettings*.json
files. Serilog is configured to buffer file writes and to write file and console logs via a background thread. Program
supplies aCancellationToken
toDriver.RunAsync
, and it will mimic the functionality that the various web/app hosts supply when managing long-running applications: interrupt signals are captured by the host, the host will update theCancellationToken
so the app can gracefully shut down, and if the app doesn't close in five seconds, then the app will be forcefully closed.Driver
hasSettings
andRegisterTo
, an easy reminder how to best register settings POCOs with validation on startup.