
After extraction, the self-extracted archive starts a new process with the first embedded file (e.g., open a readme file, run post-extraction action.). The 'Run first item after extraction' option defines the RUN_1ST_ITEM symbol that enables a piece of code in the SelfExtractor.cs file. Using (SelfExtractor archive = new SelfExtractor())Īrchive.CompileArchive(saveFileDialog1.FileName, checkBox1.Checked) Drop some files on the form and click the bottom-right button to create a self-extracted archive:
It demonstrates the dynamic creation of assemblies with embedded resources. The self-extracted archive compiler (see screenshot above) is provided as an example.
The SelfExtractor.cs file contains the source code built by the SelfExtractor class to generate the standalone executable. The SelfExtractor class in ArchiveCompiler.cs contains the logic to build a standalone executable with selected files embedded as resource. The ArchiveCompiler.Demo namespace contains the demo project. Since the script-driven testing tool is not a suitable demonstration application, I looked for something else and the self-extractor compiler is the first idea that came across my mind. I found the result interesting enough to share it with you. I finally came up with the solution described in this article. I decided to package the script file and all its dependencies into the executable script engine as embedded resources. To make the job of validation users easier, advanced users should be able to deploy their scripts as standalone executables. Advanced users edit script files and validation users run scripts. The tool is used both by advanced users and by validation users. Why embed resources into an existing executable file at runtime? I was working on a script-driven testing tool. It also shows how to compress files using the. This article shows how to embed resources at runtime by creating dynamic assemblies. When you need to add resources at runtime, you are just alone. In that case, the Resource Designer is helpless. But, the resources might not be available at design-time: consider a scenario where the user provides some pictures to be embedded into a slideshow application.
The Resource Designer allows you to add/edit resources in an assembly at design-time. Visual Studio comes up with a user interface tool to manage resources.