wpf icon indicating copy to clipboard operation
wpf copied to clipboard

The executable file is too large after build

Open maihcx opened this issue 3 weeks ago • 2 comments

Description

I use dotnet publish with SelfContained=false and PublishSingleFile=true options and noticed that when I update to .net10 the file size after build is very large compared to .net9

Reproduction Steps

I use this bat command to build

@echo off
setlocal enabledelayedexpansion
echo ================================
echo   Building TrackingRTF Project
echo ================================

set OUTPUT_DIR=.\publish

REM Danh sách các project cần build (thêm project mới vào đây)
set PROJECTS=TrackingRTF TrackingRTF.FoCRTL TrackingRTF.Tray TrackingRTF.Core

REM Tạo thư mục output nếu chưa có
if not exist "%OUTPUT_DIR%" (
    mkdir "%OUTPUT_DIR%"
)

REM Xóa các file exe cũ
echo Cleaning old executables...
for %%P in (%PROJECTS%) do (
    if exist "%OUTPUT_DIR%\%%P.exe" (
        echo Removing old exe: %%P.exe
        del /q "%OUTPUT_DIR%\%%P.exe"
    )
)

REM Build từng project
echo.
echo Starting build process...
echo.

for %%P in (%PROJECTS%) do (
    echo [%%P] Building...
    
    dotnet publish .\%%P\%%P.csproj -c Release -r win-x64 --self-contained false ^
        /p:PublishSingleFile=true ^
        /p:IncludeAllContentForSelfExtract=true ^
        /p:DebugType=None ^
        /p:DebugSymbols=false ^
        -o "%OUTPUT_DIR%"
    
    if !errorlevel! neq 0 (
        echo [%%P] Build FAILED!
        pause
        exit /b !errorlevel!
    )
    
    echo [%%P] Build successful!
    echo.
)

echo ================================
echo   All builds completed!
echo   Output: %OUTPUT_DIR%
echo ================================
pause

Expected behavior

I wish when building with dotnet publish the file size would be improved similar to .net9. Here is a picture to prove it

Image

Actual behavior

this is after i upgraded to .net10

Image

Regression?

This issue does not occur in .net9 and lower versions

Known Workarounds

My current solution is to downgrade to .net9

Impact

No response

Configuration

  • Net 10
  • Windows 11 | Version 25H2 (OS Build 26200.7171)
  • x64
  • I'm not sure

Other information

No response

maihcx avatar Nov 14 '25 02:11 maihcx

The .NET 10 file sizes suggest self-contained build. If that was a change in .NET 10, then I doubt it's WPF specific. Can you check whether this reproduces for simple console application? If so, the issue belongs to https://github.com/dotnet/sdk/

miloush avatar Nov 14 '25 10:11 miloush

I can not repro this issues. My csproj code:

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

  <PropertyGroup>
    <OutputType>WinExe</OutputType>
    <TargetFramework>net10.0-windows</TargetFramework>
    <Nullable>enable</Nullable>
    <ImplicitUsings>enable</ImplicitUsings>
    <UseWPF>true</UseWPF>

    <PublishSingleFile>true</PublishSingleFile>
    <SelfContained>false</SelfContained>
    <RuntimeIdentifier>win-x64</RuntimeIdentifier>
    <IncludeNativeLibrariesForSelfExtract>true</IncludeNativeLibrariesForSelfExtract>
  </PropertyGroup>

  <ItemGroup>
    <PackageReference Include="Microsoft.Extensions.Hosting" Version="10.0.0" />
  </ItemGroup>

</Project>

My dotnet version:

>dotnet --info
.NET SDK:
 Version:           10.0.100
 Commit:            b0f34d51fc
 Workload version:  10.0.100-manifests.355811b7
 MSBuild version:   18.0.2+b0f34d51f

My publish command line:

dotnet publish

My exe file:

Image

lindexi avatar Nov 16 '25 07:11 lindexi

@miloush @lindexi you can download this to try, in here is the builder.bat file

https://github.com/maihcx/DataSphere.git

maihcx avatar Nov 17 '25 01:11 maihcx