Note: this entry has moved.
Both posts were commented by Sebastien Lambla and Daniel Cazzulino pointing out a few “issues” found in the
But the big news is not about minor fixes… Let’s see what Whidbey brings so you don’t have any excuses now to not follow the SR type approach:
Great News #1: An updated resgen.exe
The days of coding your own SR type are gone. The resgen.exe utility was updated to support the generation of a strongly typed resource class (/str option) through the use of CodeDOM. This means that you can feed it a .resx file with the following:
And you will get back a class definition like this:
Then you could use it from your code like this:
This sounds pretty cool but you still have some chores to perform by hand: run the command line utility resgen.exe, add the generated code file to your project, compile it and repeat this process every time the .resx file is modified.
Great News #2: Whidbey can do the work for you
For all lazy developers out there: good news is you don’t have to perform the above mentioned tasks in order to get your strongly typed resource class. You only drop your .resx file into the \Code folder and you’re ready to go. Whidbey will generate the resource class for you plus something definitively cool: VS.NET will automatically support intellisense for it. Want to modify the existing .resx? Just go ahead, save it, and the class (and intellisense support) will be updated accordingly. I believe this is as lazy as it can get.
What’s the magic behind all this?
Build Providers. You can now (in Whidbey, that’s it) participate in the build process of your application. You code a type that implements IBuildProvider and you register it in web/machine.config against the file extension you’re interested in handling (i.e.: System.Web.Compilation.ResXBuildProvider is the one in charge of .resx files). I promise I’ll posting more on build providers in the next days.
Lastly, just be aware that because of a few bugs in the current PDC03 build you may not get a totally friendly experience, i.e. you may notice that your app doesn’t automatically pick up changes made to files (.resx or any other type) located in the \Code folder thus requiring an additional application restart until that happen. I found about this the hard way :-( but thanks to a quickly follow up with the ASP.NET team this was traced down and should be already fixed.