I found that I needed to add the Microsoft.Windows.Compatibility NuGet package. Although I also changed from .NET 7.0 to .NET 8.0 and added the magic lines to my csproj file from this answer all at the same time. Removing the magic csproj file lines still works and I would imagine reverting to .NET 7.0 would as well.