| C# Source Code: embed_executable_source.zip | |
Sometimes it is necessary to embed an executable (or any other file) into your application
and later recreate it during runtime. At the center of the technique are the Resource capabilities
of .NET and the concept of Reflection. Below is an example of such a technique using C#.
Steps in 'plain' English
1. Embed executables using Visual Studio IDE.
2. Use Reflection to investigate current assembly for all embedded resources.
3. For desired Resource(s), open a Stream to the Resource.
4. Read from this Stream and simultaneously write the contents of Stream to disk.
| |
|
Sample Source Code
| |
Each individual file must be added into your solution as an Embedded Resource? To do this right
click in the Solution Explorer then select: Add-> Existing Item. Now locate the executable (or any other)
file of your choice and then select it. You will now see this file in the Solution Explorer. Now right
click on it and choose Properties-> Make sure "Build Action" has "Embedded Resource" selected.
|
另外资源:http://devhood.com/Tutorials/tutorial_details.aspx?tutorial_id=75