Make your code cross-platform
The beauty of .NET is that it is cross-platform. The IL runs almost everywhere. If you build an application, it will work on your Windows and Linux machines.
Running an exe on Linux?
No, you cannot run your Windows exe
on Linux. An EXE file is a typical Windows construct. The file layout is specific to that platform, and Linux systems have another way to handle executables. However, the compiler also produces a DLL file if you build your system. That file can be run with the dotnet
command. So, if your system is called MyAwesomeApp.exe
, you will also find a MyAwesomeApp.dll
in the Build
directory. On all supported platforms, you can run your application using the dotnet MyAwesomeApp.dll command
, which works on Windows and Linux.
But that doesn’t mean you can copy your binaries, run them, and expect everything to work fine. There are some caveats you should be aware of. But don’t worry – we’ll cover them one by one here...