Nacos.NET 1.0.1

dotnet add package Nacos.NET --version 1.0.1
                    
NuGet\Install-Package Nacos.NET -Version 1.0.1
                    
This command is intended to be used within the Package Manager Console in Visual Studio, as it uses the NuGet module's version of Install-Package.
<PackageReference Include="Nacos.NET" Version="1.0.1" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="Nacos.NET" Version="1.0.1" />
                    
Directory.Packages.props
<PackageReference Include="Nacos.NET" />
                    
Project file
For projects that support Central Package Management (CPM), copy this XML node into the solution Directory.Packages.props file to version the package.
paket add Nacos.NET --version 1.0.1
                    
#r "nuget: Nacos.NET, 1.0.1"
                    
#r directive can be used in F# Interactive and Polyglot Notebooks. Copy this into the interactive tool or source code of the script to reference the package.
#:package Nacos.NET@1.0.1
                    
#:package directive can be used in C# file-based apps starting in .NET 10 preview 4. Copy this into a .cs file before any lines of code to reference the package.
#addin nuget:?package=Nacos.NET&version=1.0.1
                    
Install as a Cake Addin
#tool nuget:?package=Nacos.NET&version=1.0.1
                    
Install as a Cake Tool

Nacos.NET

Nacos C# SDK 核心库,提供配置中心(INacosConfigService)和服务注册/发现(INacosNamingService)的基础实现。


快速开始

注册服务

// 同时注册配置服务与命名服务
builder.Services.AddNacosV2Config(x =>
{
    x.ServerAddresses = new List<string> { "http://localhost:8848/" };
    x.Namespace = "your-namespace";
    x.UserName = "nacos";
    x.Password = "nacos";
});

builder.Services.AddNacosV2Naming(x =>
{
    x.ServerAddresses = new List<string> { "http://localhost:8848/" };
    x.Namespace = "your-namespace";
    x.UserName = "nacos";
    x.Password = "nacos";
});

也可以从 appsettings.json 读取配置:

builder.Services.AddNacosV2Config(builder.Configuration);
builder.Services.AddNacosV2Naming(builder.Configuration);

对应 appsettings.json

{
  "NacosConfig": {
    "ServerAddresses": ["http://localhost:8848/"],
    "Namespace": "your-namespace",
    "UserName": "nacos",
    "Password": "nacos"
  }
}

注入使用

public class MyService
{
    private readonly INacosConfigService _config;
    private readonly INacosNamingService _naming;

    public MyService(INacosConfigService config, INacosNamingService naming)
    {
        _config = config;
        _naming = naming;
    }

    public async Task<string> GetRemoteConfig()
    {
        // 读取配置
        return await _config.GetConfig("dataId", "DEFAULT_GROUP", 3000);
    }

    public async Task<string> GetServiceAddress()
    {
        // 获取服务实例
        var instance = await _naming.SelectOneHealthyInstance("my-service", "DEFAULT_GROUP");
        return $"http://{instance.Ip}:{instance.Port}";
    }
}

配置 Filter(扩展点)

ConfigFilterChainManager 支持通过 ConfigFilterAssemblies 动态加载 IConfigFilter 实现,可在配置读取时对内容进行处理(例如解密)。

自定义 Filter

实现 IConfigFilter 接口(可选实现 ILoggerAware 以接收日志实例):

public class MyConfigFilter : IConfigFilter, ILoggerAware
{
    private ILogger _logger = NullLogger.Instance;

    public void SetLogger(ILogger logger) => _logger = logger;

    public void Init(NacosSdkOptions options)
    {
        // 从 options.ConfigFilterExtInfo 读取 Filter 配置
        _logger.LogInformation("MyConfigFilter initialized.");
    }

    public void DoFilter(IConfigRequest request, IConfigResponse response, IConfigFilterChain chain)
    {
        chain.DoFilter(request, response); // 先执行链中其他 Filter

        var content = (response as ConfigResponse)?.GetContent();
        if (!string.IsNullOrEmpty(content))
        {
            // 对 content 做处理后写回
            (response as ConfigResponse)?.SetContent(content);
        }
    }

    public int GetOrder() => 0;

    public string GetFilterName() => nameof(MyConfigFilter);
}

appsettings.json 中注册程序集名,SDK 会通过反射自动实例化 Filter:

{
  "NacosConfig": {
    "ConfigFilterAssemblies": ["MyAssembly.Name"],
    "ConfigFilterExtInfo": "传给 Filter 的扩展参数(如加密密钥)"
  }
}

项目已内置 AES 加密 Filter,见 Nacos.NET.Config.Encryption

Product Compatible and additional computed target framework versions.
.NET net10.0 is compatible.  net10.0-android was computed.  net10.0-browser was computed.  net10.0-ios was computed.  net10.0-maccatalyst was computed.  net10.0-macos was computed.  net10.0-tvos was computed.  net10.0-windows was computed. 
Compatible target framework(s)
Included target framework(s) (in package)
Learn more about Target Frameworks and .NET Standard.

NuGet packages (3)

Showing the top 3 NuGet packages that depend on Nacos.NET:

Package Downloads
Nacos.NET.AspNetCore

ASP.NET Core integration for Nacos.NET — one-line AddNacos() registration, health checks, and hosted service lifecycle management.

Nacos.NET.Extensions.Configuration

Microsoft.Extensions.Configuration provider for Nacos — pulls remote config on startup and watches for changes.

Nacos.NET.Config.Encryption

AES-256 config decryption filter for Nacos.NET — transparently decrypts cipher values fetched from Nacos configuration center.

GitHub repositories

This package is not used by any popular GitHub repositories.

Version Downloads Last Updated
1.0.1 41 6/8/2026
1.0.0 43 6/8/2026