To see the help message outputed by the command line, run: dotnet run --project SES.ConsoleApplication\ -- echo -h
- Project template settings are found in the
.template.configfolder - Make sure
appsettings.jsonfile is set to "Copy to output directory"- It will end up in the same directory as the exe
- To set the environment value at the command line, use:
dotnet run --environment Production// Other values are Staging, Development
- TODO: Setup launchSettings.json
dotnet run --launch-pofile <NAME>or use-lp- This file located in the project Properties folder
When running a command with a bool? param = null (i.e. a nullable value), only the parameter key is needed. i.e. command-name --param or command-name -p. (Using command-name -p true will cause the command to fail).
In the directory that contains the .template.config folder, run:
dotnet new install . or dotnet new install . --force (If the template already exists)
To use the installed template to create a new project, you can then run:
dotnet new sesconsole in a new folder. The name of the folder will dictate the project name. Or use dotnet new sesconsole -n <project name> to specify the project name
Alternately, you can also pick the sesconsole template from Rider
NOTE: (2025-03-09) neuecc recommends not using ConsoleApp.Log() and ConsoleApp.LogError() in typical applications.
(The context for ConsoleApp.Log... is "Program", which matters if you want to control the log level from appsettings.json)
Or call the service provider ConsoleApp.ServiceProvider:
public static class StaticExample
{
public static void Log(string msg)
{
if (ConsoleApp.ServiceProvider != null)
{
// Using ConsoleApp.Log...
ConsoleApp.LogError(msg); // Can log anywhere, even in static classes!!
// Using ConsoleApp.ServiceProvider
var logFactory = ConsoleApp.ServiceProvider.GetService<ILoggerFactory>();
var logger = logFactory.CreateLogger("StaticLogger");
logger.ZLogInformation($"Logging an information message from a static class using the service provider.");
}
}
}NOTE: All logs are written to the logs folder.
The option classes must end with the word "Option"
Filters can be attached globally, to specific classes, or specific methods using UseFilter<T> or [ConsoleAppFilter<T>].
You can override the exit code using filters. You can share information between commands and filters, and between multiple different filters.
ConsoleAppFramework supports attribute based parameter validation.
Run the publish.cmd command.
If you want to change the exe name, update the publish.cmd file with: -p:AssemblyName=YourDesiredExeName e.g. dotnet publish -c Release -p:AssemblyName=YourDesiredExeName
The project includes several utility CMD scripts in the root directory to simplify common tasks:
| Script | Description |
|---|---|
setup.cmd |
Initializes a new project after template creation. Creates git repository and necessary directory structure. Automatically executed as a post-action when creating a new project from the template. |
publish.cmd |
Publishes the application as a self-contained executable. Use this to create a distributable version of your application. |
create_template.cmd |
Utility for template developers to update or regenerate template files. |
consolidate_readmes.cmd |
Collects all README.md and README.txt files from the entire project into a single READMES directory. Useful for documentation overview and review. READMES folder is excluded from git |
- Publishing your application: Run
publish.cmdto create a self-contained executable - Consolidating documentation: Run
consolidate_readmes.cmdto collect all README files into the READMES directory - After creating a new project:
setup.cmdruns automatically, but can be re-run if needed
- Really good information on logging here (with configuration): https://learn.microsoft.com/en-us/dotnet/core/extensions/logging?tabs=command-line
- .gitignores: https://github.com/github/gitignore
- .editorconfig: https://editorconfig.org/
- Add loglevels to test