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:
- Allow the customer IT / PS to alter the resource you are using (without your help)
- 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
- 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).
- The entire localization related files will stay with a new directory.
- 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)
- You will have to create a batch file / VBS that will do all the compilation and moving of the new resource.
Detailed Solution
- Create a new directory called "LocalizationKit" (This is for simplicity)
- 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: - al.exe
- al.exe.config
- alink.dll
- alinkui.dll
- ResGen.exe
- 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)
- Create a batch / VBS file that will do the following for all the resources:
- Convert the RESX file to .resources using resgen (E.g. Resgen.exe [file.resx])
- 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
- 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]
- 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).
5 comments:
Hello Ran,
I have been searching for this exact solution.
Can you send me your sample code?
eastburnj (at) quaero (dot) com
Josh
Hi, I am having a web application which has app_localresources per module, how can i do the same but in diferents folders?, do you have an example?.
Hi,
I dont have an example for that use case but i suggest that to:
1. Add the relevant RESX files to the original SLN and compile (to understand how the RESX should be embedded)
2. Alter the batch file to recursively take the relevant RESX file and embed them as needed
Post a comment after you finish, i am sure other want it :)
thanks
can you please provide details of these files and what is there role in this localization ?
al.exe
al.exe.config
alink.dll
alinkui.dll
ResGen.exe
ResGen - used to compile the txt resource to a resources file
AL - used to merge the resource into a DLL (loaded by ASP.NET)
other DLL are used by AL.EXE
hope that clarifies.
as a side note i would suggest to move to DB resource provider.
Post a Comment