dotnet / msbuild

The Microsoft Build Engine (MSBuild) is the build platform for .NET and Visual Studio.
https://docs.microsoft.com/visualstudio/msbuild/msbuild
MIT License
5.21k stars 1.35k forks source link

[Unhandled Exception]: "error MSB4166: Child node "2" exited prematurely" caught while ILRepacking #8741

Closed ASPushkin80lvl closed 1 year ago

ASPushkin80lvl commented 1 year ago

Issue Description

I have a project with two files - Sample.csproj and ILRepack.targets. The ILRepack step fails with the error message shown in the issue title

Steps to Reproduce

I have a project with two files - Sample.csproj and ILRepack.targets.

Sample.cspoj:

<Project Sdk="Microsoft.NET.Sdk">

  <PropertyGroup>
    <TargetFrameworks>netstandard20</TargetFrameworks>
    <CopyLocalLockFileAssemblies>true</CopyLocalLockFileAssemblies>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.NETCore.Portable.Compatibility" Version="1.0.2" />
    <PackageReference Include="Autofac" Version="4.6.2" />
    <PackageReference Include="ILRepack.Lib.MSBuild.Task" Version="2.0.18" />
    <PackageReference Include="ILRepack.NETStandard" Version="2.0.4" />
  </ItemGroup>

</Project>

ILRepack.targets:

<?xml version="1.0" encoding="utf-8" ?>
<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <Target Name="ILRepacker" AfterTargets="Build">

    <ItemGroup>
      <InputAssemblies Include="$(TargetPath)"/>
      <InputAssemblies Include="@(ReferencePathWithRefAssemblies)" Condition="'%(filename)' == 'Autofac'" />
    </ItemGroup>

    <ILRepack InputAssemblies="@(InputAssemblies)" OutputFile="$(TargetPath)" LibraryPath="$(OutputPath)" />

  </Target>

</Project>

I am building this project in Visual Studio and get the following error:

    Target ILRepacker:
      Task "ILRepack"
        Added assembly 'D:\Sample\bin\Release\netstandard20\Sample.dll'
        Added assembly 'C:\Users\aleksandrs.jakovlevs\.nuget\packages\autofac\4.6.2\lib\netstandard1.1\Autofac.dll'
        Merging 2 assembies to 'D:\Sample\bin\Release\netstandard20\Sample.dll'
        MSBUILD : error MSB4166: Child node "2" exited prematurely. Shutting down. Diagnostic information may be found in files in "C:\Users\aleksandrs.jakovlevs\AppData\Local\Temp\MSBuildTempAleksandrs.Jakovlevs\" and will be named MSBuild_*.failure.txt. This location can be changed by setting the MSBUILDDEBUGPATH environment variable to a different directory.

Actual Behavior

No file appears in the folder mentioned in the error message. If I remove reference to Microsoft.NETCore.Portable.Compatibility from csproj file or set CopyLocalLockFileAssemblies to false or remove LibraryPath="$(OutputPath)" from ILRepack.targets file, the build succeeds.

Analysis

No response

Versions & Configurations

MSBuild version - 17.5.1.16304 Visual Studio version - Professional 2022 17.5.3

danmoseley commented 1 year ago

If you build with /m:1 I guess there will be no out of proc nodes and you may get a stack in the console.

ASPushkin80lvl commented 1 year ago

@danmoseley

It says Process is terminated due to StackOverflow

ILRepacker:
  Added assembly 'D:\Sample\bin\Debug\netstandard20\Sample.dll'
  Added assembly 'C:\Users\aleksandrs.jakovlevs\.nuget\packages\autofac\4.6.2\lib\netstandard1.1\Autofac.dll'
  Merging 2 assembies to 'D:\Sample\bin\Debug\netstandard20\Sample.dll'
INFO: IL Repack - Version 2.0.18
INFO: ------------- IL Repack Arguments -------------
/out:D:\Sample\bin\Debug\netstandard20\Sample.dll  D:\Sample\bin\Debug\netstandard20\Sample.dll C:\Users\aleksandrs.jakovlevs\.nuget\packages\autofac\4.6.2\lib\netstandard1.1\Autofac.dll
-----------------------------------------------
INFO: Adding assembly for merge: D:\Sample\bin\Debug\netstandard20\Sample.dll
INFO: Adding assembly for merge: C:\Users\aleksandrs.jakovlevs\.nuget\packages\autofac\4.6.2\lib\netstandard1.1\Autofac.dll

Process is terminated due to StackOverflowException.
AR-May commented 1 year ago

Team triage: this seems like a bug in ILRepacker task itself rather than in msbuild. Could you open this issue in their repository instead? It is https://github.com/ravibpatel/ILRepack.Lib.MSBuild.Task. We are closing this bug. If we are wrong and it is somehow caused by MSBuild/dotnet code, please feel free to reopen it again.