-2

As far as I understand .NET concepts, the source code is first translated into an Assembly (IL code+meta data), which is compiled to machine code on the target machine with the CLR's JIT compiler. However I cannot really match these concepts to what I see when working on a C# project. When I build a project I get an .exe file, which I assume is the executable machine code. Where is the IL stored? Can I access it and transfer it to a different platform e.g. to Linux?

To sum up, could somebody correct my understanding and explain the outputs?

D4rlene
  • 31
  • 4
  • More or less. So I misunderstood and the .exe contains the IL code. What happens if I try to run the .exe on a Windows that does not have .NET installed? – D4rlene May 26 '22 at 21:38
  • That depends... .NET Framework built the IL into the .exe file when that was the output, and Windows knew how to load the Framework. .NET Core builds to a .dll file and requires a loader to execute. Earlier versions used dotnet.exe for that, but now the build output includes a stub loader (JonasH referred to this below) by the same name as the .dll file. – madreflection May 26 '22 at 21:42

2 Answers2

1

When I build a project I get an .exe file, which I assume is the executable machine code

This is incorrect. The exe file just contains a small stub that causes the OS to load it in the .net runtime. Or for self contained assemblies I guess it contains the entire runtime. Regardless, the rest of the .exe file is IL-code that will be loaded by the runtime and compiled to machine code.

On linux I think you just invoke the .net runtime directly with you assembly as the argument. I.e. dotnet myAssembly.exe

JonasH
  • 28,608
  • 2
  • 10
  • 23
0

There is no assembly code in .net assemblies.

.Net programs are converted to a .NET Assembly, which is an .exe or .dll that contains intermediate bytecode. See CIL

Visual Studio will place the .NET Assemblies in your project's /bin or /bin/Release). You can change this path.

The dll or .exe are the assembled files which are generated inside the cited folders.

Both files can run on linux as long as the framework version is supported by the plataform.

Full .net framework is only for windows, but mono and core are being ported to linux.

https://learn.microsoft.com/en-us/dotnet/standard/assembly/