In .NET Core 3.0, the support for single-file applications is added.
Publishing to a single file can be triggered by adding the following property to an application's project file:
<PropertyGroup>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
PublishSingleFile
property applies to both frameworks dependent and self-contained publish operations.PublishSingleFile
property applies to platform-specific builds for a given runtime-identifier.PublishSingleFile
is set to true
, it is an error to leave RuntimeIdentifier
undefined, or to set UseAppHost
to false
.PublishSingleFileproperty
causes the managed app, managed dependencies, platform-specific native dependencies, configurations, etc. to be embedded within the native apphost.By default, the symbol files are not embedded within the single-file but remain as separate files in the publish directory. This includes both the IL .pdb
file, and the native .ni.pdb
/ app.guid.map
files generated by ready-to-run compiler. Setting the following property causes the symbol files to be included in the single-file.
<PropertyGroup>
<IncludeSymbolsInSingleFile>true</IncludeSymbolsInSingleFile>
</PropertyGroup>
Certain files can be explicitly excluded from being embedded in the single-file by setting following meta-data:
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
For example, to place some files in the publish directory but not bundle them in the single-file:
<ItemGroup>
<Content Update="*.xml">
<CopyToPublishDirectory>PreserveNewest</CopyToPublishDirectory>
<ExcludeFromSingleFile>true</ExcludeFromSingleFile>
</Content>
</ItemGroup>
The dotnet publish
command supports packaging your app into a platform-specific single-file executable.
To publish a single-file executable, set the PublishSingleFile
in your project file as shown below.
<PropertyGroup>
<RuntimeIdentifier>win10-x64</RuntimeIdentifier>
<PublishSingleFile>true</PublishSingleFile>
</PropertyGroup>
Or you can run the dotnet publish
from the command line as shown below.
dotnet publish -r win10-x64 -p:PublishSingleFile=true