Edit ASP.NET MVC 3 resx files in deployment server

2019-02-09 13:55发布

问题:

This is my first question here!

I have one ASP.NET MVC 3 Project with a Properties folder, containing some .resx files used to difference content in my views by language (en/es). I'm working in VS2010 with .Net 4.

When I deploy the application to server, I find that no resx files are published, and instead of it, I have some .dll files.

I have set the build action to Embedded resource , Do not copy to output directory and PublicResXFileCodeGenerator as Custom Tool in .resx files properties.

I want to have .resx files on the server and be able to edit them without recompile or redeploy. The views should use those changes.

How can I do that?

Thanks for your help!!

回答1:

Put the resx files in your App_GlobalResources and change the "Build Action" to Content and "Copy To Output Directory" to false. Make sure the "Custom Tool" is set to GlobalResourceProxyGenerator

That should make them changeable even at runtime.

You can simply use xpath to query over them, take the keys, values and comments and edit them as you wish using an XDocument.

You should also know that such a thing won't work with visual studio's publish because App_GlobalResources is not allowed with precompiled website.