Udostępnij za pośrednictwem


Resources in Applications

Nearly every production-quality application needs to use resources. A resource is any nonexecutable data that is logically deployed with an application. A resource might be displayed in an application as error messages or as part of the user interface. Resources can contain data in a number of forms, including strings, images, and persisted objects. Storing your data in a resource file allows you to change the data without recompiling your entire application. Note that to write persisted objects to a resource file, the objects must be serializable.

The .NET Framework provides comprehensive support for the creation and localization of resources. In addition, the .NET Framework supports a simple model for packaging and deploying these localized resources.

For information about resources in ASP.NET, see ASP.NET Web Page Resources Overview.

Creating and Localizing Resources

You can localize your application's resources for specific cultures. This allows you to build localized (translated) versions of your applications. An application loads the appropriate localized resources based on the value of the CultureInfo.CurrentUICulture property. This value is set either explicitly in the application's code or by the common language runtime based on the locale for the current user on the local computer. For more information about how CurrentUICulture is set, see Locating and Using Resources for a Specific Culture and Using the CurrentUICulture Property.

Packaging and Deploying Resources

You can deploy your application's resources in satellite assemblies. By definition, satellite assemblies only contain resource files. They do not contain any application code. In the satellite assembly deployment model, you create an application with one default assembly (which is the main assembly) and several satellite assemblies. You should create one satellite assembly for each culture that the application supports. Because the satellite assemblies are not part of the main assembly, you can easily replace or update resources corresponding to a specific culture without replacing the application's main assembly.

Carefully determine which resources will make up your application's default resource assembly. Because it is a part of the main assembly, any changes to it will require you to replace the main assembly. If you do not provide a default resource, an exception will be thrown when the resource fallback process attempts to find it. In a well-designed application, using resources should never throw an exception.

See Also

Concepts

Using the CurrentUICulture Property

Packaging and Deploying Resources

Reference

CultureInfo.CurrentUICulture

Other Resources

Encoding and Localization