Archived

This topic is now archived and is closed to further replies.

Making resource files (C#)

This topic is 5149 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

Hi there, Is there any tutorials or tips anyone has on making resource files? I basically want to make all my textures used into one file (e.g. one for particles, one for background, one for player sprites etc) and pull the data out based on an index. I''ve got the feeling that this ability is in C# someplace but cant really find anything after googling. Phil Price™: Better than cool - uber cool.

Share this post


Link to post
Share on other sites
You can just embed any file directly into the exe or dll. On the command line you can use the /resource switch:

csc /resource:texture.gif Game.cs

In VS.NET you can accomplish the same by adding the file to your project, then choosing "Embedded Resource" as the Build Action in the properties window. Note that VS.NET will always prepend the default namespace to the resource name. If you are in doubt what the actual name of the resource is, use ildasm or a similar tool to inspect the assembly.

In the code you can then extract the resource through a Stream:


Stream resourceStream = this.GetType().Assembly.GetManifestResourceStream( "texture.gif" );
Image texture = Image.FromStream( resourceStream );


--
AnkhSVN - A Visual Studio .NET Addin for the Subversion version control system.
[Project site] [Blog] [RSS] [Browse the source] [IRC channel]

Share this post


Link to post
Share on other sites