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

0
=
0
+
0
No specific Bitcoin Bounty has been announced by author. Still, anyone could send Bitcoin Tips to those who provide a good answer.
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
=
1
=
$0.25
1 tip with total amount of 3.1999998 mBTC($0.25 USD) have been sent by alex
  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.

SEND BITCOIN TIPS
User rating:

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

1

Too many commands? Learning new syntax?

FavScripts.com is a free tool to save your favorite scripts and commands, then quickly find and copy-paste your commands with just few clicks.

Boost your productivity with FavScripts.com!

Post Answer