dotnet / runtime

.NET is a cross-platform runtime for cloud, mobile, desktop, and IoT apps.
https://docs.microsoft.com/dotnet/core/
MIT License
15.47k stars 4.76k forks source link

net7 - Build freezes when publishing trimmed app with net6+ class libraries #87220

Closed michaldobrodenka closed 1 year ago

michaldobrodenka commented 1 year ago

I have a sln which contains several class libraries and one executable cmdline csproj. I'm modernizing whole solution, removing mono/net461 executable, upgrading class libraries from netstandard20 to net7. When publishing my app with parameters:

dotnet publish my.csproj -r linux-arm -p:PublishTrimmed=True -p:TrimMode=partial --self-contained true -c Release -f net7.0

and one specific csproj of my class libraries is set to net7.0 build freezes. on line C:\Program Files\dotnet\dotnet.exe exec "C:\Program Files\dotnet\sdk\7.0.101\Roslyn\bincore\csc.dll" ... Freezing means than NET host process takes almost all cpu, a several Gigs of RAM.

To "unfreeze" build I have to:

Building it on Windows 10,11 and in linux docker.

What I've tried and didn't help:

Unfortunately project is closed source. But I can run some test, access my desktop remotely or something like that.

ghost commented 1 year ago

@dotnet/linker-contrib a new issue has been filed in the ILLink area, please triage

matheusavi commented 1 year ago

Same issue building on al2! I needed to set an 8gb machine to build a small project using AOT.

michaldobrodenka commented 1 year ago

I couldn't finish build even after several hours.

biste5 commented 1 year ago

for us, our Blazor WASM project builds in about 4 minutes with .NET 6 or without trimming, 1+ hour with .NET 7 and trimming

michaldobrodenka commented 1 year ago

Maybe I could try to wait more than 6 hours. In net6 it is build within 100seconds.

michaldobrodenka commented 1 year ago

Waiting 10hours didn't help. I've attached to running csc.

2 tasks are blocked here: image

michaldobrodenka commented 1 year ago

image

michaldobrodenka commented 1 year ago

The same issue with sdk 7.0.200. Last version I was able to build my project with was something like net7 Preview7

michaldobrodenka commented 1 year ago

image

michaldobrodenka commented 1 year ago

still hangs up in net8 preview1

michaldobrodenka commented 1 year ago

I have a strong suspicion it's somehow connected to using netstanrard2.1 libraries in solution

michaldobrodenka commented 1 year ago

I have a strong suspicion it's somehow connected to using netstanrard2.1 libraries in solution

it's not about netstandard2.1. It was just that net8 Preview 1 could not trim netstd2.1 libs.

Still reproducible in latest 7.0.4 & 8P2

michaldobrodenka commented 1 year ago

Ok, I found a little workaround - when all referenced csprojs are net5 or lower, main project (net6.0, net7.0) builds normally with net7 SDK. So I can use features later than netstandard2.1, just not latest one - 6/7.

sbomer commented 1 year ago

@michaldobrodenka this is likely the same issue as https://github.com/dotnet/runtime/issues/86379. Are you able to try building your project with the latest nightly 8.0 SDK available at https://github.com/dotnet/installer/? We are also planning to backport the fix into an upcoming 7.0 servicing release.

ghost commented 1 year ago

Tagging subscribers to this area: @agocke, @sbomer, @vitek-karas See info in area-owners.md if you want to be subscribed.

Issue Details
I have a sln which contains several class libraries and one executable cmdline csproj. I'm modernizing whole solution, removing mono/net461 executable, upgrading class libraries from netstandard20 to net7. When publishing my app with parameters: `dotnet publish my.csproj -r linux-arm -p:PublishTrimmed=True -p:TrimMode=partial --self-contained true -c Release -f net7.0 ` and one specific csproj of my class libraries is set to net7.0 build freezes. on line `C:\Program Files\dotnet\dotnet.exe exec "C:\Program Files\dotnet\sdk\7.0.101\Roslyn\bincore\csc.dll" ... ` Freezing means than NET host process takes almost all cpu, a several Gigs of RAM. To "unfreeze" build I have to: - remove trimming ( `-p:PublishTrimmed=True -p:TrimMode=partial` ) - without trimming build is completed in 20sec - set this one library to netstandard20 and build with net7 SDK - set all csproj files in solution to net6 and build in net6 SDK - net6 build completes in about a minute without problems Building it on Windows 10,11 and in linux docker. What I've tried and didn't help: - build with MS net7 SDK docker - build for different runtimes - linux-x64, win-x64, linux-arm... - SDK 7.0.100 and 7.0.101 Unfortunately project is closed source. But I can run some test, access my desktop remotely or something like that.
Author: michaldobrodenka
Assignees: -
Labels: `untriaged`, `area-Tools-ILLink`, `needs-area-label`
Milestone: -
michaldobrodenka commented 1 year ago

@sbomer I've tried to build it with latest nighly, but seems that I can't get versions or something right: image

Maybe I'll wait for next official net8 Preview/net7 and retest it.

michaldobrodenka commented 1 year ago
 Version:   8.0.100-preview.6.23307.25
 Commit:    f98e016a22

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\8.0.100-preview.6.23307.25\

.NET workloads installed:
There are no installed workloads to display.

Host:
  Version:      8.0.0-preview.6.23307.4
  Architecture: x64
  Commit:       54dab738de

.NET SDKs installed:
  2.1.800 [C:\Program Files\dotnet\sdk]
  6.0.402 [C:\Program Files\dotnet\sdk]
  7.0.200 [C:\Program Files\dotnet\sdk]
  7.0.400-preview.23225.8 [C:\Program Files\dotnet\sdk]
  8.0.100-preview.6.23307.25 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 8.0.0-preview.6.23307.4 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 8.0.0-preview.6.23307.4 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 6.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.16 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.3 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.5 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 8.0.0-preview.6.23307.1 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
michaldobrodenka commented 1 year ago

Ok, after clearing nuget local cache, I'm able to start build, still freezes, but there is a problem with ILLink task version

image

warning NU1603: TapHome.Core.Translations depends on Microsoft.NET.ILLink.Tasks (>= 7.0.100-1.23211.1) but Microsoft.NET.ILLink.Tasks 7.0.100-1.23211.1 was no t found. An approximate best match of Microsoft.NET.ILLink.Tasks 8.0.0-preview.2.23128.3 was resolved.

Maybe I should add ILLink task nuget?

sbomer commented 1 year ago

@michaldobrodenka thanks for giving it a try. For the nightly SDKs you'll need to add nuget feeds mentioned under https://github.com/dotnet/installer#installers-and-binaries. For projects using the illink analyzer targeting net7.0 you will need the dotnet7 feed specifically.

michaldobrodenka commented 1 year ago

I tried targeting net8 & latest net8 nightly (Preview6), build is still freezing. I'll retest it within a few weeks

sbomer commented 1 year ago

@michaldobrodenka sorry, I forgot to mention that your project needs to target net8.0 to get the analyzer fix, at least until we make the servicing fix (https://github.com/dotnet/linker/pull/3217). And note that you should be able to work around this by setting <EnableTrimAnalyzer>false</EnableTrimAnalyzer>. Then you won't see trim compatibility warnings at build time, but you can instead rely on the warnings produced when publishing.

michaldobrodenka commented 1 year ago

7.0.9 - still freezes <EnableTrimAnalyzer>false</EnableTrimAnalyzer> - to one of the libraries and it builds ok!

sbomer commented 1 year ago

Thanks for checking! Looks like the servicing fix should ship with 7.0.10.

agocke commented 1 year ago

This should be fixed. Newly discovered problems are likely new issues.

michaldobrodenka commented 1 year ago

This should be fixed. Newly discovered problems are likely new issues.

Is the fix merged in 7.0.10? Because I tried it and build still hangs without <EnableTrimAnalyzer>false</EnableTrimAnalyzer> in one of the libraries

.NET SDK:
 Version:   7.0.400
 Commit:    73bf45718d

Runtime Environment:
 OS Name:     Windows
 OS Version:  10.0.19045
 OS Platform: Windows
 RID:         win10-x64
 Base Path:   C:\Program Files\dotnet\sdk\7.0.400\

Host:
  Version:      7.0.10
  Architecture: x64
  Commit:       a6dbb800a4

.NET SDKs installed:
  6.0.400 [C:\Program Files\dotnet\sdk]
  7.0.400-preview.23330.10 [C:\Program Files\dotnet\sdk]
  7.0.400 [C:\Program Files\dotnet\sdk]

.NET runtimes installed:
  Microsoft.AspNetCore.App 6.0.19 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.AspNetCore.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.AspNetCore.App]
  Microsoft.NETCore.App 6.0.19 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.NETCore.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.NETCore.App]
  Microsoft.WindowsDesktop.App 5.0.6 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 6.0.19 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.8 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]
  Microsoft.WindowsDesktop.App 7.0.10 [C:\Program Files\dotnet\shared\Microsoft.WindowsDesktop.App]

Other architectures found:
  arm64 [C:\Program Files\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\arm64\InstallLocation]
  x86   [C:\Program Files (x86)\dotnet]
    registered at [HKLM\SOFTWARE\dotnet\Setup\InstalledVersions\x86\InstallLocation]

Environment variables:
  Not set

global.json file:
  Not found

Learn more:
  https://aka.ms/dotnet/info

Download .NET:
  https://aka.ms/dotnet/download
sbomer commented 1 year ago

@michaldobrodenka thank you for following up. I confirmed that the fix shipped in the 7.0.10 servicing release (7.0.400 SDK), so this sounds like a different bug. Is there any way you could provide us with a repro, perhaps a simplified bit of code from the library that exhibits the hang?

If you're unable to share due to the license, please contact me at svbomer at microsoft.com to discuss.