0

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?

Joseph Katzman
  • 1,959
  • 6
  • 21
  • 47
  • Does this answer your question? [Can't get costura.fody to embed dll into exe](https://stackoverflow.com/questions/68502368/cant-get-costura-fody-to-embed-dll-into-exe) – Martin Sep 21 '21 at 22:02
  • 2
    "Single-file apps are always OS and architecture-specific. You need to publish for each configuration, such as Linux x64, Linux ARM64, Windows x64, and so forth", it couldn't be clearer from https://learn.microsoft.com/en-us/dotnet/core/deploying/single-file – Lex Li Sep 22 '21 at 04:42

1 Answers1

1

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).

omajid
  • 14,165
  • 4
  • 47
  • 64
  • How it can be architecture-specific if the compiled app that we deliver contains IL code which is architecture-agnostic? As far as I remember the JIT compiler is responsible for compiling IL code to machine native instructions. Does it means that the built-in .NET Runtime contains JIT compiler? – Joseph Katzman Sep 23 '21 at 14:06
  • A single-file app isn't IL. It's the **entire** runtime (CLR, Libraries and more), and your app, which might even be precompiled. The runtime contains everything needed to run your application. It includes many components, including the JIT, but also things that let you talk to the OS/hardware via the .NET APIs. Even if you leave out your app, the runtime is very OS/Architecture specific. – omajid Sep 23 '21 at 16:24
  • 1
    If you want more details about the .NET runtime, the [Book of the Runtime](https://github.com/dotnet/runtime/blob/main/docs/design/coreclr/botr/intro-to-clr.md) is a great resource. – omajid Sep 23 '21 at 16:25