Repository: godot
Issue: Windows MSVC x64 Debug Mono build fails due to "Could not load file or assembly 'Microsoft.DotNet.PlatformAbstractions, Version=2.1.0.0"
Labels: platform:windows,topic:buildsystem,needs testing,topic:dotnet

### Godot version

3.3.3-stable

### System information

Windows 10

### Issue description

I am trying to build Godot within Mono x64 Command Prompt with Visual Studio 2019 installed:

It seems like [this](https://github.com/dotnet/Nerdbank.GitVersioning/issues/466#issuecomment-620615064) might be relevant?



```powershell
F:\GodotBuild\godot>mono --version
Mono JIT compiler version 6.12.0 (Visual Studio built mono)
Copyright (C) 2002-2014 Novell, Inc, Xamarin Inc and Contributors. www.mono-project.com
        TLS:           __thread
        SIGSEGV:       normal
        Notification:  Thread + polling
        Architecture:  amd64
        Disabled:      none
        Misc:          softdebug
        Interpreter:   yes
        LLVM:          supported, not enabled.
        Suspend:       preemptive
        GC:            sgen (concurrent by default)

F:\GodotBuild\godot>dotnet --version
5.0.400

F:\GodotBuild\godot>scons --version
SCons by Steven Knight et al.:
        SCons: v4.2.0.fcdadeef19fe5fead09fa7544a27502be65312be, Sat, 31 Jul 2021 18:12:46 -0700, by bdbaddog on ProDog2020
        SCons path: ['c:\\users\\aytas\\appdata\\local\\programs\\python\\python37-32\\lib\\site-packages\\SCons']
Copyright (c) 2001 - 2021 The SCons Foundation

F:\GodotBuild\godot>scons p=windows target=debug tools=yes module_mono_enabled=yes copy_mono_root=yes -j8
scons: Reading SConscript files ...
Configuring for Windows: target=debug, bits=default
Found MSVC version 14.2, arch amd64, bits=64
Checking for `thread_local` support... supported
Found Mono root directory: C:\Program Files\Mono\
YASM is necessary for WebM SIMD optimizations.
WebM SIMD optimizations are disabled. Check if your CPU architecture, CPU bits or platform are supported!
Checking for C header file mntent.h... (cached) no
scons: done reading SConscript files.
scons: Building targets ...
[ 96%] build_api_solution(["bin\GodotSharp\Api\Debug\GodotSharp.dll", "bin\GodotSharp\Api\Debug\GodotSharp.pdb", "bin\GodotSharp\Api\Debug\GodotSharp.xml", "bin\GodotSharp\Api\Debug\GodotSharpEditor.dll", "bin\GodotSharp\Api\Debug\GodotSharpEditor.pdb", "bin\GodotSharp\Api\Debug\GodotSharpEditor.xml"], [])
[ 97%] MSBuild path: C:\Program Files\dotnet\dotnet.exe
[ 99%] progress_finish(["progress_finish"], [])
[100%] Microsoft (R) Build Engine version 16.11.0+0538acc04 for .NET
Copyright (C) Microsoft Corporation. All rights reserved.

  Determining projects to restore...
  All projects are up-to-date for restore.
C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(192,5): error MSB4018: The "GenerateDepsFile" task failed unexpectedly. [F:\GodotBuild\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(192,5): error MSB4018: System.IO.FileNotFoundException: Could not load file or assembly 'Microsoft.DotNet.PlatformAbstractions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60'. The system cannot find the file specified. [F:\GodotBuild\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(192,5): error MSB4018: File name: 'Microsoft.DotNet.PlatformAbstractions, Version=2.1.0.0, Culture=neutral, PublicKeyToken=adb9793829ddae60' [F:\GodotBuild\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(192,5): error MSB4018:    at Microsoft.NET.Build.Tasks.FrameworkReferenceResolver.GetDefaultReferenceAssembliesPath() [F:\GodotBuild\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(192,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.WriteDepsFile(String depsFilePath) [F:\GodotBuild\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(192,5): error MSB4018:    at Microsoft.NET.Build.Tasks.GenerateDepsFile.ExecuteCore() [F:\GodotBuild\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(192,5): error MSB4018:    at Microsoft.NET.Build.Tasks.TaskBase.Execute() [F:\GodotBuild\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(192,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskExecutionHost.Microsoft.Build.BackEnd.ITaskExecutionHost.Execute() [F:\GodotBuild\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
C:\Program Files\dotnet\sdk\3.1.101\Sdks\Microsoft.NET.Sdk\targets\Microsoft.NET.Sdk.targets(192,5): error MSB4018:    at Microsoft.Build.BackEnd.TaskBuilder.ExecuteInstantiatedTask(ITaskExecutionHost taskExecutionHost, TaskLoggingContext taskLoggingContext, TaskHost taskHost, ItemBucket bucket, TaskExecutionMode howToExecuteTask) [F:\GodotBuild\godot\modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj]
scons: *** [bin\GodotSharp\Api\Debug\GodotSharp.dll] RuntimeError : 'msbuild' exited with error code: 1
Traceback (most recent call last):
  File "F:\GodotBuild\godot\modules\mono\build_scripts\solution_builder.py", line 106, in run_command
    subprocess.check_call(args, env=env_override)
  File "c:\users\aytas\appdata\local\programs\python\python37-32\lib\subprocess.py", line 328, in check_call
    raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['C:\\Program Files\\dotnet\\dotnet.exe', 'msbuild', 'F:\\GodotBuild\\godot\\modules\\mono\\glue/GodotSharp/GodotSharp.sln', '/restore', '/t:Build', '/p:Configuration=Debug', '/p:NoWarn=1591']' returned non-zero exit status 1.

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "c:\users\aytas\appdata\local\programs\python\python37-32\lib\site-packages\SCons\Action.py", line 1279, in execute
    result = self.execfunction(target=target, source=rsources, env=env)
  File "F:\GodotBuild\godot\modules\mono\build_scripts\api_solution_build.py", line 21, in build_api_solution
    build_solution(env, solution_path, build_config, extra_msbuild_args=extra_msbuild_args)
  File "F:\GodotBuild\godot\modules\mono\build_scripts\solution_builder.py", line 148, in build_solution
    run_command(msbuild_path, msbuild_args, env_override=msbuild_env, name="msbuild")
  File "F:\GodotBuild\godot\modules\mono\build_scripts\solution_builder.py", line 108, in run_command
    raise RuntimeError("'%s' exited with error code: %s" % (name, e.returncode))
RuntimeError: 'msbuild' exited with error code: 1
scons: building terminated because of errors.
```

### Steps to reproduce

Follow the official documentation for 3.3.3-stable for [Compiling with Mono](https://docs.godotengine.org/en/3.3.3/development/compiling/compiling_with_mono.html#doc-compiling-with-mono), except with `target=debug` and **multithreading enabled**:

```powershell
# Build temporary binary
scons p=windows target=debug tools=yes module_mono_enabled=yes mono_glue=no -j4
# Generate glue sources
bin\godot.windows.tools.64.mono --generate-mono-glue modules/mono/glue 

### Build binaries normally
# Editor
scons p=windows target=debug tools=yes module_mono_enabled=yes -j4
# Export templates
scons p=windows target=debug tools=no module_mono_enabled=yes -j4
scons p=windows target=release_debug tools=no module_mono_enabled=yes -j4
scons p=windows target=release tools=no module_mono_enabled=yes -j4
```

## Relevant GodotSharp project files that won't build

### modules\mono\glue\GodotSharp\GodotSharp.sln

```sln
Microsoft Visual Studio Solution File, Format Version 12.00
# Visual Studio 2012
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GodotSharp", "GodotSharp\GodotSharp.csproj", "{AEBF0036-DA76-4341-B651-A3F2856AB2FA}"
EndProject
Project("{FAE04EC0-301F-11D3-BF4B-00C04F79EFBC}") = "GodotSharpEditor", "GodotSharpEditor\GodotSharpEditor.csproj", "{8FBEC238-D944-4074-8548-B3B524305905}"
EndProject
Global
	GlobalSection(SolutionConfigurationPlatforms) = preSolution
	Debug|Any CPU = Debug|Any CPU
	Release|Any CPU = Release|Any CPU
	EndGlobalSection
	GlobalSection(ProjectConfigurationPlatforms) = postSolution
		{AEBF0036-DA76-4341-B651-A3F2856AB2FA}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{AEBF0036-DA76-4341-B651-A3F2856AB2FA}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{AEBF0036-DA76-4341-B651-A3F2856AB2FA}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{AEBF0036-DA76-4341-B651-A3F2856AB2FA}.Release|Any CPU.Build.0 = Release|Any CPU
		{8FBEC238-D944-4074-8548-B3B524305905}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
		{8FBEC238-D944-4074-8548-B3B524305905}.Debug|Any CPU.Build.0 = Debug|Any CPU
		{8FBEC238-D944-4074-8548-B3B524305905}.Release|Any CPU.ActiveCfg = Release|Any CPU
		{8FBEC238-D944-4074-8548-B3B524305905}.Release|Any CPU.Build.0 = Release|Any CPU
	EndGlobalSection
EndGlobal
```

### modules\mono\glue\GodotSharp\GodotSharp\GodotSharp.csproj

```csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <ProjectGuid>{AEBF0036-DA76-4341-B651-A3F2856AB2FA}</ProjectGuid>
    <OutputPath>bin/$(Configuration)</OutputPath>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <RootNamespace>Godot</RootNamespace>
    <TargetFramework>netstandard2.0</TargetFramework>
    <DocumentationFile>$(OutputPath)/$(AssemblyName).xml</DocumentationFile>
    <EnableDefaultItems>false</EnableDefaultItems>
  </PropertyGroup>
  <PropertyGroup>
    <DefineConstants>$(DefineConstants);GODOT</DefineConstants>
  </PropertyGroup>
  <ItemGroup>
    <Compile Include="Core\AABB.cs" />
    <Compile Include="Core\Array.cs" />
    <Compile Include="Core\Attributes\ExportAttribute.cs" />
    <Compile Include="Core\Attributes\GodotMethodAttribute.cs" />
    <Compile Include="Core\Attributes\RPCAttributes.cs" />
    <Compile Include="Core\Attributes\SignalAttribute.cs" />
    <Compile Include="Core\Attributes\ToolAttribute.cs" />
    <Compile Include="Core\Basis.cs" />
    <Compile Include="Core\Color.cs" />
    <Compile Include="Core\Colors.cs" />
    <Compile Include="Core\DebuggingUtils.cs" />
    <Compile Include="Core\Dictionary.cs" />
    <Compile Include="Core\Dispatcher.cs" />
    <Compile Include="Core\DynamicObject.cs" />
    <Compile Include="Core\Extensions\NodeExtensions.cs" />
    <Compile Include="Core\Extensions\ObjectExtensions.cs" />
    <Compile Include="Core\Extensions\PackedSceneExtensions.cs" />
    <Compile Include="Core\Extensions\ResourceLoaderExtensions.cs" />
    <Compile Include="Core\GD.cs" />
    <Compile Include="Core\GodotSynchronizationContext.cs" />
    <Compile Include="Core\GodotTaskScheduler.cs" />
    <Compile Include="Core\GodotTraceListener.cs" />
    <Compile Include="Core\GodotUnhandledExceptionEvent.cs" />
    <Compile Include="Core\Interfaces\IAwaitable.cs" />
    <Compile Include="Core\Interfaces\IAwaiter.cs" />
    <Compile Include="Core\Interfaces\ISerializationListener.cs" />
    <Compile Include="Core\MarshalUtils.cs" />
    <Compile Include="Core\Mathf.cs" />
    <Compile Include="Core\MathfEx.cs" />
    <Compile Include="Core\NodePath.cs" />
    <Compile Include="Core\Object.base.cs" />
    <Compile Include="Core\Plane.cs" />
    <Compile Include="Core\Quat.cs" />
    <Compile Include="Core\Rect2.cs" />
    <Compile Include="Core\RID.cs" />
    <Compile Include="Core\SignalAwaiter.cs" />
    <Compile Include="Core\StringExtensions.cs" />
    <Compile Include="Core\Transform.cs" />
    <Compile Include="Core\Transform2D.cs" />
    <Compile Include="Core\UnhandledExceptionArgs.cs" />
    <Compile Include="Core\Vector2.cs" />
    <Compile Include="Core\Vector3.cs" />
    <Compile Include="Properties\AssemblyInfo.cs" />
  </ItemGroup>
  <!--
  We import a props file with auto-generated includes. This works well with Rider.
  However, Visual Studio and MonoDevelop won't list them in the solution explorer.
  We can't use wildcards as there may be undesired old files still hanging around.
  Fortunately code completion, go to definition and such still work.
  -->
  <Import Project="Generated\GeneratedIncludes.props" />
</Project>
```

### modules\mono\glue\GodotSharp\GodotSharpEditor\GodotSharpEditor.csproj

```csproj
<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <ProjectGuid>{8FBEC238-D944-4074-8548-B3B524305905}</ProjectGuid>
    <OutputPath>bin/$(Configuration)</OutputPath>
    <AppendTargetFrameworkToOutputPath>false</AppendTargetFrameworkToOutputPath>
    <RootNamespace>Godot</RootNamespace>
    <TargetFramework>netstandard2.0</TargetFramework>
    <DocumentationFile>$(OutputPath)/$(AssemblyName).xml</DocumentationFile>
    <EnableDefaultItems>false</EnableDefaultItems>
  </PropertyGroup>
  <PropertyGroup>
    <DefineConstants>$(DefineConstants);GODOT</DefineConstants>
  </PropertyGroup>
  <ItemGroup>
    <ProjectReference Include="..\GodotSharp\GodotSharp.csproj">
      <Private>false</Private>
    </ProjectReference>
  </ItemGroup>
  <!--
  We import a props file with auto-generated includes. This works well with Rider.
  However, Visual Studio and MonoDevelop won't list them in the solution explorer.
  We can't use wildcards as there may be undesired old files still hanging around.
  Fortunately code completion, go to definition and such still work.
  -->
  <Import Project="Generated\GeneratedIncludes.props" />
</Project>
```

### Minimal reproduction project

_No response_