Go to → Solution explorer → Right click on your project → Properties. One Project window will display like below. Click on application tab and set your application name icon etc.
Something like ILMerge perhaps?
There's even a GUI
Note: I haven't actually tried either of them.
There is the Costura.Fody add on, and this compiles everything into a single exe that doesn't require installation. It can be installed via nuget, however the latest version of nuget will prevent the FodyWeavers.xml file from being created, so this needs to be done manually.
Found the perfect answer finally
Going to post the whole page without a picture because the page is so old I'm afraid it will be deleted.
For me, I didn't bother making the references "do not copy". Also, I completely skipped stepped 4 since I couldn't add them. I wonder if it has to do with it already being added by Nuget Manager.
In the end, I could just pluck out the exe file and run it anywhere from my HDD.
Copied from the link above:
A while back I was working on a small C# WinForms application in Visual Studio 2008. For the sake of simplifying the deployment process of the application, having all of its components bundled up into one exe file would make it much easier to manage. But–documentation and tutorials on embedding dll files within an exe file were outdated, incomplete, or simply didn’t work.
The best example out of the lot was an excerpt from a book, posted on an MSDN blog by its author. Unfortunately, it didn’t work as presented and didn’t include clear instructions on how or where to implement it. However, it still offered a very good starting point. After some research, trial, and error, and with the help of the Visual Studio debugger, here’s the solution.
Note: This method allows you to place dll files into any subfolder or series of subfolders within your project without needing to change any code after the fact. If you wish to forgo the use of a subfolder (placing the dll files in the project root), or use a hard-coded path to your subfolder(s) containing the dll files instead, there are alternative methods which would be more appropriate, but won’t be covered here.
The dll files themselves need to be embedded in the Visual Studio project, rather than just referenced. In your project, create a folder in the project’s root to store the dll files (right-click on the project name > add > new folder). I named mine “lib”.
Copy and paste your dll (and any accompanying support or definition files) into the lib folder. For purposes of this tutorial, the example dll used will be Cassia.
Next, include the dll as a project resource. Right-click on the project name > properties (or Project menu > yourprojectname Properties). Go to the “Resources” tab.
Select “Files”, as shown here:
Click “Add Resource”, change the file type to “all files”, and navigate to the “lib” file where your dll is located. Select it and click “Open”.
The dll file should now be included as a project resource:
Add a reference to the dll file in the project. In the Solution Explorer pane, right-click on “References” > Add Reference (Or, Project menu > Add Reference). Click the Browse tab, navigate to the lib folder where the dll is located, select the dll file, and click “Ok”. A reference to your dll will then appear under the references folder in your project.
By default, compiled files and project references are copied to the bin folder when the project is built. This will need to be prevented. Under the “References” folder, select the reference to your dll file. In the properties pane (or right-click > properties), look for the attribute named “Copy to output directory”, and set the value to false.
Next, select the dll file under the “lib” folder. In the properties pane, look for the attribute “copy to output directory” and set the value to “Do not copy”.
Also look for the attribute “Build Action” and set the value to “Embedded Resource”. This indicates how the file will be treated and accessed when the project is built.
Lastly, exclude extraneous files accompanying the dll file, such as help files and XML definitions files–they are not needed in the project when it is built. Right-click on the file (such as the XML definitions file) and click “Exclude From Project”. Now it will not be copied to the bin folder when the project is built.
In the code view for your executing WinForm, include the namespace System.Reflections. This is important for some of the code responsible for loading your embedded dll file(s).
In the code view for your executing WinForm, this code should be placed in the constructor method (usually named the same as the form). It needs to appear before the InitializeComponent() method: ``` AppDomain.CurrentDomain.AssemblyResolve += (sender, args) => { string resourceName = new AssemblyName(args.Name).Name + ".dll"; string resource = Array.Find(this.GetType().Assembly.GetManifestResourceNames(), element => element.EndsWith(resourceName));
using (var stream = Assembly.GetExecutingAssembly().GetManifestResourceStream(resource)) { Byte[] assemblyData = new Byte[stream.Length]; stream.Read(assemblyData, 0, assemblyData.Length); return Assembly.Load(assemblyData); } }; ```
Upon launching the exe, this code is responsible for detecting what dll files are needed and are being referenced, and load them from their embedded location.
In the code view for your executing WinForms application, you can now include the dll file’s namespace(s).
In order to test everything, you will need to implement code from the dll file’s namespace(s), so that the AssemblyResolve event is triggered. However, if you include code from the dll’s namespace(s) within the constructor, Application.Run() will throw a “file not found” error for your dll file when the WinForms application is built and executed.
To correct this, you will need to place any code using the dll file namespace(s) in another method outside of constructor method. This is because the event handler for the assembler cannot be located within the same method that is calling it. It’s simple enough to do, but it’s just one caveat to be aware of.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With