Adding CsWinRT nuget breaks using Windows.System namespace
See the question and my original answer on StackOverflowWith .NET 5, built-in support for WinRT APIs in .NET is removed (because it's Windows specific) , so we can't use Microsoft.Windows.SDK.Contracts
any more.
The solution as explained here Built-in support for WinRT is removed from .NET is to
Remove references to the Microsoft.Windows.SDK.Contracts package. Instead, specify the version of the Windows APIs that you want to access via the TargetFramework property of the project. For example:
<TargetFramework>net5.0-windows10.0.19041</TargetFramework>
Note with that in place, there's no need to manually add a reference to C#/WinRT (Microsoft.Windows.CsWinRT
) it should be done automatically and shown as "Microsoft.Windows.SDK.NET.Ref
" in the list of Frameworks Dependencies.