Run Azurite in Windows

Azurite is an emulator for Azure blob, queue and table that can be used in a local development environment.

“Newer” Visual Studio installations should include this emulator. Whether it has started correctly or works as expected is hidden in mist.

So, I use these files to start azurite emulator from my Windows desktop.
If the default azurite ports in use, the related processes are automatically stopped.

Prerequisites: install Azurite to c:\azurite
Put the following 2 files in c:\azurite folder and create a shortcut for azurite.bat on your window desktop:

c:\azurite\azurite.bat:

@echo off
pwsh -NoLogo -NoProfile -File "C:\azurite\azurite.ps1"
pause

c:\azurite\azurite.ps1:

# --- Settings ---

# --- The path where azurite is installed
$azuriteRoot = 'C:\azurite'
$portsToFree = 10000, 10001, 10002   # Blob, Queue, Table

# --- Go to working folder ---
Set-Location -Path $azuriteRoot

# --- Show Azurite version ---
Write-Host "Running Azurite Version:" (azurite -v)

# --- Function: stop whatever is listening on specified ports ---
function Stop-ListeningProcessesOnPorts {
    param([int[]]$Ports)

    foreach ($p in $Ports) {
        try {
            # Find listeners on the port
            $conns = Get-NetTCPConnection -LocalPort $p -State Listen -ErrorAction SilentlyContinue
            if (-not $conns) {
                Write-Host "Port $p is free."
                continue
            }

            # Stop each owning process
            foreach ($c in $conns) {
                try {
                    $proc = Get-Process -Id $c.OwningProcess -ErrorAction Stop
                    Write-Host "Found process '$($proc.ProcessName)' (PID $($proc.Id)) already listening on port $p, shutting it down..."
                    Stop-Process -Id $proc.Id -Force
                }
                catch {
                    Write-Warning "Failed to stop PID $($c.OwningProcess) on port $p. $_"
                }
            }
        }
        catch {
            Write-Warning "Could not query listeners on port $p. $_"
        }
    }
}

# --- Kill ports if needed ---
Write-Host "-----------------------------"
Write-Host "Checking ports needed by Azurite:" 
Stop-ListeningProcessesOnPorts -Ports $portsToFree
Write-Host "-----------------------------"

# --- Start Azurite ---
azurite -l $azuriteRoot -d (Join-Path $azuriteRoot 'debug.log')

# --- Keep window open after Azurite exits ---
Read-Host "Press Enter to exit"

Docs:

https://learn.microsoft.com/en-us/azure/storage/common/storage-use-azurite

https://learn.microsoft.com/en-us/azure/storage/common/storage-install-azurite

Use .http files in Visual Studio 2022

The Visual Studio 2022 .http file editor provides a convenient way to test ASP.NET Core projects, especially API apps. The editor provides a UI that:

  • Creates and updates .http files.
  • Sends HTTP requests specified in .http files.
  • Displays the responses.

This article contains documentation for:

The .http file format and editor was inspired by the Visual Studio Code REST Client extension. The Visual Studio 2022 .http editor recognizes .rest as an alternative file extension for the same file format.

Source: Use .http files in Visual Studio 2022 | Microsoft Learn

New: Better search in Visual Studio – Visual Studio Blog

Image All in one search

To enable the new search experience, go to Tools > Options > Environment > Preview Features > New Visual Studio Search Experience. After doing that, and restarting Visual Studio, you’ll now see the new search button appear in the title bar, as shown in the screenshot below.

Image All in one search split button

Ctrl + T for code search and Ctrl + Q for feature search stay the same, so your muscle memory remains intact.

Source: New: Better search in Visual Studio – Visual Studio Blog

Fine Code Coverage – Visual Studio Marketplace

Visualize unit test code coverage easily for free in Visual Studio Community Edition (and other editions too)

Coverage View
Source: Fine Code Coverage – Visual Studio Marketplace

Usage:

  1. Install
  2. Open the Fine Code Coverage window
  3. Run all unit tests
  4. See stats in Fine Code Coverage window
  5. Exclude the test project itself from coverage calculation:

    (Below excludes project that ends with .Test and all its types (*

Pattern: [assemblyname]type

Filter Expressions:

Wildcards
* => matches zero or more characters
		
Examples
[*]* => All types in all assemblies (nothing is instrumented)
[coverlet.*]Coverlet.Core.Coverage => The Coverage class in the Coverlet.Core namespace belonging to any assembly that matches coverlet.* (e.g coverlet.core)
[*]Coverlet.Core.Instrumentation.* => All types belonging to Coverlet.Core.Instrumentation namespace in any assembly
[coverlet.*.tests]* => All types in any assembly starting with coverlet. and ending with .tests

Both 'Exclude' and 'Include' options can be used together but 'Exclude' takes precedence.

Log info with tracepoints – Visual Studio (Windows) | Microsoft Docs

Tracepoints allow you to log information to the Output window under configurable conditions without modifying or stopping your code. This feature is supported for both managed languages (C#, Visual Basic, F#) and native code as well as languages such as JavaScript and Python.

Source: Log info with tracepoints – Visual Studio (Windows) | Microsoft Docs

EditorConfig settings – Visual Studio

You can add an EditorConfig file to your project or codebase to enforce consistent coding styles for everyone that works in the codebase. EditorConfig settings take precedence over global Visual Studio text editor settings. This means that you can tailor each codebase to use text editor settings that are specific to that project. You can still set your own personal editor preferences in the Visual Studio Options dialog box. Those settings apply whenever you’re working in a codebase without an .editorconfig file, or when the .editorconfig file doesn’t override a particular setting. An example of such a preference is indent style—tabs or spaces.

Source: EditorConfig settings – Visual Studio (Windows) | Microsoft Docs