Commit 2ab9203
Output MSBuild errors when publishing (#7566)
## Summary of changes
We saw the following error in our CI:
```
01:59:31 [INF] > "C:\Program Files\dotnet\dotnet.exe" publish c:\mnt\tracer\src\Datadog.Trace.MSBuild\Datadog.Trace.MSBuild.csproj --configuration Release --framework net461 --no-restore --no-build --output c:\mnt\shared\bin\monitoring-home\net461 /property:Platform=AnyCPU
01:59:34 [ERR] MSBUILD : error MSB4166: Child node "3" exited prematurely. Shutting down. Diagnostic information may be found in files in "C:\Users\ContainerAdministrator\AppData\Local\Temp\MSBuildTemp\" and will be named MSBuild_*.failure.txt. This location can be changed by setting the MSBUILDDEBUGPATH environment variable to a different directory.
01:59:34 [ERR] Target PublishManagedTracer has thrown an exception
```
In order to diagnose the actual error generated from MSBUILD, we are
checking for these MSBuild_*.failure.txt files and printing them into
the logs.
Potentially, these logs could be generated in any MSBUILD call. Since we
have only seen this in PublishManagedTracer, in this PR we are only
checking for error files in that task, but it could easily be added to
any other compilation or publishing task.
## Reason for change
## Implementation details
## Test coverage
We can force an intentional crash by using this target file and using
these properties: /p:CrashDuringBuild=true
/p:CustomBeforeMicrosoftCommonTargets="Crash.targets"
```
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
<UsingTask TaskName="CrashNow"
TaskFactory="RoslynCodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
<Task>
<Using Namespace="System" />
<Code Type="Fragment" Language="cs"><![CDATA[
Environment.FailFast("Intentional crash for MSBuild failure-file test");
return true; // not reached
]]></Code>
</Task>
</UsingTask>
<!-- Fire before Build/Publish, but only when asked AND only for the target project -->
<Target Name="CrashIfEnabled"
BeforeTargets="Build;Publish;CoreCompile"
Condition="'$(CrashDuringBuild)'=='true' and '$(MSBuildProjectName)'=='Datadog.Trace'">
<Message Text="Crashing MSBuild worker for $(MSBuildProjectName)..." Importance="high" />
<CrashNow />
</Target>
</Project>
```
## Other details
<!-- Fixes #{issue} -->
<!-- 1 parent bef226e commit 2ab9203
2 files changed
+82
-11
lines changed| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
52 | 52 | | |
53 | 53 | | |
54 | 54 | | |
| 55 | + | |
55 | 56 | | |
56 | 57 | | |
57 | 58 | | |
| |||
794 | 795 | | |
795 | 796 | | |
796 | 797 | | |
797 | | - | |
798 | | - | |
799 | | - | |
800 | | - | |
801 | | - | |
802 | | - | |
803 | | - | |
804 | | - | |
805 | | - | |
806 | | - | |
807 | | - | |
| 798 | + | |
| 799 | + | |
| 800 | + | |
| 801 | + | |
| 802 | + | |
| 803 | + | |
| 804 | + | |
| 805 | + | |
| 806 | + | |
| 807 | + | |
| 808 | + | |
| 809 | + | |
| 810 | + | |
| 811 | + | |
| 812 | + | |
| 813 | + | |
| 814 | + | |
| 815 | + | |
| 816 | + | |
| 817 | + | |
| 818 | + | |
808 | 819 | | |
809 | 820 | | |
810 | 821 | | |
| |||
| Original file line number | Diff line number | Diff line change | |
|---|---|---|---|
| |||
| 1 | + | |
| 2 | + | |
| 3 | + | |
| 4 | + | |
| 5 | + | |
| 6 | + | |
| 7 | + | |
| 8 | + | |
| 9 | + | |
| 10 | + | |
| 11 | + | |
| 12 | + | |
| 13 | + | |
| 14 | + | |
| 15 | + | |
| 16 | + | |
| 17 | + | |
| 18 | + | |
| 19 | + | |
| 20 | + | |
| 21 | + | |
| 22 | + | |
| 23 | + | |
| 24 | + | |
| 25 | + | |
| 26 | + | |
| 27 | + | |
| 28 | + | |
| 29 | + | |
| 30 | + | |
| 31 | + | |
| 32 | + | |
| 33 | + | |
| 34 | + | |
| 35 | + | |
| 36 | + | |
| 37 | + | |
| 38 | + | |
| 39 | + | |
| 40 | + | |
| 41 | + | |
| 42 | + | |
| 43 | + | |
| 44 | + | |
| 45 | + | |
| 46 | + | |
| 47 | + | |
| 48 | + | |
| 49 | + | |
| 50 | + | |
| 51 | + | |
| 52 | + | |
| 53 | + | |
| 54 | + | |
| 55 | + | |
| 56 | + | |
| 57 | + | |
| 58 | + | |
| 59 | + | |
| 60 | + | |
0 commit comments