Thursday, August 24, 2006

Compiling Resource file in a PreCompiled web site at the production server

So you have a precompile web site located on the customer's production server and you want few of the following:

  1. Allow the customer IT / PS to alter the resource you are using (without your help)
  2. Create a simple mechanism of updating the resource file without distributing a DLL.

To do a task like this you would probably create a provider for the localization and start coding you way threw the solution, I suggest another approach that is far more simple and doesn't require you / customer to deal with DLLs and also enable the customer's IT / PS to write an application that will enable him to edit the resource.

High Level Solution

on the production server you will have a directory that will hold all the pre compile RESX file + few utility classes that can be called in various ways (web page / schedule / exe , etc).

Few Words

  1. For simplicity you will only update a specific culture and not natural - the reason is that i don't want to start messing with a more complex compilation of a typed resource).
  2. The entire localization related files will stay with a new directory.
  3. You will have to have a new directory that will hold the pre compiled RESX (for each culture other than the natural as said in Pr.1)
  4. You will have to create a batch file / VBS that will do all the compilation and moving of the new resource.

Detailed Solution

  1. Create a new directory called "LocalizationKit" (This is for simplicity)
  2. Create a new directory under "LocalizationKit" called "Utilities" - this directory will hold all the files needed to compile the resource at the production server.
    Copy the following files to this directory:
    1. al.exe
    2. al.exe.config
    3. alink.dll
    4. alinkui.dll
    5. ResGen.exe
  3. On your post build event create a task that will copy each resource (related files) to a new directory under "LocalizationKit" based on the culture name (E.g. en-US, en-GB, etc)
  4. Create a batch / VBS file that will do the following for all the resources:
    1. Convert the RESX file to .resources using resgen (E.g. Resgen.exe [file.resx])
    2. Compile the relevant .resource files to one DLL (E.g. al.exe /nologo /t:lib /embed:[resource], [file name] /culture:[RESX culture] /out:App_GlobalResources.resources.dll
    3. Copy the newly created resource DLL to the relevant directory under the bin (E.g. ..\Bin\en-US\) [Make sure that the directory exist, if not than create it]
    4. Delete the ".Resource" file (not needed)

Now all that you have to do on your production server is to alter the relevant RESX file in the "LocalizationKit" directory and call the method before.

Using this solution you can give the customer the option to change keys in the resource without needing you / new code.

Hope this help you (if you want a sample directory mail me).