I have just read an article about Self-Contained Single file apps in .NET 5. It's a kind of deployment option which allows me to create a single file which consists of:
- Native executable launcher
- .NET runtime
- .NET libraries
- {your_app} dependencies
Is this single file app pointed to a specific platform? I guess yes, because it should contain a version of a runtime specific to platform and the application should be compiled by using the architecture of the target machine. Am I right? Does it mean that I should know the target platform (Windows, Linux, MacOs), machine architecture before delivering my self-contained single file apps?
CodePudding user response:
The single file self-contained executable is very very specific. It is specific to your Operating System (Linux, macOS or Windows). It is also specific to your architecture (arm64, x64, etc). If you build for win-x64
(Windows x64) it will not work on linux-x64
(Linux x64) and it will also not work on linux-arm64
(Linux Arm 64).
You should know exactly what OS and architecture you are targeting to create a self-contained single file executable that will work there.
You could, of course, compile a single application multiple times, each time creating a single-file application specific to an OS/Architecture combination. Then your users could pick the single file executable that corresponds to their OS/Architecture. To do this, you just need to adjust your dotnet publish
command; you don't need to redesign/re-architect your application (assuming it's not somehow tied to an OS/Architecture already).