您现在访问的是微软AZURE全球版技术文档网站,若需要访问由世纪互联运营的MICROSOFT AZURE中国区技术文档网站,请访问 https://docs.azure.cn.

用于 .NET 的 Azure 计费库Azure Billing libraries for .NET

概述Overview

使用 Azure 计费 API(预览)可以编程方式访问 Azure 计费信息和发票。Azure Billing API (preview) provides programmatic access to your Azure billing information and invoices.

管理库Management library

直接从 Visual Studio 包管理器控制台或使用 .NET Core CLI 安装 NuGet 包Install the NuGet package directly from the Visual Studio Package Manager console or with the .NET Core CLI.

Visual Studio 包管理器Visual Studio Package Manager

Install-Package Microsoft.Azure.Management.Billing
dotnet add package Microsoft.Azure.Management.Billing

代码示例Code Example

连接到 Azure 并获取发票列表。Connect to Azure and get a list of invoices.

/* Include these directives
using Microsoft.Rest.Azure.Authentication;
using Microsoft.Azure.Management.Billing;
using Microsoft.Azure.Management.Billing.Models;
*/

// Log into Azure
var serviceCreds = ApplicationTokenProvider.LoginSilentAsync(tenantId, clientId, secret);
var billingClient = new BillingClient(serviceCreds);
billingClient.SubscriptionId = subscriptionId;

// Get list of invoices
billingClient.Invoices.List();

示例Samples