Walkthrough: Downloading Satellite Assemblies on Demand with the ClickOnce Deployment API
Windows Forms applications can be configured for multiple cultures through the use of satellite assemblies. A satellite assembly is an assembly that contains application resources for a culture other than the application's default culture.
As discussed in Localizing ClickOnce Applications, you can include multiple satellite assemblies for multiple cultures within the same ClickOnce deployment. By default, ClickOnce will download all of the satellite assemblies in your deployment to the client machine, although a single client will probably require only one satellite assembly.
This walkthrough demonstrates how to mark your satellite assemblies as optional, and download only the assembly a client machine needs for its current culture settings. The following procedure uses the tools available in the Windows Software Development Kit (SDK). You can also perform this task in Visual Studio. For more information, see Walkthrough: Downloading Satellite Assemblies on Demand with the ClickOnce Deployment API Using the Designer and Walkthrough: Downloading Satellite Assemblies on Demand with the ClickOnce Deployment API Using the Designer and Walkthrough: Downloading Satellite Assemblies on Demand with the ClickOnce Deployment API Using the Designer and Walkthrough: Downloading Satellite Assemblies on Demand with the ClickOnce Deployment API Using the Designer and Walkthrough: Downloading Satellite Assemblies on Demand with the ClickOnce Deployment API Using the Designer.
For testing purposes, the following code example programmatically sets the culture to ja-JP. See the "Next Steps" section later in this topic for information on how to adjust this code for a production environment.
This topic assumes that you know how to add localized resources to your application using Visual Studio. For detailed instructions, see Walkthrough: Localizing Windows Forms.
To download satellite assemblies on demand
Add the following code to your application to enable on-demand downloading of satellite assemblies.
Imports System.Deployment.Application Imports System.Globalization Imports System.Threading Public Class Form1 Shared Sub Main(ByVal args As String()) Application.EnableVisualStyles() Thread.CurrentThread.CurrentUICulture = New CultureInfo("ja-JP") GetSatelliteAssemblies(Thread.CurrentThread.CurrentUICulture.ToString()) Application.Run(New Form1()) End Sub Private Shared Sub GetSatelliteAssemblies(ByVal groupName As String) If (ApplicationDeployment.IsNetworkDeployed) Then Dim deploy As ApplicationDeployment = ApplicationDeployment.CurrentDeployment If (deploy.IsFirstRun) Then Try deploy.DownloadFileGroup(groupName) Catch de As DeploymentException ' Log error. Do not report error to the user, as there may not be a satellite ' assembly if the user's culture and the application's default culture match. End Try End If End If End Sub End Class
Generate satellite assemblies for your application by using Resgen.exe (Resource File Generator) or Visual Studio.
Generate an application manifest, or open your existing application manifest, by using MageUI.exe. For more information about this tool, see MageUI.exe (Manifest Generation and Editing Tool, Graphical Client).
Click the Files tab.
Click the ellipsis button (...) and select the directory containing all of your application's assemblies and files, including the satellite assemblies you generated using Resgen.exe. (A satellite assembly will have a name in the form isoCode\ApplicationName.resources.dll, where isoCode is a language identifier in RFC 1766 format.)
Click Populate to add the files to your deployment.
Select the Optional check box for each satellite assembly.
Set the group field for each satellite assembly to its ISO language identifier. For example, for a Japanese satellite assembly, you would specify a download group name of ja-JP. This will enable the code you added in step 1 to download the appropriate satellite assembly, depending upon the user's CurrentUICulture property setting.
In a production environment, you will likely need to remove the line in the code example that sets CurrentUICulture to a specific value, because client machines will have the correct value set by default. When your application runs on a Japanese client machine, for example, CurrentUICulture will be ja-JP by default. Setting this value programmatically is a good way to test your satellite assemblies before you deploy your application.