DEV Community

loading...

How can I include resources in a compiled C# program for later use?

baenencalin profile image Calin Baenen ・1 min read

I want something similar to the effect of how Jar files retain data (as they are like zip files).
Since this is not the case w/ CSharp, how can I include resources?

Here's an example of what I want to do (this is meant to be a filesystem):

Project:
 Main.cs
 Components:
  JSONHandlers.cs
  JSON:
   myFile.json
   one.json
   two.json
Enter fullscreen mode Exit fullscreen mode

Now, let's say I want to read one.json from the compiled output (Project.exe), as far as I'm aware, files like these aren't included in the end-product, and it doesn't create a file for this, so if I try to read that file, it will throw an exception.

Another example is if I have a folder of resources (images, dialogue, etc...) (in a game-dev ctx), and I tried to use those.
So, is there any way of packaging these resources with the executable?

Thanks!
Cheers!

Discussion (6)

pic
Editor guide
Collapse
lifelongthinker profile image
Sebastian

There are many ways to do this. For two common ones, have a look at this blog post:
ikriv.com/blog/?p=1530

Collapse
baenencalin profile image
Calin Baenen Author

Is there any way I can do this w/ just the dotnet CLI?
I don't use V.S., and don't know if it's a requirement or not, to get it working, as it doesn't say anything about doing it w/o V.S.

Thank you for the link to this post.
Cheers.

Collapse
lifelongthinker profile image
Sebastian • Edited

Yes, you just need to edit the project file (it's in XML format).

Thread Thread
baenencalin profile image
Calin Baenen Author

It doesn't say how to do this in the .csproj file, could you provide a url to an example of an uncompiled program that will have something packaged inside of it?
Solutions for V.S. seem to be more popular than the barebones method of CLI and .csproj (but I guess that's to be expected with all these fancy tools).

Thread Thread
lifelongthinker profile image
Thread Thread
baenencalin profile image
Calin Baenen Author

TY a ton.
Cheers.