.NET - compile all DLL dependencies into one standalone portable EXE file for console or a desktop project in Visual Studio

0

I have a small console project in Visual Studio 2010 and I want to build and publish console application as a standalone EXE file or package with a small number of files to be copy-paste deployed if possible.

There is of course an .EXE file with a bunch of .DLL files in ProjDir/bin/Release but this folder contains multiple files(DLLs, config file, resource etc.), and I would prefer to have just one .EXE file if possible.

If anyone knows a good method of how to package .NET application into one executable file, please share!

Thanks!

1 Answer

  1. DLLs: you can combine your multiple libraries into 1 assembly using ILMerge utility.

    ilmerge /target:exe /targetplatform:"v4,C:\Program Files\Reference Assemblies\Microsoft\Framework.NETFramework\v4.0" /out:MyConsoleAppCombined.exe out:MyConsoleApp.exe MyFirstLibrary.dll MySecondLibrary.dll

  2. Resources: Your resources can be stored as Embedded Resources in your assembly. And when your application starts you'll have to grab them from your assembly as Streams:

    Assembly.GetExecutingAssembly().GetManifestResourceStream("MyNamespace.MyImage.bmp");

    Alternatively, especially if you use localization resources in your app, take a look at Satellite Assemblies. They allow you to pack your resources in separate assemblies for different languages and the right assembly is loaded if your app is configured to be used in that language

  3. Config files: If you have to use config files in your app you will have to store them as embedded resources as well and parse them manually in your app. Kind of defeats the purpose of configuration files, since you'll have to update your app to change a configuration setting. I'd rather just hard-code my settings in the app.

User rating:

Thank you! This is very helpful, I personally did not even know about ILMerge utility method

1

Post Answer