Creating the Satellite Assemblies


This next step converts the .resx files to .resources files and the .resources files to satellite assemblies. To start, you will use ResGen as you did earlier (this assumes that the path to the ResGen.exe application is in your environment path). In each of the three folders, run the following at the command line:

 ResGen NorthwindTraders.[culture].resx NorthwindTraders.[culture].resources 

Replace [culture] with the cultural designator (en-US, es-ES, or fr-FR). Each folder should now have two files: a .resx file and a .resources file.

Caution

You must do this in separate directories because the next step causes each .resources file to be created with the same name. Needless to say, if everything is in the same folder you will only end up with one DLL.

Next, you will use Assembly Linker to create the actual satellite assemblies for use by your application. You can find Assembly Linker in the C:\%windows%\ Microsoft .NET\Framework\[framework version number]. It is a good idea to put this folder into your environment path. Run the following at the command line in each of the three folders (line breaks are for formatting only; this should all be one line):

 al /out:NorthwindTraders.Resources.dll /c:[culture] /embed:NorthwindTraders.[culture].resources, NorthwindTraders.[culture].resources 

Again, replace [culture] with the correct cultural designator.

Caution

Do not leave a space in the embed tag after the comma or you will receive an unknown error and the file will not compile.

As mentioned earlier, Assembly Linker is beyond the scope of this book, but it is important to note that the /c switch determines which culture this assembly is referenced for. Because the filename has no indicator, nor do your resources, this is the only way for the Common Language Runtime (CLR) to determine whether to access the resources from this particular satellite assembly.

Caution

The MSDN documentation recommends using a Hub and Spoke model for packaging and deploying your application and dealing with satellite assemblies that contain resources. There is one small problem with this, though: You may not use the VS .NET IDE to compile your main executable. The only way to embed a resource (or link a resource) to an EXE is to compile the application with Assembly Linker.

Each language folder should now have a third file in it: the NorthwindTraders.Resources.dll. This is all you need to do to create the satellite assemblies. To actually use the resource information in your code, you need to do one more thing. Because your resources will not get deployed automatically when you build the application, you need to do it yourself. So, in Windows Explorer, copy the en-US, es-ES, and fr-FR folders from the NorthwindTraders folder to the NorthwindTraders\bin folder. You should delete the .resx and .resources files from the copied folders. When you are finished, the project directory structure should look like that in Figure 13-3.


Figure 13-3: The NorthwindTraders directory structure

Now you can access the resources from code.




Building Client/Server Applications with VB. NET(c) An Example-Driven Approach
Building Client/Server Applications Under VB .NET: An Example-Driven Approach
ISBN: 1590590708
EAN: 2147483647
Year: 2005
Pages: 148
Authors: Jeff Levinson

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net