17

I have searched for this and there are a number of previous answers but all seem overly complex.

I'm new to C# and Windows development in general (previous Mac developer).

I have written a simple console application in C# using Visual Studio Community edition. My application uses two third party libraries (CommandLineParser and json.NET) added to my project with NuGet from within VS.

All I want to do is build my project as a standalone .exe file that can be simply run from a command prompt without having to worry about the end user having to install lots of DLLs (something that I'm not used to dealing with as a new Windows user). I understand that the end user would need to have the .NET framework installed. Is there an idiot-proof guide to building a single .exe file in my use case?

I can't help but think that this must be a very common problem.

Thanks.

Garry Pettet
  • 8,096
  • 22
  • 65
  • 103
  • 2
    this is indeed common. however, there is no default solution so the problem. i never needed it, but I know of a nuget package called [Fody.Costura](https://github.com/Fody/Costura) which is able to pack your dependencies (dlls and stuff) as resources into the app. Another possibilitiy would be ILMerge which basically does the same – nozzleman Nov 11 '16 at 10:20
  • 7
    You can check this http://stackoverflow.com/questions/189549/embedding-dlls-in-a-compiled-executable – Miguel Nov 11 '16 at 10:20
  • Don't know what version of vs you're using. With vs 2013 you can use the installshield limited edition (free) and it does a great job also. Simple, straight forward gui, right in vs with a guided ui. It'll check for dependencies like .net and install them on the client if needed, etc. You can also configure to add binaries. You end up with a folder and a setup.exe – nocturns2 Nov 11 '16 at 10:57
  • Fody Costura looks to be the solution. Thank you. – Garry Pettet Nov 11 '16 at 12:38
  • This is now possible from .NET Core 3 https://learn.microsoft.com/en-us/dotnet/core/whats-new/dotnet-core-3-0?irgwc=1&OCID=AID2000142_aff_7593_1243925&tduid=%28ir__td9a1mo1gskft13hkk0sohz3xm2xnhd2y9u6pcnk00%29%287593%29%281243925%29%28je6NUbpObpQ-G_lRuhzJba1YviSMaIfjUA%29%28%29&irclickid=_td9a1mo1gskft13hkk0sohz3xm2xnhd2y9u6pcnk00#single-file-executables?ranMID=24542&ranEAID=je6NUbpObpQ&ranSiteID=je6NUbpObpQ-G_lRuhzJba1YviSMaIfjUA&epi=je6NUbpObpQ-G_lRuhzJba1YviSMaIfjUA – Dave Mateer Apr 23 '20 at 13:17
  • If this helps too (to make it smaller is handy!) https://davemateer.com/2020/04/13/NET-Core-Single-Executable-Console-Application – Dave Mateer Apr 23 '20 at 13:18

2 Answers2

7

You can merge the libraries with ILMerge and run it as a post build event in Visual Studio. This will creat one exe with all libraries. You will find some more information about ILMerge here.

Andre Hofmeister
  • 3,185
  • 11
  • 51
  • 74
7

Alternatively if you want to run adhoc test to see that it really works and get it done relatively fast you can try using ILMerge-GUI

I have previously struggled to use ILMerge by itself. With the GUI, it was much faster for me to verify that I can get everything working.

CJC
  • 795
  • 8
  • 25