Ardalis (Steve Smith) speaking at Techorama 2024
Ardalis (Steve Smith)

Software Architect • Microsoft MVP • Clean Code Advocate

MVP Architect Author Speaker Trainer
Work With Me →

Helping other software professionals to keep improving!

Recent Blog Posts

Single File Test Suites in Dotnet Csharp

Single File Test Suites in Dotnet Csharp

This article is part of the 2025 Advent of C# Code Calendar, which publishes 2 C# articles every day in December leading up to 25 December.

NOTE: Originally targeted xUnit v2; now updated to xUnit.v3.

Introduction

One of my favorite new features in .NET 10 is C# file-based apps (or file-based C# programs if you prefer). With this feature, we can create individual .cs files and then run them using dotnet run <file.cs>. On Unix OSes you can go even further and mark the files as executable and include a shebang (#!) directive as the first line to tell the OS what to run it with and then you can run the files directly without even calling dotnet run.

Read More →
Use cd - in Powershell 7 to Return to Previous Directory

Use cd - in Powershell 7 to Return to Previous Directory

Introduction

A command that many shells have had forever and that PowerShell has had for a long time as well is ‘cd -’ which means “change directory to previous folder”. This means you could do something like this:

1
2
3
4
5
6
> cd c:\dev
c:\dev
> cd c:\temp
c:\temp
> cd -
c:\dev

This is quite handy in many situations. In particular, since I’ve modified my PowerShell Profile to NOT start in my users folder but instead to start in my c:\dev folder (from which I can easily get to any repo I may be working from), I very often find myself using cd - whenever I create a new terminal in the folder I want to be in such as when using VS Code.

Read More →
How to Update .NET on Wsl or Ubuntu

How to Update .NET on Wsl or Ubuntu

Ever year or so, a new version of .NET ships, and I need to upgrade the .NET SDK version on my machines. Not just the Windows machines, but also the WSL Ubuntu bits that live on those same machines.

First, determine what version of dotnet you already have using this:

1
2
dotnet --version
> 10.0.100-rc.1.25451.107

Yep, I need to update that. But how? Surely there must be a simple way to do it using just the command line. If you just do a quick search for how to do this, you’ll find instructions like this:

Read More →
The Ardalis Cli

The Ardalis Cli

Back in the .NET 10 Preview days, Andrew Lock wrote about running one-off dotnet tools with DNX. I decided to riff on that to create what was initially just a business card, but then I enhanced it with some additional functionality, making a full-blown Ardalis CLI tool, which mostly just gets you access to content from me in your terminal.

You can find the source for my ardalis command line interface as well as its listing on NuGet. You should review these before running commands on your machine to ensure the tool isn’t doing anything nefarious.

Read More →
Use TimeSpan Or Specify Units In Duration Properties And Parameters

Use TimeSpan Or Specify Units In Duration Properties And Parameters

A special case of primitive obsession is the use of an int value to describe a span of time. You see this all the time in various APIs, and it’s a frequent source of bugs and confusion. Developers are forced to either guess or try to find the documentation that describes what units int timeout or int delay actually uses.

Having a retry delay of 1 millisecond instead of 1 second, for example, is a huge difference - that’s 1000x more load on your system! But so is having a timeout of 1000 seconds (nearly 17 minutes!) instead of 1000 milliseconds (1 second). Either way, it’s three orders of magnitude away from the expected and intended behavior, which can lead to production incidents and difficult-to-diagnose bugs.

Read More →