Click here to Skip to main content
15,896,269 members
Home / Discussions / C#
   

C#

 
AnswerRe: Save an object to my exe? Pin
Luc Pattyn9-Mar-10 7:09
sitebuilderLuc Pattyn9-Mar-10 7:09 
GeneralRe: Save an object to my exe? Pin
Som Shekhar9-Mar-10 7:26
Som Shekhar9-Mar-10 7:26 
GeneralRe: Save an object to my exe? Pin
Luc Pattyn9-Mar-10 9:42
sitebuilderLuc Pattyn9-Mar-10 9:42 
AnswerRe: Save an object to my exe? Pin
Dave Kreskowiak9-Mar-10 7:32
mveDave Kreskowiak9-Mar-10 7:32 
AnswerRe: Save an object to my exe? Pin
Matthew Klein9-Mar-10 7:44
Matthew Klein9-Mar-10 7:44 
AnswerRe: Save an object to my exe? Pin
#realJSOP9-Mar-10 8:40
professional#realJSOP9-Mar-10 8:40 
AnswerRe: Save an object to my exe? Pin
AspDotNetDev9-Mar-10 12:44
protectorAspDotNetDev9-Mar-10 12:44 
AnswerRe: Save an object to my exe? Pin
AspDotNetDev9-Mar-10 12:57
protectorAspDotNetDev9-Mar-10 12:57 
Now that you know the simple way, I'll describe the harder way.

First, you use the ResourceWriter class to create a resource out of the data you want to be embedded in the EXE.

Next, you use the C# compiler to embed that resource file into an assembly (the assembly is created from some C# code, so you can't just embed it in your primary assembly straight away). What is in the assembly is unimportant, as it will be ignored (you only want the assembly so you can have an assembly with a resource file embedded in it).

Next, you can use ILMerge to combine the assembly you just created with your main assembly.

You can then load that resource at runtime.




Those are most of the tools you'll need to accomplish this task. However, there are a few points you'll need to consider.

For one, you don't want multiple EXE's, so you'll want to make sure to embed the above tools into your main assembly (CSC and ILMerge). To run them, you'd then extract them to a file, run them, then delete them when you are done running them.

Next, combining the generated assembly with your main assembly will increase the size of the main assembly. To prevent it from increasing in size each time you run it, you'll wan to first compile the assembly and then add the assembly as a resource for itself. When you merge the main assembly with the generated one, you'll actually add the main assembly to the resource file you generate, then compile that resource file into a new assembly, then merge that generated assembly with the assembly you export from your resources.

The above ResourceWriter only works with strings. So, when you want to embed EXE's (aka byte arrays) and images and such, you'll need to embed them as strings. That means you'll have to do some parsing and deserializing.

You will have to do some switching of EXE's (i.e., delete the old one and run the new one) as I described in the "simple way" in my previous post.
GeneralRe: Save an object to my exe? Pin
Matthew Klein9-Mar-10 13:23
Matthew Klein9-Mar-10 13:23 
QuestionComparing things with null - but not for equality Pin
harold aptroot9-Mar-10 5:05
harold aptroot9-Mar-10 5:05 
AnswerRe: Comparing things with null - but not for equality Pin
Dan Mos9-Mar-10 5:33
Dan Mos9-Mar-10 5:33 
QuestionCode is Rounding Down instead of Rounding Up Pin
suprsnipes9-Mar-10 4:15
suprsnipes9-Mar-10 4:15 
GeneralRe: Code is Rounding Down instead of Rounding Up Pin
harold aptroot9-Mar-10 4:20
harold aptroot9-Mar-10 4:20 
AnswerRe: Code is Rounding Down instead of Rounding Up Pin
Richard MacCutchan9-Mar-10 4:42
mveRichard MacCutchan9-Mar-10 4:42 
AnswerRe: Code is Rounding Down instead of Rounding Up Pin
PIEBALDconsult9-Mar-10 4:44
mvePIEBALDconsult9-Mar-10 4:44 
AnswerRe: Code is Rounding Down instead of Rounding Up Pin
Luc Pattyn9-Mar-10 4:46
sitebuilderLuc Pattyn9-Mar-10 4:46 
GeneralRe: Code is Rounding Down instead of Rounding Up Pin
Richard MacCutchan9-Mar-10 6:19
mveRichard MacCutchan9-Mar-10 6:19 
GeneralRe: Code is Rounding Down instead of Rounding Up Pin
Luc Pattyn9-Mar-10 6:37
sitebuilderLuc Pattyn9-Mar-10 6:37 
GeneralRe: Code is Rounding Down instead of Rounding Up Pin
Richard MacCutchan9-Mar-10 7:38
mveRichard MacCutchan9-Mar-10 7:38 
GeneralRe: Code is Rounding Down instead of Rounding Up Pin
Luc Pattyn9-Mar-10 9:41
sitebuilderLuc Pattyn9-Mar-10 9:41 
AnswerRe: Code is Rounding Down instead of Rounding Up Pin
Rob Philpott9-Mar-10 6:10
Rob Philpott9-Mar-10 6:10 
AnswerRe: Code is Rounding Down instead of Rounding Up Pin
suprsnipes9-Mar-10 21:41
suprsnipes9-Mar-10 21:41 
QuestionPasspoint: Robust Discretization Pin
einsteinmow9-Mar-10 3:17
einsteinmow9-Mar-10 3:17 
AnswerRe: Passpoint: Robust Discretization Pin
R. Giskard Reventlov9-Mar-10 4:08
R. Giskard Reventlov9-Mar-10 4:08 
GeneralRe: Passpoint: Robust Discretization Pin
EliottA9-Mar-10 5:05
EliottA9-Mar-10 5:05 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.