Smart.Console.Template 4.4.1

Suggested Alternatives

Smart.App

Additional Details

Smart.Console.Template是一个.NET软件模板包,他已不再维护。接替他的是Smart.App软件模板包,支持.NET 8/10平台,支持DDD架构。
Smart.Console.Template is a .NET software template package that is no longer maintained. It has been succeeded by the Smart.App software template package, which supports the .NET 8/10 platforms and is compatible with DDD architecture.

dotnet new install Smart.Console.Template::4.4.1
                    
This package contains a .NET Template Package you can call from the shell/command line.

Smart.Console.Template

.NET 8/9 NuGet NLog

基于 .NET 通用主机(IHost)的控制台应用快速开发框架,集成依赖注入、配置管理和后台服务支持。

功能特性

1. 现代化控制台架构

  • 基于 Microsoft.Extensions.Hosting 构建
  • 支持后台服务(IHostedService
  • 内置优雅停机(Ctrl+C 中断处理)

2. 开箱即用的组件

  • 配置系统
csharp
.AddJsonFile("appsettings.json")
.AddEnvironmentVariables()
.AddUserSecrets<Program>()
  • 依赖注入
csharp
services.ScanCustomizedServices(); // 自动扫描注册服务

3. 关键设计

csharp
// 中文编码支持(GBK/GB2312)
Encoding.RegisterProvider(CodePagesEncodingProvider.Instance);

// 后台服务异常处理
services.Configure<HostOptions>(options =>
{
  options.BackgroundServiceExceptionBehavior = BackgroundServiceExceptionBehavior.Ignore;
});

快速开始

安装

bash
dotnet new install Smart.Console.Template

创建项目

bash
dotnet new smart.console -n MyDemo

添加服务

csharp
// 实现 IHostedService
public class DemoService : BackgroundService
{
  protected override Task ExecuteAsync(CancellationToken stoppingToken)
  {
    // 你的业务逻辑
  }
}

// 通过特性自动注册
[Service(ServiceLifetime.Singleton, InjectScheme.OnlySelf)]
public class DataService
{
  // 你的业务逻辑
}

部署要求

必须使用「依赖框架」部署模式
项目发布时请使用以下命令配置(目标框架由您指定,此处为net8.0):

bash
dotnet publish -c Release --self-contained false -f net8.0
部署模式 适用场景 本模板要求
依赖框架 目标机器已安装 .NET 运行时 ✅ 强制使用
独立部署 无运行时环境 ❌ 不支持

推荐搭配 .NET 运行时安装脚本 部署

开发建议

服务注册约定

用户需要了解Smart.Inject框架的用法,访问Smart.Inject

Developed by zenglei

This package has no dependencies.

NuGet packages

This package is not used by any NuGet packages.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
4.4.1 428 11/12/2025 4.4.1 is deprecated because it is no longer maintained.
4.4.0 331 11/9/2025 4.4.0 is deprecated because it is no longer maintained.
4.3.2 387 7/14/2025 4.3.2 is deprecated because it is no longer maintained.
4.3.1 384 7/14/2025 4.3.1 is deprecated because it is no longer maintained.
4.3.0 414 7/3/2025 4.3.0 is deprecated because it is no longer maintained.
4.2.0 443 3/27/2025 4.2.0 is deprecated because it is no longer maintained.
4.1.0 402 3/23/2025 4.1.0 is deprecated because it is no longer maintained.
4.0.4 384 3/18/2025 4.0.4 is deprecated because it is no longer maintained.
4.0.3 465 3/4/2025 4.0.3 is deprecated because it is no longer maintained.
4.0.2 360 2/26/2025 4.0.2 is deprecated because it is no longer maintained.
4.0.1 357 2/16/2025 4.0.1 is deprecated because it is no longer maintained.
4.0.0 355 2/15/2025 4.0.0 is deprecated because it is no longer maintained.
3.2.0 363 2/14/2025 3.2.0 is deprecated because it is no longer maintained.
3.1.2 362 2/9/2025 3.1.2 is deprecated because it is no longer maintained.
3.1.1 363 12/29/2024 3.1.1 is deprecated because it is no longer maintained.
3.1.0 372 12/7/2024 3.1.0 is deprecated because it is no longer maintained.
3.0.1 353 12/7/2024 3.0.1 is deprecated because it is no longer maintained.
3.0.0 359 12/7/2024 3.0.0 is deprecated because it is no longer maintained.
2.0.1 344 11/27/2024 2.0.1 is deprecated because it is no longer maintained.
2.0.0 343 11/26/2024 2.0.0 is deprecated because it is no longer maintained.
Loading failed