Embedded Resources in .NET Core #51844
Replies: 2 comments 1 reply
-
The resx-files aren't coupled to Windows Forms. They can be used in .NET Core / .NET 5+ just fine.
😃 yes with resx files and the tooling included in VS. That's IMO the easiest way to go. Why do you want to re-invent the wheel here? |
Beta Was this translation helpful? Give feedback.
-
To be more specific, there are 2 supported ways to embed a file as a resource. The first way is to use the The second way is using a RESX file. These actually get compiled into a structured file format called a .resource file, and then are included as an Embedded Resource. These resources are designed to be accessed via the Before compilation into a .resource file, .RESX is tied to certain Windows Forms Code, as that is where the code to read and write the uncompiled xml format lives. After compilation it does not depend on Windows Forms in any way. MSBuild contains a cross platform RESX compiler that does not use the Windows Form code, but parses the format itself. A source generator approach would end up with the resource stored an additional time. (Stored both as raw data in the executable, and in managed memory as a string or byte array, likely as a static field on the generated class, so this copy in managed memory will not get garbage collected.) With the Embeded Resources approach, you get a stream that reads the data directly from the executable. |
Beta Was this translation helpful? Give feedback.
-
What is the "right" way to embed resources in a .NET core assembly without relying on RESX files and Windows Forms?
I think I'd like something similar to a source generator that generates a static class with the resources in it.
Does something like that exist?
Beta Was this translation helpful? Give feedback.
All reactions