Latest Rider - Asp.Net Core MVC - How can I set Resource.resx code generator to use public instead of internal?
Hi gang,
I'm trying to use a localization resource from a .cshtml file... seems like something I should need to do for localized web pages.. I did the following:
- Add a new "Resource.resx" file to the project at the top-level folder
- Go to one of my Index.cshtml files
- On the typical `ViewBag.Title` assignment line, highlight the string literal, right-click -> Refactor... -> Refactor This... -> Move to resource
- Pick the `Resources.resx` file as the target
- Next...
When the dust settles, the new resource has been added to the resx, and the C# code generation has been run.. and the resource string is referenced instead of the string literal... except there's a red squiggly under that reference, and it's complaining `Cannot access internal class Xyz here`.
Looking at the generated class, sure enough... it's `internal` instead of `public`.
After googling a bunch, most hits are talking about Visual Studio and a droplist in the resource editor tool that lets you specify public vs. internal (eg. https://www.devcurry.com/2013/02/aspnet-mvc-using-resource-files-to.html ). Some other hits talked of using `PublicResXFileCodeGenerator` instead of a default `ResXFileCodeGenerator`... but again, nothing w.r.t. how to do this in Rider (eg. https://www.devcurry.com/2013/02/aspnet-mvc-using-resource-files-to.html ). I did find one Rider-specific post that appears to be out of date (see: https://rider-support.jetbrains.com/hc/en-us/community/posts/360000174464-Change-access-modifier-of-resx-to-public )... the File Properties -> Diagnostic section for my resx file does not include a `Generator` setting.
What is the current proper way to be able to manage resources with Rider such that I can access the resource strings in Razor view code?
Thanks,
Tyler
Please sign in to leave a comment.
Hi Tyler!
Thank you for contacting us.
I've created an issue for this RIDER-33587, but I suppose this issue relates to Resource designer RIDER-3108. Please, feel free to upvote both.
You can use a workaround that you mentioned in the related thread:
- create a resource file
- edit the .csproj file manually (context menu on project in Solution Explorer > Edit > Edit '<name>.csproj')
- search for the embedded resource tag that includes the *.resx file
- Change Generator child tag content to 'PublicResXFileCodeGenerator'
- apply "Move to resource".
This workaround works only for one *.resx file at once, so you need change Generator for each file.
Hope this helps.