How to fix Unity compiler error when building WP8.1 game?

I made an adaption of the Roll-a-Ball tutorial game into a WP8.1 (windows phone 8.1) game. Upon attempting to build the game: I got this error:

Could not start compilationException: 'References\CommonConfiguration\Neutral\Windows.winmd' not found, do you have Windows Phone 8.1 SDK installed?
UnityEditor.Scripting.Compilers.MicrosoftCSharpCompiler.FillNETCoreCompilerOptions (MetroSDK metroSDK, System.Collections.Generic.List`1 arguments, System.String& argsPrefix) (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Scripting/Compilers/MicrosoftCSharpCompiler.cs:134)
UnityEditor.Scripting.Compilers.MicrosoftCSharpCompiler.StartCompiler () (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Scripting/Compilers/MicrosoftCSharpCompiler.cs:225)
UnityEditor.Scripting.Compilers.ScriptCompilerBase.BeginCompiling () (at C:/BuildAgent/work/d63dfc6385190b60/Editor/Mono/Scripting/Compilers/ScriptCompilerBase.cs:47)
UnityEditor.HostView:OnGUI()

I then downloaded the 8.1 sdk on my D drive.

Same error on build.

I then copied the “Windows Kits” folder to “C:\Program Files (x86)”.

Same error on build.

I then copied the “Windows Kits” folder back to my D drive and reinstalled the 8.1 sdk on my C drive.

Same error on build.

I discovered the “Windows Kits” folder was not in my “C:\Program Files (x86)” folder, so I copied it there from my old install.

Same error on build.

I tried copying the “Windows Kits” folder to “Program Files”.

Same error on build.

What else can I do? How can I fix this problem?

EDIT: I fixed the problem and posted an answer about how I fixed it.

You can also get this error when on Windows 10 using Unity 5.2.1f1 and Visual Studio 2015.
That is when the extra Visual Studio 2015 modules for Windows Phone 8.1 are not yet installed.

You can add the modules in Control Panel → Programs and Features → Microsoft Visual Studio … 2015 → Modify.

I figured it out. It turned out the problem was nothing to do with the sdk, I actually needed to install visual studio 2013. I installed it to the default directory and had no build errors.