C
C#17mo ago
Tofaa

❔ ✅ Equivalent of Java's resources folder in c#

I've been dipping my toes in c# for a while but i cant seem to find a proper way of storing files in the app itself, i use rider.
9 Replies
nukleer bomb
nukleer bomb17mo ago
In project 1) Move files you need to store in app in project folder 2) Set ContentType of these files to EmbeddedResource These two steps will add files inside assembly
Tofaa
TofaaOP17mo ago
if i have a ton can i use a folder?
nukleer bomb
nukleer bomb17mo ago
Yes, and wildcard paths are supported in .csproj file, not sure about Rider In code 1) Get instance of Assembly class that represents assembly in which files are stored:
var asm = typeof(SomeClassFromThatAssembly). Assembly;
// or
var asm = Assembly.GetExecutingAssembly(); // if assembly you need is one that is executing right now
// or
var asm = Assembly.GetEntryAssembly(); // If assembly you need is one that contains entrypoint
var asm = typeof(SomeClassFromThatAssembly). Assembly;
// or
var asm = Assembly.GetExecutingAssembly(); // if assembly you need is one that is executing right now
// or
var asm = Assembly.GetEntryAssembly(); // If assembly you need is one that contains entrypoint
2) Call asm.GetManifestResourceNames() to get an string[] of all resource files in that assembly or asm.GetManifestResourceStream(string) to get Stream to read that resource
Tofaa
TofaaOP17mo ago
imma try figuring outhow to set content type of a folder toembedded resource in rider
nukleer bomb
nukleer bomb17mo ago
You can't set ContentType for folders. Use wildcards to set it for all files inside that folder: Set ContentType for some file in that folder and then edit .csproj file to change path to that file to use wildcard So
<ItemGroup>
<EmbeddedResource Include="some/folder/your_file.ext" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="some/folder/your_file.ext" />
</ItemGroup>
will change to
<ItemGroup>
<EmbeddedResource Include="some/folder/*" />
</ItemGroup>
<ItemGroup>
<EmbeddedResource Include="some/folder/*" />
</ItemGroup>
Change * to ** to recursively include all subdirectories and files
Tofaa
TofaaOP17mo ago
Thank you so much :D
nukleer bomb
nukleer bomb17mo ago
No problem. Also, $close if you have no more questions
MODiX
MODiX17mo ago
Use the /close command to mark a forum thread as answered
Accord
Accord17mo ago
Was this issue resolved? If so, run /close - otherwise I will mark this as stale and this post will be archived until there is new activity.
Want results from more Discord servers?
Add your server