Because I don't use Visual Studio projects or MSBuild, I had to find out how to deal with this at the C# compiler's command line. It isn't that complicated, but there are some new concepts. The .NET assemblies in the same directory as csc.exe are "implementation assemblies". When you want to compile for a particular .NET version, you should use "reference assemblies", which are explained here: ILDasm, mscorlib and System.Runtime decompilation differences depending on the directory
You find reference assemblies under c:\program files (x86)\Reference Assemblies\Microsoft\Framework\.NET Framework
. In there are directories for 3.5, 4.0, 4.5 and 4.5.1, on a machine with VS.2008 to VS.2013 installed. To make use of them, you need a command line like:
csc /target:library /noconfig /nostdlib+ /reference:"C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NET Framework\v4.5\mscorlib.dll" MyLibSrc.cs
/noconfig
tells the C# compiler to ignore csc.rsp, which provides it with a default list of assemblies to reference, which are the implementation assemblies you don't want.
/nostdlib+
tells the C# compiler not to use its default standard library.
/reference
tells the C# compiler that it can use the library whose pathname follows. The one shown here is the standard library for .NET 4.5: the project I built this with only uses the standard library, so that was all I needed.