Skip to content

Instantly share code, notes, and snippets.

@MarkKharitonov
Last active January 18, 2020 18:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save MarkKharitonov/db84bc6f2a8bc75abc15bd0c6afe6d4e to your computer and use it in GitHub Desktop.
Save MarkKharitonov/db84bc6f2a8bc75abc15bd0c6afe6d4e to your computer and use it in GitHub Desktop.
A minimal reproduction of the MSBuild 15 recompilation bug

The minimal reproduction contains

  • 8 cs files - they are all very small, only one contains a non trivial function (~10 lines)
  • 14 csproj files - most of them have no cs files at all, hence the compiler warnings about not seeing any source code at all
  • 2 sln files - the problem reproduces in the second solution
  • 1 dll file - that is the misreferenced binary that causes the recompilation bug

Reproduction notes

  1. The repro.ps1 script assumes that msbuild runs MSBuild 15.
  2. Running repro.ps1 -FromScratch reproduces the bug using the minimal reproduction available at the MSBuild15RecompilationBug github repository.
  3. The generated binary logs are then analyzed using the tool available at the MSBuildBinaryLogAnalyzer github repository.
  4. Using the switch -FromScratch makes the script:
    1. create new temp directory,
    2. clone the aforementioned repositories
    3. build the tool and the reproduction
    4. analyze the relevant binary logs and output the result in a human friendly way
  5. To reproduce again without repeating the whole sheband just run the script without any arguments from the directory where repro.ps1 -FromScratch lands us.
  6. The tool can output its result as json to facilitate scripting when passed the --json flag. In any case running it without any arguments would show the help screen.
  7. Refer to the transcript.txt for a few examples.
param([switch]$FromScratch)
if ($FromScratch)
{
$ReproDir = [io.path]::GetTempFileName()
Remove-Item $ReproDir
mkdir $ReproDir > $null
Set-Location $ReproDir
git clone git@github.com:MarkKharitonov/MSBuild15RecompilationBug.git
git clone git@github.com:MarkKharitonov/MSBuildBinaryLogAnalyzer.git
Set-Location MSBuildBinaryLogAnalyzer
dotnet build -v:q
Set-Location ..\MSBuild15RecompilationBug\
}
else
{
git clean -qdfX
}
msbuild .\DataSvc.sln /v:q
msbuild .\Main.sln /v:q /bl:1.binlog
msbuild .\Main.sln /v:q /bl:2.binlog
..\MSBuildBinaryLogAnalyzer\src\MSBuildBinaryLogAnalyzer\bin\Debug\net472\MSBuildBinaryLogAnalyzer.exe .\2.binlog .\1.binlog
---
C:\> C:\temp\repro\repro.ps1 -FromScratch
Cloning into 'MSBuild15RecompilationBug'...
remote: Enumerating objects: 64, done.
remote: Counting objects: 100% (64/64), done.
remote: Compressing objects: 100% (27/27), done.
remote: Total 64 (delta 12), reused 64 (delta 12), pack-reused 0 eceiving objects: 100% (64/64)
Receiving objects: 100% (64/64), 124.49 KiB | 2.35 MiB/s, done.
Resolving deltas: 100% (12/12), done.
Cloning into 'MSBuildBinaryLogAnalyzer'...
remote: Enumerating objects: 78, done.
remote: Counting objects: 100% (78/78), done.
remote: Compressing objects: 100% (45/45), done.
Receiving objects: 43% (34/78) d 78 (delta 32), pack-reused 0
Receiving objects: 100% (78/78), 19.41 KiB | 4.85 MiB/s, done.
Resolving deltas: 100% (32/32), done.
Microsoft (R) Build Engine version 16.3.0+0f4c62fea for .NET Core
Copyright (C) Microsoft Corporation. All rights reserved.
Build succeeded.
0 Warning(s)
0 Error(s)
Time Elapsed 00:00:01.24
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\Services\Platform\WBDataSvc\DataSvc\DataSvc.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\DB\DL\Db\WbDb.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\Services\Platform\DataProcessor\DataProcessor.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\Services\Platform\DataManager\DataManager.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\Services\Platform\MemberSession\MemberSession.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\Services\Platform\Common\Common.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\Services\Platform\Data\Data.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\WFM\BridgeDotNet\Xyz.WFM.BridgeDotNet\Xyz.WFM.BridgeDotNet.csproj]
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\\MSBuild\15.0\bin\MSBuild.exe /bl:1.binlog /v:q .\Main.sln
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\WFM\BridgeDotNet\Xyz.WFM.BridgeDotNet\Xyz.WFM.BridgeDotNet.Main.csproj]
CSC : warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. [C:\Users\mkharito
nov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\WFM\BridgeDotNet\Xyz.WFM.BridgeDotNet\Xyz.WFM.BridgeDotNet.Main.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\UI\EngagementSetup\EngagementSetup.csproj]
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\\MSBuild\15.0\bin\MSBuild.exe /bl:2.binlog /v:q .\Main.sln
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\UI\EngagementSetup\EngagementSetup.csproj]
1 Triggers:
C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\UI\EngagementSetup\EngagementSetup.csproj (...\Framework\bin\Debug\AutoMapper.dll vs ...\EngagementSetup\bin\AutoMapper.dll)
1 Recompiled projects:
C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\UI\EngagementSetup\EngagementSetup.csproj (...\Framework\bin\Debug\AutoMapper.dll vs ...\EngagementSetup\bin\AutoMapper.dll)
C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug [master ≡]>
---
C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug [master ≡]> C:\temp\repro\repro.ps1
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\Services\Platform\WBDataSvc\DataSvc\DataSvc.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\DB\DL\Db\WbDb.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\Services\Platform\DataProcessor\DataProcessor.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\Services\Platform\DataManager\DataManager.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\Services\Platform\MemberSession\MemberSession.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\Services\Platform\Common\Common.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\Services\Platform\Data\Data.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\WFM\BridgeDotNet\Xyz.WFM.BridgeDotNet\Xyz.WFM.BridgeDotNet.csproj]
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\\MSBuild\15.0\bin\MSBuild.exe /bl:1.binlog /v:q .\Main.sln
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\WFM\BridgeDotNet\Xyz.WFM.BridgeDotNet\Xyz.WFM.BridgeDotNet.Main.csproj]
CSC : warning CS8021: No value for RuntimeMetadataVersion found. No assembly containing System.Object was found nor was a value for RuntimeMetadataVersion specified through options. [C:\Users\mkharito
nov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\WFM\BridgeDotNet\Xyz.WFM.BridgeDotNet\Xyz.WFM.BridgeDotNet.Main.csproj]
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\UI\EngagementSetup\EngagementSetup.csproj]
Microsoft (R) Build Engine version 15.9.21+g9802d43bc3 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program Files (x86)\Microsoft Visual Studio\2017\Enterprise\\MSBuild\15.0\bin\MSBuild.exe /bl:2.binlog /v:q .\Main.sln
Building the projects in this solution one at a time. To enable parallel build, please add the "/m" switch.
CSC : warning CS2008: No source files specified. [C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\UI\EngagementSetup\EngagementSetup.csproj]
1 Triggers:
C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\UI\EngagementSetup\EngagementSetup.csproj (...\Framework\bin\Debug\AutoMapper.dll vs ...\EngagementSetup\bin\AutoMapper.dll)
1 Recompiled projects:
C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug\UI\EngagementSetup\EngagementSetup.csproj (...\Framework\bin\Debug\AutoMapper.dll vs ...\EngagementSetup\bin\AutoMapper.dll)
C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug [master ≡]>
---
C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug [master ≡]> ..\MSBuildBinaryLogAnalyzer\src\MSBuildBinaryLogAnalyzer\bin\Debug\net472\MSBuildBinaryLogAnalyzer.exe -i .\2.binlog -i2 .\1.binlog --json
{
"Triggers": [
{
"ProjectName": "EngagementSetup",
"ProjectPath": "C:\\Users\\mkharitonov\\AppData\\Local\\Temp\\tmp33E9.tmp\\MSBuild15RecompilationBug\\UI\\EngagementSetup\\EngagementSetup.csproj",
"Diff": [
{
"FirstBuild": "\\Framework\\bin\\Debug\\AutoMapper.dll",
"SecondBuild": "\\EngagementSetup\\bin\\AutoMapper.dll"
}
]
}
],
"Recompiled": [
{
"ProjectName": "EngagementSetup",
"ProjectPath": "C:\\Users\\mkharitonov\\AppData\\Local\\Temp\\tmp33E9.tmp\\MSBuild15RecompilationBug\\UI\\EngagementSetup\\EngagementSetup.csproj"
}
]
}
C:\Users\mkharitonov\AppData\Local\Temp\tmp33E9.tmp\MSBuild15RecompilationBug [master ≡]>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment