Resource Files (.rex) Usage Notes from the Field

4. February 2013 14:54 by Chris in dev  //  Tags:   //   Comments (0)

I set up a website with resource files in ASP.NET, MVC4 as it happens but makes little difference. This because the site is bilingual - Welsh and English. 

Post launch the client wanted a content change which involved changing a resource file but, perhaps because of my implementation 'choices' the site did not dynamically pick up the .resx change. I thought, in my ignorance, that maybe I needed to force a recompile so changed the web.config. This didn't work either so now I probably need to understand better what is going on. Hence this blog entry.

Here's how I have the resources configured (as per the best practice google found for me): 

  • Build Action: Embedded resource
  • Copy to output directory: do not copy
  • Custom tool: PublicResXFileCodeGenerator

The fact there is a custom tool here leads me still to think recompilation is needed. A little more about the tool is here and here.

After which I had another "doh!" moment and came thought that I should simply copy the corresponding designer file as well as this is where the property will be accessed and the IDE is handling this for me. In which case I will then also need to force recompilation.

But no, still not working. What have I missed? Ok, so checking the bin directory there is also an xml file containing data relating to the resources. Let's try that as well. Hmmm, nope. Forcing recompilation one more time. Still no joy.

Ok so let's takea look with reflector - the resources are part of the assembly. So let's grab the deployed assembly (which is of identical size) and see if I can access the resources directly within it - they should be the old versions. They are. So the resources are literally embedded in the assembly but simply copying the related files up to the server and forcing a recompilation doesn't do all that is necessary to update the resource references, presumably due to this additional custom tool which Visual Studion integrates with but isn't part of the standard .NET compilation process? So I can just copy up the dll compiled locally. Which worked. Got there at last.

In my book this isn't ideal however and does raise the issue as well that maintenance life becomes a little more complex when you move to resource files, at least with this configuration. When/ if I get a chance I might have a play with other configurations. In the meantime, others have looked at already.

Pingbacks and trackbacks (1)+

Add comment

  Country flag

biuquote
  • Comment
  • Preview
Loading

About the author

I am Dr Christopher Sully (MCPD, MCSD) and I am a Cardiff, UK based IT Consultant/ Developer and have been involved in the industry since 1996 though I started programming considerably earlier than that. During the intervening period I've worked mainly on web application projects utilising Microsoft products and technologies: principally ASP.NET and SQL Server and working on all phases of the project lifecycle. If you might like to utilise some of the aforementioned experience I would strongly recommend that you contact me. I am also trying to improve my Welsh so am likely to blog about this as well as IT matters.

Month List