The last days I spent some time to port my NuGet packages (AzureBillingApi and FeedReader) to .net standard. As it was not so straight forward, I want to share what I did. The migration is certainly more complicated the larger the project is, but this post will hopefully give you some basic insights on how to migrate. The most time-consuming part will be to change the existing code so that it works with .net standard. In this blog post, I’ll focus on how to change the project to use .net standard and .net framework. In this case, I’ll port the AzureBillingApi to .net standard 1.4, but it will still support .net framework 4.5.2.
Before migrating the project, you should at first check if the NuGet packages that you use in your project are already compatible to .net standard. There are different ways how to check it. You can create a new .net standard project and manually add all NuGet packages to it – then try to build it. This will immediately show you if these packages support .net standard or not.
Another way is to go to nuget.org or use the NuGet Package Explorer and check the dependencies (Dependencies section) for all your packages.
In this blog post I’ll build a simple C# Azure function that returns an object as JSON. That’s useful if you want to build a simple “API” or if you just want to return some information in a structured format. Such a function could read data from an on-premise environment and provide this data to a logic app, because it’s much easier to connect an Azure function to on-premise than a logic app.
Create a C# Azure Function
First step is to create a new C# function. I’ll use the HttpTriggerWithParameters-CSharp template and I’ll use the authorization level ‘Anonymous’ (that’s okay for this demo):
Since end of April 2017, there is the new Azure Invoice API available. This API allows to download the Azure invoices for a subscription as PDF file. This does currently not work for Enterprise Agreements, but according to the blog post (https://azure.microsoft.com/en-us/blog/azure-billing-reader-role-and-preview-of-invoice-api/) it is planned.
The downloaded PDF is the invoice itself. The API does currently only support to create and download invoice pdfs. It does not support to access specific costs (e.g. per resources), because this is part of the billing API. I already blogged about the billing API here: Use the Azure Billing API and calculate the costs