.NET 6 outputs far larger executable than CSC

429 Views Asked by At

When I compile a executable with csc, it takes 4KB. On the other hand, with publish option in visual studio 2022 I get 9.91 MB. Both files can be run on a pc independetly. "Release" version of file in visual studio is much smaller, however isn't standalone. How to get same file size with dotnet?

.pubxml:

<?xml version="1.0" encoding="utf-8"?>
<!--
https://go.microsoft.com/fwlink/?LinkID=208121. 
-->
<Project ToolsVersion="4.0" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <PropertyGroup>
    <Configuration>Release</Configuration>
    <Platform>Any CPU</Platform>
    <PublishDir>bin\Release\net6.0\publish\win-x86\</PublishDir>
    <PublishProtocol>FileSystem</PublishProtocol>
    <TargetFramework>net6.0</TargetFramework>
    <SelfContained>true</SelfContained>
    <RuntimeIdentifier>win-x86</RuntimeIdentifier>
    <PublishSingleFile>True</PublishSingleFile>
    <PublishReadyToRun>False</PublishReadyToRun>
    <PublishTrimmed>True</PublishTrimmed>
  </PropertyGroup>
</Project> 
0

There are 0 best solutions below