-
Notifications
You must be signed in to change notification settings - Fork 0
ProjectFiles
⚠️ EXPERIMENTAL FEATURE: This feature is currently experimental and may undergo significant changes in future versions.
The Project Files Generator creates strongly-typed wrappers for embedded resources in your project, providing safe and convenient access to these resources at runtime. It generates a static class structure that mirrors your project's resource folder hierarchy.
This feature requires explicit opt-in. To enable it, add the following property to your .csproj file:
<ShadowWriter_EnableEmbeddedResources>true</ShadowWriter_EnableEmbeddedResources>The generator creates two main components:
-
EmbeddedResourceInfoclass - Provides access to individual embedded resources -
EmbeddedResourcesstatic class - Contains strongly-typed properties for all embedded resources
- Strongly-typed Access: Each embedded resource is represented by a property with the appropriate name
- Hierarchical Organization: Resources are organized in nested classes that mirror your folder structure
- Runtime Safety: Built-in null checks and proper exception handling
-
Debug Information: Includes a
DebugInfoproperty listing all available resources
// Access a resource at the root level
var stream = EmbeddedResources.MyImage1Png.GetEmbeddedResourceStream();
// Access a resource in a subfolder
var stream = EmbeddedResources.Images.Logo.CompanyLogoPng.GetEmbeddedResourceStream();The generator follows these naming conventions:
- File names are converted to PascalCase
- File extensions become part of the property name
- Special characters are removed or converted to valid C# identifiers
- Folder names become nested static classes
For example:
-
images/logo.pngbecomesEmbeddedResources.Images.LogoPng -
docs/user-guide.pdfbecomesEmbeddedResources.Docs.UserGuidePdf
When the ShadowKit.IO package is referenced, the generated EmbeddedResourceInfo class implements ITransientFileManagerSource, enabling additional integration features.
-
Resource Organization
- Keep resources in meaningful folder structures
- Use consistent naming conventions for files
-
Error Handling
try { using var stream = EmbeddedResources.MyResource.GetEmbeddedResourceStream(); // Process the stream } catch (FileNotFoundException ex) { // Handle missing resource }
-
Resource Management
- Always dispose of resource streams properly
- Use
usingstatements when working with resource streams
- The feature must be explicitly enabled via project properties
- Resource names must be valid C# identifiers after conversion
- Changes to embedded resources require recompilation to update the generated code
- Generated code is marked with
[CompilerGenerated]attribute - All generated classes are internal by default
- Resource streams are obtained via
Assembly.GetManifestResourceStream - The generator automatically handles resource name mangling for .NET resource naming conventions
As this is an experimental feature, future versions may include:
- Additional resource access patterns
- Enhanced metadata support
- Custom resource transformation pipelines
- External resource mapping capabilities