Search code examples
azure-storagevisual-studio-2022

How to use Azurite with Visual Studio 2022?


I have a project that requires Azure Storage. Previously, I have been using the Microsoft Azure Storage Emulator - v5.10, which can easily be run from the Search bar.

How can Azurite be setup to be used in a project in Visual Studio 2022?


There is no Connected Service appearing in my Solution Explorer. And when I right-click a project and select Add, the Connection Service it is deactivated.

I have a multi-project ASP .NET MVC solution, mostly running .NET Framework 4.8.


Solution

  • In Visual Studio Installer => Visual Studio => Modify => Individual components, I have unchecked the .NET Framework 4.8 SDK => Remove => Modify.

    You can see that the components related to Azure resource have been removed.

    enter image description here

    • Now when I try to add the Connected Services, I can see the option to Manage Connected Services but the Connected Services window is not opened.

    enter image description here

    • If you select the Azure development/ .NET Framework 4.8 SDK(under Individual components) and modify VS, the components related to Azure resources will be added.

    enter image description here

    • Modify VS with above changes.

    • Now Iam able to see and add Azurite from Connected services.

    enter image description here

    Is there a preferred way to integrate it with Visual Studio or any recommended best practices for this?

    Yes, this is the most easy and preferred way to add Azure resources.

    If you still face issues, you can even integrate Azurite manually (but includes manual steps to follow which is not easy to configure).

    The below screenshot is from Connected Services, try to install the specified packages manually.

    enter image description here

    Packages to Install from NuGet Manager

    enter image description here

    • Right click on the Solution Explorer => Manage User Secrets, secrets.xml will be created.

    • Add the below settings in secrets.xml.

    <?xml version="1.0" encoding="utf-8"?>
    <root>
      <secrets ver="1.0">
        <secret name="Azurite" value="UseDevelopmentStorage=true" />
        <secret name="Azurite:blob" value="UseDevelopmentStorage=true" />
        <secret name="Azurite:queue" value="UseDevelopmentStorage=true" />
      </secrets>
    </root>
    
    • And 3 files with serviceDependencies prefix has to be added which contains the Azurite ConnectionID.

    enter image description here

    Refer this MSDoc for more details.