Adding Azurite to a .NET project


Adding Azurite to a .NET project

Azurite is an open source Azure Storage API compatible server (emulator), that simulates most of the commands supported by Azure Storage with minimal dependencies. It replaces the deprecated Azure Storage Emulator, according to Microsoft’s documentation.

Creating new projects with Azurite

Installing Azurite in projects created from scratch is super easy, so let’s take an Azure Functions project for example. All we need to do is to tick the “Use Azurite for runtime storage account” checkbox when creating the new project.

As soon as you finish creating your project, you can already see on the Output view that Azurite is up and running.

Adding Azurite to an existing .NET project

Sometimes, we might accidentally not add Azurite when creating a new project. Or maybe we used another template that doesn’t install it automatically. Maybe we are replacing the deprecated Azure Storage Emulator, who knows. But anyway, it’s very simple to add it, although not straightforward.

The first thing you need to do is to add a service dependency, so open the Solution Explorer, right-click on Connected Services then Add > Azure Storage.

A new window will pop up. Choose “Storage Azurite emulator (Local)”, give any connection string name to it, decide whether or not to store it and press Finish. By the way, in this tutorial, we are not saving the connection string anywhere.

Now’s the time that it gets not so straightforward anymore. We need to add a local.settings.json file inside our project’s folder. The contents of it can change depending on which .NET version you are running. Below you can find some examples for .NET 6 and 7, but you can always create a new project with Azurite, and then copy the contents of the generated file.

local.settings.json for .NET 6

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet"
    }
}

local.settings.json for .NET 7

{
    "IsEncrypted": false,
    "Values": {
        "AzureWebJobsStorage": "UseDevelopmentStorage=true",
        "FUNCTIONS_WORKER_RUNTIME": "dotnet-isolated"
    }
}

Restart your Visual Studio and you will see that Azurite is now up and running!