Q:

Multi-Target .NET Standard 2.0 and .NET 4.5 fails due to missing .net 4.5 framework

On my dev box I have .net 4.6.2 and dotnet-sdk-2.1 installed. I originally had 4.0 then 4.5 then 4.6.2
I am able to run dotnet build on a project which multi-targets to both netstandard2.0 and net45 like this:
<TargetFrameworks>netstandard2.0;net45</TargetFrameworks>

I am able to build it successfully and run unit tests etc. I see the bin directory contains subdirectories for each target framework and contains all the DLLs.
When I try to put together my CI build on a teamcity agent which is built on Windows Server 2016. I get an error:

The reference assemblies for framework ".NETFramework,Version=v4.5" were not found. 

This is puzzling to me because the machine has .NET 4.6.2 SDK installed. (It also has the dotnet sdk 2.1 installed)
Doing some googling around I see many mentioning that the frameworks should be in the dictory:
C:\Program Files (x86)\Reference Assemblies\Microsoft\Framework\.NETFramework\

And when I check the Server 2016 machine I see the directory and I see subdirectory: v4.6.2 no subdirectories for 4.5
On my dev box however I see all kinds of directories there: 4.5, 4.0, 3.5, 4.6.2 ...
I can't install framework 4.5 SDK on the Server 2016 machine because it already has a higher version installed. So it seems I can't build targeting .NET 4.5 on that machine.
As a sanity check I changed my csproj file to:
<TargetFrameworks>netstandard2.0;net462</TargetFrameworks>

And I was able to build the project successfully. So the build does work but it requires 4.6.2 on that machine. It does not work neither if I target net46.
What am I doing wrong here?
Is there a way for me to be able to multi-target my project to net45 on the Server 2016 machine?

A:

TL;DR: install the .NET Framework 4.5 Developer Pack to build .NET Framework 4.5 projects.
You say that your server has the .NET Framework 4.6.2 Developer Pack installed, and you are trying to build a .NET Framework 4.5 project with it.
Unlike runtime packs, where each version contains (so to speak) the previous version, you need to have the developer pack for the exact version of the framework you are targetting.

