Cannot compile solution in visual studio

I have a very odd problem. The source for my current game compiles fine in Unity3D and runs. When I double-click on a script Unity3D (5.4.1) will generate my SLN file and open it in Visual Studio 2015.

When I try to compile in Visual Studio I get loads of errors

Error CS0234 The type or namespace name ‘LoggingFacade’ does not exist in the namespace ‘MyCompanyName’ (are you missing an assembly reference?)

Here is the really odd thing. If I double-click an error to open the offending CS file the error disappears without me having to alter the source code at all. So I can in fact build my game in Visual Studio if I first open every CS file in the editor. If I don’t then I get these errors.

Can anyone help?

Why do you build in Visual Studio? I don’t think you need to do that at all. Unity does that for you when you run or build your game. VS is just an editor.

The answer is the project was set to compile against .NET 2.0 SUBSET. To change it go to File->Build Settings, then click Player Settings, and in the Object Inspector expand the Other Settings tab and change Api Compatibility Level.