NFEConsulta 0.4.2

dotnet add package NFEConsulta --version 0.4.2
                    
NuGet\Install-Package NFEConsulta -Version 0.4.2
                    
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="NFEConsulta" Version="0.4.2" />
                    
For projects that support PackageReference, copy this XML node into the project file to reference the package.
<PackageVersion Include="NFEConsulta" Version="0.4.2" />
                    
Directory.Packages.props
<PackageReference Include="NFEConsulta" />
                    
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 NFEConsulta --version 0.4.2
                    
#r "nuget: NFEConsulta, 0.4.2"
                    
#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 NFEConsulta@0.4.2
                    
#: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=NFEConsulta&version=0.4.2
                    
Install as a Cake Addin
#tool nuget:?package=NFEConsulta&version=0.4.2
                    
Install as a Cake Tool

Logo

NuGet Downloads Build Publish CodeQL Scorecard Release Drafter GitHub stars License

NFEConsulta é uma biblioteca .NET para consultar NF-e.

Diferenciais

  • Status oficial da SEFAZ via NFeStatusServico4, em vez de ping ou teste de rede.
  • Resolucao conservadora de endpoints por UF, com SP como default e override explicito quando necessario.
  • CorrelationId opcional para rastrear jobs, lotes e logs.
  • Validacao de XML contra XSD oficial incluso no pacote.
  • Contratos tipados para separar retorno fiscal de falha tecnica.
  • Suporte para biblioteca, CLI e API REST interna.

Documentacao

Instalacao

dotnet add package NFEConsulta

Exemplo rapido

using System.Security.Cryptography.X509Certificates;
using NFEConsulta.Infrastructure;
using NFEConsulta.Models;
using NFEConsulta.Services;

using X509Certificate2 certificado = CertificadoProvider.ObterPorPem(
    "certs/cert.pem",
    "certs/key.pem");

NFeConsultaOptions options = new()
{
    Ambiente = TipoAmbiente.Producao,
    Uf = UfNFe.SP,
    CorrelationId = "job-20260619-001"
};

using NFeConsultaClient client = NFeConsultaClient.CriarComCertificado(certificado, options);
ConsultaNFeResult resultado = await client.ConsultarChaveAsync("99999999999999999999999999999999999999999999");

Extraindo dados do Certificado

Biblioteca C#

using NFEConsulta.Infrastructure;

CertificadoInfo info = certificado.ExtrairInfo();
Console.WriteLine($"CNPJ: {info.Cnpj}");
Console.WriteLine($"Vencimento: {info.DataExpiracao}");

CLI

nfeconsulta certificado --cert-pem cert.pem --key-pem key.pem
# Ou com saida em JSON:
nfeconsulta certificado --cert-pem cert.pem --key-pem key.pem --json

Consultando CNPJ / Cadastro de Contribuinte na SEFAZ

Você pode consultar a situação fiscal e cadastral de um CNPJ, CPF ou Inscrição Estadual (IE) diretamente junto aos webservices estaduais da SEFAZ usando o método NFeCadastroClient.

using NFEConsulta.Models;
using NFEConsulta.Services;

NFeConsultaOptions options = new()
{
    Ambiente = TipoAmbiente.Producao,
    Uf = UfNFe.SP // Define a UF da consulta
};

using NFeCadastroClient client = NFeCadastroClient.CriarComCertificado(certificado, options);
CadastroConsultaResult resultado = await client.ConsultarCadastroAsync("12345678901234"); // CNPJ, CPF ou IE

if (resultado.Sucesso)
{
    foreach (var cad in resultado.Contribuintes)
    {
        Console.WriteLine($"Nome: {cad.Nome}");
        Console.WriteLine($"IE: {cad.IE}");
        Console.WriteLine($"Situação: {cad.Situacao}"); // Ex: "Habilitado"
        Console.WriteLine($"Endereço: {cad.Endereco?.Logradouro}, {cad.Endereco?.Numero} - {cad.Endereco?.NomeMunicipio}/{cad.UF}");
    }
}

O que esta incluso

  • Validacao de chave de acesso de 44 digitos.
  • Extracao de chave a partir de XML de NF-e.
  • Validacao XML contra XSD oficial.
  • Consulta de NF-e por chave.
  • Consulta do status oficial da SEFAZ.
  • Consulta de cadastro de contribuinte (CNPJ, CPF ou IE) via SEFAZ (CadConsultaCadastro4).
  • Extração de dados e metadados de certificados digitais (CNPJ, nome, datas).
  • Suporte para biblioteca, CLI e API interna.

Projetos

  • src/NFEConsulta.Core: biblioteca principal publicada no NuGet como NFEConsulta.
  • src/NFEConsulta.Cli: CLI publicada como NFEConsulta.Cli.
  • src/NFEConsulta.Api: API REST interna.

Pacote e versao

A versao publica atual e 0.4.2.

🔗 Projetos relacionados

Projeto Descrição
NFeSchemaDownloader Mantém os Schemas XML (XSD) da SEFAZ sempre atualizados automaticamente
NFEDanfe Gera DANFE em PDF a partir de XML NF-e autorizado

Ferramentas CLI

  • NFEDanfe.Cli → Geração de DANFE pela linha de comando.
  • NFeSchemaDownloader.Cli → Automação de download de Schemas.

Fluxo recomendado

NFeSchemaDownloader (Mantém XSDs atualizados)
   │
   ▼
NF-e XML
   │
   ▼
NFEConsulta (Valida XML via XSD e consulta SEFAZ)
   │
   ▼
NFEDanfe (Gera o PDF final)

Autor

Fabyo Guimaraes Oliveira

Licenca

MIT.

Product Compatible and additional computed target framework versions.
.NET net8.0 is compatible.  net8.0-android was computed.  net8.0-browser was computed.  net8.0-ios was computed.  net8.0-maccatalyst was computed.  net8.0-macos was computed.  net8.0-tvos was computed.  net8.0-windows was computed.  net9.0 was computed.  net9.0-android was computed.  net9.0-browser was computed.  net9.0-ios was computed.  net9.0-maccatalyst was computed.  net9.0-macos was computed.  net9.0-tvos was computed.  net9.0-windows was computed.  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.
  • net10.0

    • No dependencies.
  • net8.0

    • 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
0.4.2 107 6/26/2026
0.4.0 107 6/26/2026
0.3.0 162 6/24/2026
0.2.5 107 6/23/2026
0.2.4 108 6/23/2026
0.2.3 228 6/19/2026
0.2.2 107 6/19/2026
0.2.1 109 6/19/2026
0.2.0 112 6/19/2026
0.1.11 109 6/18/2026
0.1.10 108 6/18/2026
0.1.8 112 6/18/2026
0.1.7 107 6/18/2026
0.1.6 110 6/18/2026