Skip to content

Pass embedded resource names the same way as MSBuild #474

@sin-ack

Description

@sin-ack

Problem Definition

When an <EmbeddedResource> item is added to a .csproj, the filenames are converted into the format {project name}.{dotted path} for the manifest resource in the assembly, where "dotted path" is the project-relative path of the embedded resource with slashes turned into periods. For example, if a/b/c.txt is embedded into the dll for project Foo.Bar, the generated name is Foo.Bar.a.b.c.txt. This is accomplished by MSBuild passing the resource flag as /resource:path,name to csc, where path is the actual path to the file and name is this generated name.

rules_dotnet however only passes the resource as /resource:path which turns the name into the last component. So in the example above, the manifest resource is called c.txt. This breaks one of my use-cases because I embed a directory by globbing and use the name of the manifest resource to create a virtual file system in memory.

Solution

I believe MSBuild's approach can be replicated by doing the following:

  1. Get the full path of the resource.
  2. Strip the repository root of the target from the start.
  3. Strip the package path of the target from the start.
  4. Replace slashes with periods.
  5. Prepend the out attribute and a period.

Open Questions

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions