Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Creating a "portable" .exe (without installer)

I've recently coded a little program to determine numbers in a picture and it is reliant on two libraries I've used. (DLLs)

Since my target computer is not allowed to install programs due to security reasons, I need to create a portable .exe. .NET is installed on the target computer but for some reason VS still does not include the libraries I've used in the exe but instead creates an application folder with a setup.exe, some .DEPLOY files and an application manifest.

I am new to VS and .NET in general so this question could be easy to answer, but I'm asking since I've found nothing useful on StackOverflow neither on google.

like image 228
Daniel Siegel Avatar asked May 03 '16 12:05

Daniel Siegel


3 Answers

You can simply build the application and copy your bin/Debug folder along, but that would still mean you need multiple files.

In order to merge all references into the executable, use ILMerge. Here is some help calling ILMerge.

Basically, after building, you should do something like this:

ilmerge /target:winexe /out:SelfContainedProgram.exe 
    Program.exe ClassLibrary1.dll ClassLibrary2.dll

There is just one file you need to send along.

like image 165
Patrick Hofman Avatar answered Oct 22 '22 02:10

Patrick Hofman


One way to do this is to build your application in Release mode (You can pick from Debug or Release in the drop-down). Then go to C:\Projects\[ProjectName]\[ProjectName]\bin\Release (The location of your project folder may vary). You'll see a bunch of files but all you really need are the DLLs, executable, and the config if you used one. You won't have to do any setup if you keep the necessary files in the application's folder, just copy them all to a folder on the target computer, create a shortcut if you want then you're good to go.

like image 39
PeskyToaster Avatar answered Oct 22 '22 02:10

PeskyToaster


You can just copy all your assemblies into any folder you want. Simply chose "Build" from within Visual Studio and copy the files from bin/debug to your destination-folder.

However you have to ensure that all (relative) paths (if existing) still work as you cannot be sure where the user of your program copies the files to.

like image 2
MakePeaceGreatAgain Avatar answered Oct 22 '22 03:10

MakePeaceGreatAgain