# .NET Single File Executable
**.NET executable projects can be published into a single file using `PublishSingleFile` MSBuild property, which allows you to easily distribute the application as a single file. Single-file applications are always OS and architecture-specific.**
**Single file deployment is available for both framework-dependent and self-contained applications.** Single file and self-contained deployment features are independent, meaning that one does not impact the other. For more information about the difference between the two models see [[Shared vs. Self-Contained Dotnet Deployments|Shared vs. Self-Contained .NET Deployments]].
## Running and Extracting Files
**In .NET 5, by default, all .NET assemblies are combined into a single file, and the assembly is started without needing to extract individual files. This is not the case with .NET Core 3.0, where assemblies had to be extracted to a temp directory first.**
Note that any native dependencies are by default still published next to the managed dll, although this behavior can be overridden using `IncludeNativeLibrariesForSelfExtract`. The default was chosen to ensure a good debugging experience, which requires that native files are accessed directly (this is according to the docs, unsure exactly why this is the case).
## Drawbacks
**Some .NET APIs are not compatible with single-file deployments. This also applies to any dependencies your files will have, so if you use single-file deployment more intensive runtime tests are needed.**
**The most common problems are APIs related to dll file paths, and APIs that use relative file paths of other files shipped with the application.**
Here are some examples from .NET docs along with some suggestion for fixes to common problems below.
| API | Behavior with single-file deployment |
| ------------------------------ | ---------------------------------------------------------- |
| `Assembly.Location` | Returns an empty string. |
| `Module.FullyQualifiedName` | Returns a string with the value of or throws an exception. |
| `Module.Name` | Returns a string with the value of `<Unknown>` |
| `Assembly.GetFile` | Throws `IOException`. |
| `Assembly.GetFiles` | Throws `IOException`. |
| `Assembly.CodeBase` | Throws `PlatformNotSupportedException`. |
| `Assembly.EscapedCodeBase` | Throws `PlatformNotSupportedException`. |
| `AssemblyName.CodeBase` | Returns null. |
| `AssemblyName.EscapedCodeBase` | Returns null. |
Fixes to common problems:
- For a safe way of getting the path to the current assembly see [[Getting the Path to Executing Assembly]]
- Consider avoiding similar problems with embedded resources (see [[Accessing Embedded Resources]]).
## MSBuild Properties
| Property | Description |
| -------------------------------------- | --------------------------------------------------------------------------------------- |
| `PublishSingleFile` | Enables single file deployment |
| `IncludeNativeLibrariesForSelfExtract` | Bundle native libraries. They will be extracted to temp before the app is ran. |
| `IncludeAllContentForSelfExtract` | Will cause all files to be extracted before running the app. Matches previous behavior. | | |
(to use these without modifying csproj you can pipe them directly to a dotnet call e.g. `dotnet publish -p PublishSingleFile=true --sc`. `--sc` stands for single-executable).)
## Sources
- [[Single File Application - .NET]]