Could not load file or assembly 'System.Security.Principal.Windows'
I had the same issue after I upgraded Microsoft.Net.Compiler from 2.8.2 to 2.9.0. After I downgraded to 2.8.2 projects compiled without any errors.
None of the previous answers worked for me.
The problem was that I didn't have the .NET Compiler Platform SDK installed.
To solve, open Visual Studio Installer, choose "Modify", and under the "Invididual Component" tab, check the .NET Compiler Platform SDK, and confirm your changes by clicking "Modify".
After I installed it and reopened Visual Studio, the problem is gone.
Had this same issue and resolved it.
In a 3 project solution MVC controller (Web,Business,Data)
Caused by the Microsoft.Net.Compiler 2.9.0 being installed on the Web project but not the other projects.
To resolve: Right click the solution. Manage NuGet Packages. Installed > Search for the compiler Ensure it is the same version and it is installed on all projects in your solution
Once installed my solution built successfully