共用方式為


Localization of Managed Resources and Managed VS Packages

I received the following question recently:

Should I set CurrentThread.CurrentUICulture in my package code?

The CurrentUICulture setting is used to direct the Resource Manager load the correct localized resources out of a managed resource satellite dll.  This is not the same as the VS Package satellite dll which, at present, must be a native resource dll because of the way the VS environment works.  If, on the other hand you have managed resources that you'd like to use that aren't required by VS, then you have the problem of whether or not to set the CurrentUICulture so that the proper localized resources are used.

In most cases you don't have to set the CurrentUICulture.

  1. If your package makes use of the Microsoft.VisualStudio.VSIP.Helper dll in Everett (from the VSIP Extras SDK) or its successor in Whidbey, then the proper CurrentUICulture is set for the the package automatically when it loads, even if the user changes the setting in the VS Tools Options / ... / IntlSettings page.  Note that a restart of VS is required for changes to take effect since the setting is only set at package load. 
  2. If a package is not written using the SDK helper library, then it can and should set the CurrentUICulture when the package loads after using IUIHostLocale2::GetUILocale to retrieve the locale being used by VS.  In most cases this will be a benign operation since the default CurrentUICulture setting from the URT is the same as the default VS value which both come from the OS's GetUserDefaultUILanguage API.

I hope this helps to get your localized managed resources working correctly for your package and to save you from having to write the code yourself.

Allen