Answer the question
In order to leave comments, you need to log in
How to compile a C# project into one .exe file?
Hello.
I wrote a simple C# console application for Windows.
There is a task to compile a small project into 1 .exe file. That is, hide the .dll files that are created after compilation.
Most of the "google" does not work (articles from 2001-2012). I think the issue is relevant.
What means do you use?
Answer the question
In order to leave comments, you need to log in
Single File Application - a feature of modern dotnets since .net Core 3
Literally, with the help of one option in the project file or one line in the console, it assembles your project into a single executable, which can also optionally have a built-in runtime.
Here is an example csproj:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>net6.0</TargetFramework>
<Nullable>enable</Nullable>
</PropertyGroup>
<PropertyGroup>
<!-- Вот это самое главное -->
<PublishSingleFile>true</PublishSingleFile>
<!-- Это чтобы тащить за собой рантайм До .NET 6 будут рядом лежать нативные библиотеки jit-а и сборщика мусора-->
<SelfContained>true</SelfContained>
<!-- Это необходимо, чтобы сборщик понимал, для какой ОС нужен экзешник -->
<RuntimeIdentifier>win-x64</RuntimeIdentifier>
<!-- Это чтобы ускорить запуск -->
<PublishReadyToRun>true</PublishReadyToRun>
<!-- Эти две строки, чтобы уменьшить размер бинарника -->
<PublishTrimmed>true</PublishTrimmed>
<TrimMode>link</TrimMode>
</PropertyGroup>
</Project>
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question