EmbeddedResourceBrowser 1.2.0

View on GitHub View on NuGet

EmbeddedDirectory Class

Represents a directory of embedded resources.

Base type: object.

Constants

Name Access Modifier Summary
DefaultDirectoryPathSeparator public

The default char separator used for directory paths.

Constructors

Name Access Modifier Summary
EmbeddedDirectory(Assembly) public

Initializes a new instance of the EmbeddedDirectory class.

EmbeddedDirectory(IEnumerable<Assembly>) public

Initializes a new instance of the EmbeddedDirectory class.

EmbeddedDirectory(Assembly[]) public

Initializes a new instance of the EmbeddedDirectory class.

EmbeddedDirectory(Assembly, char) public

Initializes a new instance of the EmbeddedDirectory class.

EmbeddedDirectory(IEnumerable<Assembly>, char) public

Initializes a new instance of the EmbeddedDirectory class.

Properties

Name Access Modifier Summary
Files public get

Gets the list of the embedded files.

Name public get

The name of the embedded directory.

ParentDirectory public get

Gets the parent EmbeddedDirectory, the root directory has a null parent directory.

Subdirectories public get

Gets the list of the embedded subdirectories.

Methods

Name Access Modifier Summary
GetAllFiles() public

Gets all files from the current embedded directory and all embedded subdirectories, from all levels.

GetAllSubdirectories() public

Gets all subdirectires, from all levels, from the current embedded directory.

Merge(IEnumerable<Assembly>) public

Creates an EmbeddedDirectory containing the resources from all provided assemblies using a merge strategy.

Merge(Assembly[]) public

Creates an EmbeddedDirectory containing the resources from all provided assemblies using a merge strategy.

Merge(IEnumerable<Assembly>, char) public

Creates an EmbeddedDirectory containing the resources from all provided assemblies using a merge strategy.

Remarks

The embedded resources are mapped using case-insensitive matching, if multiple assemblies or files (in the same directory) only differ in casing (e.g.: TEST FILE.txt is the same as test file.txt) then an ArgumentException is thrown.

By default, embedded resources use the dot (.) as a separator for directory paths and the assembly name is placed at the beginning of the name. <EmbeddedResource Include="MyDirectory/MySubdirectory/MyFile.ext" /> is mapped to MyAssemblyName.MyDirectory.MySubdirectory.MyFile.ext. When processing files, it is expected that files have extensions, thus the last dot (.) is ignored from the file path. When processing files, the assembly name is expected to be at the beginning of an embedded resource and the character immediately afterwards is used to determine the path separator. This will make the resource be mapped to the following structure MyDirectory/MySubdirectory/MyFile.ext.

To embed the file under a different name use the LogicalName attribute (or specify it as a child element), this allows the use of different path separators which can be useful if the embedded resources have dots (.) in their name (e.g.: MyFileWithVersion@1.2.3.txt) or when files or directories start with a number (e.g.: MyDirectory/1.2.3/File.txt). By default, the file will be embedded under MyAssemblyName.MyDirectory._1._2._3.File.txt.

When specifying the LogicalName make sure to specify the assembly name followed by the path separator otherwise the library will not pick up these files. The library is made so that it works with the default naming structure.

Specifying a different path separator can be done individually on each file.

<!-- This uses '/' as the path separator -->
<EmbeddedResource Include="MyDirectory/MySubdirectory/MyFile.ext" LogicalName="MyAssemblyName/MyDirectory/MySubdirectory/MyFile.ext" />

<!-- This uses '!' as the path separator -->
<EmbeddedResource Include="MyDirectory/MySubdirectory/MyFile.ext" LogicalName="MyAssemblyName!MyDirectory!MySubdirectory!MyFile.ext" />

The path separator is determined per file, there is no global setting for path separators allowing for mixed settings. An alternative would be to specify all the embedded files and afterwards update all the matching files. The following element will update all embedded resources that have been specified up to that element in the .csproj (or any other project file type) to have the assembly name at the beginning and normalize the paths to use forward slash as a separator. This will cause all included embedded resources to that point to have the same structure as in the file system. See MSBuild well-known item metadata and Common MSBuild project properties for more information, they work with dotnet build as well.

<EmbeddedResource Update="**/*" LogicalName="$(AssemblyName)/$([System.String]::Copy('%(Identity)').Replace('\', '/'))" />

EmbeddedResourceBrowser 1.2.0 - View on GitHub - View on NuGet