Use these settings in the main PropertyGroup in the csproj file to make the smallest, single .exe file possible.
- OutputType =
- TargetFramework =
- PublishSingleFile =
- RuntimeIdentifier =
- SelfContained =
This corresponds to:
dotnet build project.csproj --use-current-runtime --no-self-contained -p:PublishSingleFile=true -o publish
dotnet build project.csproj -r win-x64 --no-self-contained -p:PublishSingleFile=true -o publish
PublishSingleFile will instruct the publisher to combine everything into one single .exe file. RuntimeIdentifier is necessary because it will become a platform-dependent file now. SelfContained defaults to true when we set RuntimeIdentifier, but we actually want SelfContained to be false, because it's okay if we have to install the .NET Core runtime. This strips a lot of megabytes from the resulting file.
Building and publishing is also fast.