Automated build of Satellite Assemblies in Visual Studio with MSBUILD
Much has been said and written about satellite assemblies and localization techniques that are achieved using them. I believe that most of the industry has no doubt in the usefulness of this amazing feature of the .NET Framework; however the lack of automation has made it slightly difficult for many companies to adopt. (In Visual Studio 2005 the generation of satellite assemblies for controls placed on Windows Forms is an automated process. Just use the localized property in conjunction with the language property of Forms. This is not covered in this blog entry).
Just to demonstrate how simple it is to automate the creation and build of these assemblies, I have put together a simple application which uses MSBUILD and post-build events to automatically generate resources and link them into satellite assemblies.
With satellite assemblies, they need to be placed in a specific directory structure. See http://msdn2.microsoft.com/en-us/library/21a15yht(vs.80).aspx for more information on this structure.
The first step in creating a satellite assembly is to compile .resx files into .resources files. This is usually done using the RESGEN utility or the GenerateResource MSBUILD task:
Resgen.exe /compile SatelliteAssembly.en-GB.resx,SatelliteAssembly.en-GB.resources
The second step is to use the assembly linker utility to create the satellite assembly from .resources files:
AL.exe /culture:en-GB /out:en-GB\SatelliteAssembly.resources.dll /version:18.104.22.168 /embed:SatelliteAssembly.en-GB.resources
The MSBUILD script is called by the post-build event of the executable project and here is what it does:
- MSBUILD script is executed by the post-build event of the executable project passing the path to the output directory
- .resx files are compiled into .resources
- .resources are linked into satellite assemblies
- Satellite assemblies are copied to the output folder
- All temporary files and folders are deleted