Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is it possible to create a standalone executable with net-core?

When I run the command:

dotnet build -c Release

I get the program and necessary dlls of my project, however for the program to work on another computer I have to install computer to computer the .NET Core Runtime:

  • https://dotnet.microsoft.com/download/dotnet-core/current/runtime

Would it be possible to create a standalone program for Windows?

like image 836
Guilherme Nascimento Avatar asked Oct 22 '25 18:10

Guilherme Nascimento


1 Answers

To create a self-contained executable, you should use dotnet publish. For example:

dotnet publish -r win-x64 -c release

If you are using .NET Core 3, you can also trim a lot of these libraries out by adding the PublishTrimmed property to your csproj file, for example:

<Project Sdk="Microsoft.NET.Sdk">
  <PropertyGroup>
    <OutputType>Exe</OutputType>
    <TargetFramework>netcoreapp3.0</TargetFramework>
    <PublishTrimmed>true</PublishTrimmed>
  </PropertyGroup>
</Project>

Provided your app doesn't call any of the framework libraries using reflection (i.e. the dotnet command is unable to figure out you need one of the libraries it trims out), your output will be much smaller.

like image 169
DavidG Avatar answered Oct 24 '25 08:10

DavidG



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!