Home > other >  Exporting C# Applications to clients - Confusion about imports
Exporting C# Applications to clients - Confusion about imports

Time:11-24

I never really understood the technical requirements for C# applications. I know Windows 10 has some .NET-versions installed by default. But whenever i write a console-application in c# and copy the compiled .exe-file to another computer, the .exe-file never runs (doesnt matter if compiled with net-core or net-framework). It is always missing a lot of dependencies. So I always either have to copy a huge amount of dll-files into the same folder as the .exe-file or publish it as a standalone-application, which is ridicilous huge (130 MB .exe-file for 100-line application which does nothing special at all).

On the other hand i can create a windows-service, compile it and use it. The compiled service-exe is very small (around 30 kb) and can be installed via cmd.exe ("sc create [...]"). I tested this on a windows 10 VM. It runs without problems.

Am I getting everything right? Why can windows-services run without the .dll-files, but console-applications can not? Since Windows 10 has a lot of .net-applications installed, i would assume every c# application should run on windows 10 without having to add the .dll-files.

CodePudding user response:

If the target computer doesn't have the .Net runtime you are targeting installed, you have two options:

  1. Install the runtime, then run the app.
  2. Bundle the runtime with the app, either as separate files or all within the same exe.

Option 2 is only available for .Net Core and .Net 5 and higher. For .Net Framework (4 and lower) you must choose option 1.

You can detect what versions of Framework are installed by looking at some registry values: https://docs.microsoft.com/en-us/dotnet/framework/migration-guide/how-to-determine-which-versions-are-installed

.Net Framework 4.6.1 is included in Windows 10 (I think base but also version 1511). Source. This is why your Windows Service ran just fine without you needing to do anything.

You can install the .Net Core/5 runtime from https://dotnet.microsoft.com/ so that you don't need to include the runtime with the binaries, if you wish.

  • Related