Could not load file or assembly Microsoft.CodeAnalysis

I figured this out myself. To anyone reading this, the problem was that the Nuget package Microsoft.CodeDom.Providers.DotNetCompilerPlatform (which also contains the CodeAnalysis package) was the wrong version. I created a new webproject, updated the offending Nuget package right away, and the problem was solved.


Other possible fix (at least for Visual Studio 2015):

Get the latest Visual Studio update.

You can check for updates by going to Tools/Extensions and Updates/Updates

Same as this Q/A: Visual Studio 2015: Quick Actions no longer working, error: Could not load file or assembly Microsoft.CodeAnalysis