Click here to Skip to main content
Click here to Skip to main content

Create satellite assemblies with ResX Builder

, 13 Nov 2010 CPOL
Rate this:
Please Sign up or sign in to vote.
How to create satellite assemblies with ResX Builder.

Introduction

Localization in Visual Studio is very good, and whilst I found it suitable for almost every situation, there is one issue that can cause a lot of grief; how does one deploy new satellite assemblies when an application has already been built? For many small projects, this is not an issue, and the developer simply deploys a new version. However, this is not always an easy choice to make. Wouldn't it be wonderful to create a satellite assembly and upload it to your application without having to rebuild? Well, you can! Let's start seeing how...

Traditional method: If you have the time and energy to work it out, you will come to use resgen.exe and al.exe, two tools included with the Visual Studio installation. Resgen.exe will take a RESX file and spit out a .resources file. Then, you take this, and with a load of different (and tricky syntax) commands, you will end up having written something like this:

"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\resgen.exe" 
    "HelloResX.ja-JP.resx" "ResXTest.HelloResX.ja-JP.resources"

"C:\Program Files\Microsoft SDKs\Windows\v6.0A\Bin\al.exe" /t:lib 
   /out:"ja-JP\ResXTest.resources.dll" /culture:ja-JP 
   /embed:"ResXTest.HelloResX.ja-JP.resources"

It may look easy, but I tell you... it can cause some serious grief at times. Right, so to minimize on grief, I have written a nice GUI utility that I hope some of you will find useful. Let's get into explaining ResXBuilder then...

Simplifying the process with ResX Builder

All you need to do is fire up the tool, enter some info, and click Build, then voila; your new satellite assembly is ready to deploy.

Main.PNG

As you can see from the screenshot above, the main area is a grid, and basically what this is for is editing the values of an existing .resx file. For example, say you have a default .resx file called HelloResX.resx; you tell the tool where to find the template file (your default .resx file) and then click Load. This will bring up all the name/value pairs in a grid that you can edit. Once you're done translating, simply select a culture and specify the resource namespace and project name, then click Build. That's it; you're ready to deploy!

A demo app

In the attached source code, you will find a demo project. In there, you will see the following simple code:

static void Main(string[] args)
{
   List<string> cultures = new List<string>();
   cultures.Add("en-US");
   cultures.Add("zh-CHS");
   cultures.Add("ja-JP");
   cultures.Add("vi-VN");
   cultures.Add("ru-RU");

   cultures.ForEach(HiBye);
   Console.ReadLine();
}

private static void HiBye(string cultureCode)
{
   HelloResX.Culture = CultureInfo.GetCultureInfo(cultureCode);
   Console.WriteLine("Culture: {0}", cultureCode);
   Console.WriteLine("Hello: {0}", HelloResX.Hello);
   Console.WriteLine("Goodbye: {0}", HelloResX.Goodbye);
   Console.WriteLine();
}

Basically, I only have one resources file: HelloResX.resx, and because it is strongly typed, we can call the properties on it directly. By default, it will use the current culture, but if you change the Culture property as in the above code, it will try to locate the required satellite assembly from the bin folder. What I am doing in the above code is setting the culture 5 times for 5 different cultures and writing the name/value pairs to the Console. Of course, in a real world app, you won't know what cultures to load, and you would get the user to select the culture they want to use from a dropdown or something, and then try load it from there. The images below show before and after I added the satellite assemblies to the bin folder.

TestBefore.PNG

Before

TestAfter.PNG

After

Conclusion

Satellite assemblies; very useful... command line tools to generate them; nasty... GUI tools to handle the issue; makes generating satellite assemblies quick and easy. Enjoy!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

Share

About the Author

gordon_matt
Software Developer VortexSoft
Vietnam Vietnam
No Biography provided

Comments and Discussions

 
QuestionWhy 4 stars PinmemberStefan Vasiljevic28-Oct-14 5:00 
Bug[My vote of 1] Vote of 1 PinmemberMember 467008624-Dec-13 13:08 
GeneralMy vote of 5 Pinmemberdheerajv25-Jul-12 17:44 
QuestionMBG not found--code is not working PinmemberMrNilesh15-Dec-11 0:54 
AnswerRe: MBG not found--code is not working PinmemberDe Nardis Andrea24-Mar-12 8:34 
GeneralMy vote of 1 Pinmemberbcraun18-Mar-11 11:03 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.

| Advertise | Privacy | Terms of Use | Mobile
Web01 | 2.8.141223.1 | Last Updated 14 Nov 2010
Article Copyright 2010 by gordon_matt
Everything else Copyright © CodeProject, 1999-2014
Layout: fixed | fluid