This is a template for console applications.
- Clone this repository.
- Delete the
.git
folder from your local copy (it is a hidden folder in the root of the repo). - Rename
ConsoleAppTemplate
with the new project name in all files, you can useReplace in All files
editor command. - Add logic to the
\Workers\MainWorker.cs
file in theMain
method. - Rewrite this
README.md
file content and remove this section. - Edit the documentation in
/docs/
folder.
- Dependency injection.
- Asynchronous and object oriented (testable)
Program.cs
class. - Logging with
Microsoft.Extensions.Logging
and NLog. - Configuration in
AppSettings.json
usingMicrosoft.Extensions.Configuration
. - Configuration validation with
DataAnnotations
. - Documentation template in
/docs
folder andREADME.md
. - Unit Test project template with
XUnit
,FluentAssertions
,AutoFixture
andNSubstitute
(can be replaced byMoq
if preferred).
- Download the latest binaries from the releases section on GitHub.
- Or alternatively compile the project yourself by cloning this repo, optionally use the
/scripts/Build.ps1
.
Can be done in 2 ways (in order of preference):
- From the
command-line
parameters during the app invocation. - Editing
AppSettings.json
file before running the tool.
The available parameters (case-in-sensitive) are:
--Help
: Display help: config and list of commands.--Version
: Display the version number.-U
,-Url
--SomeConfigSection:SomeUrl
: Optional. Some URL.--SomeConfigSection:SomeName
: Optional. Some name.
...
Config parameters can be set from the command line arguments as supported by
dotnet's Microsoft logging.
Examples for the PowerShell console:
# Example with full param names:
.\ConsoleAppTemplate.exe -SomeConfigSection:SomeUrl "someurl.com" --SomeConfigSection:SomeName "Some Name"
# Example with short param names:
.\ConsoleAppTemplate.exe -U "someurl.com" -N "Some Name"
# Example with full-path and start-process (opens in a new cmd window):
Start "C:\ConsoleAppTemplate.exe" -ArgumentList '-U "someurl.com" --N "Some Name" '
Edit the optional AppSettings.json
file located in the same folder as the app's executable, before running the app.
These settings will be taken as the default values when a parameter is not specified.
Example:
{
"SomeConfigSection": {
"SomeUrl": "https://some-example.com",
"SomeName": "Peter",
}
}