Skip to content

[Resx Designer] SingleFileGenerators not working properly in MS.NET.Sdk.WindowsDesktop project with linked files #8392

@vsfeedback

Description

@vsfeedback

This issue has a corresponding ticket on Developer Community. Please vote and comment there to make sure your voice is heard.


Hi,

I’m trying to switch some WPF projects from the old .NET project format to the new Microsoft.NET.Sdk.WindowsDesktop format.
While doing that I encountered a problem with linked files and SingleFileGenerators, first I thought that it’s only a problem of my self written SingleFileGenerator but after some testing it seems like it’s a problem of all SingleFileGenerators.

To describe the problem a bit better here is an example directory structure of a possible project:

SingleFileGenTest.sln

  • Shared
    • Resources
      • SharedResource.resx
      • SharedResource.Designer.cs
  • SingleFileGenTest
    • SingleFileGenTest.csproj
    • Other project files

So the solution file SingleFileGenTest.sln, Shared and SingleFileGenTest directories are in the same directory.
SharedResource.resx and SharedResource.Designer.cs are in the directory Resources which is a sub-directory of Shared.
SingleFileGenTest contains all not shared project files…

In the old project format I could add a link to the SharedResource.resx and SharedResource.Designer.cs files with “Custom Tool”/SingleFileGenerator set to ResXFileCodeGenerator (at SharedResource.resx) and ResXFileCodeGenerator created SharedResource.Designer.cs without any issues. The link to the file/s is added with a reltaive path, not with a fixed path!

If I try the same with the new project format, nothing will happen at all. After some testing I found a workaround which is Ok for my SingleFileGenerator but in case of e.g. ResXFileCodeGenerator you also must set a “Custom Tool namespace” as otherwise the generated namespace is incorrect and contains the relative path dots…

The workaround that I found is to include all resx files with the following line:
<EmbeddedResource Include="$(SolutionDir)\Shared\Resources*.resx" Generator=“ResXFileCodeGenerator” />

When running the generator for the first time this will add additional entries to the project file one would be:
<EmbeddedResource Update=“C:\Src\SingleFileGenTest\Shared\Resources\SharedResource.resx”>

</EmbeddedResource>

As you see it would add the updated EmbeddedResource information with a fix path, which basically is correct but not what I want as it could be different on another PC and so I change it to a relative path like this:
<EmbeddedResource Update="…\Shared\Resources\SharedResource.resx">

</EmbeddedResource>

Even with this change the Generator will now work and generate a file but as said above in at least of ResXFileCodeGenerator with a wrong/invalid namespace.

I can work with this workaround for now but it would be much better if the SingleFileGenerators would work again with the new project format the way they did with the old in case of linked files.

I’ve attached a sample project which contains projects in the new format and old format so you can see what I mean and test it out.
To see the workaround in action, you’ve to edit the the new project file, comments are in place so you should see what to edit.

If you need anymore information, let me know.


Original Comments

Feedback Bot on 1/14/2020, 09:14 PM:

(private comment, text removed)

Feedback Bot on 2/20/2020, 06:58 PM:

(private comment, text removed)

Feedback Bot on 3/31/2020, 11:56 PM:

(private comment, text removed)

Chaojie Yang [MSFT] on 4/8/2021, 00:44 AM:

(private comment, text removed)

Alexander Jochum on 4/8/2021, 04:07 AM:

(private comment, text removed)

Chaojie Yang [MSFT] on 4/9/2021, 00:08 AM:

(private comment, text removed)

Feedback Bot on 8/2/2021, 10:43 AM:

(private comment, text removed)


Original Solutions

(no solutions)

Metadata

Metadata

Assignees

No one assigned

    Labels

    Feature-Resource-DesignerDEPRECATED The legacy resource file (RESX) editor.Triage-InvestigateReviewed and investigation needed by dev team

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions