Combine the compiled DLL with EXE

David McDivitt 186 Reputation points
2022-01-18T14:29:34.81+00:00

For VB programs, upon changing from .Net 4.x to 5 or 6, Visual Studio makes a DLL to accompany the EXE file. That does not work for me because two files must be distributed instead of one and that's a management nightmare. Is there a way to produce just one file?

VB
VB
An object-oriented programming language developed by Microsoft that is implemented on the .NET Framework. Previously known as Visual Basic .NET.
1,983 questions
No comments
{count} votes

Accepted answer
  1. Michael Taylor 41,431 Reputation points
    2022-01-18T16:43:34.16+00:00

    Yes and no. Historically with .NET Core (from which 5/6 comes) everything was a DLL that was then run by using dotnet. But that is no longer necessary because you can publish self contained binaries. You should read up on the publishing options though as there are plusses and minuses. Ultimately having an extra DLL shouldn't be a big deal as most likely you'll have other dependencies as well and therefore already have DLLs in your app. We haven't been producing single EXE binaries in years given the complexity of a modern app and the fact we generally have configuration files as well.

    But if you really want a single binary then publish as a self contained binary. This produces a single EXE targeting a very specific platform (Windows x86 or Windows x64 for example). You don't need anything else as all the runtime pieces are part of the EXE. The downside to this is that you can only run it on that platform because EXEs are specific to the platform they run on. Hence you won't be able to take your app and run it on Linux directly without republishing it.

    With the traditional approach your code is in the DLL and is platform agnostic. The EXE that is produced is a stub that simply allows your users to run your app which then loads your DLL and goes. On other platforms they wouldn't use the EXE and instead the DLL would be run using the platform-specific host. Hence you compile once and run anywhere. Of course this also requires that the user have the appropriate framework version installed as well.

    Ultimately it is up to you to decide how to publish your app but xcopy style deployments of folders of binaries, configurations, assets, etc is pretty standard. Therefore the framework dependent approach is generally the best.


0 additional answers

Sort by: Most helpful