none
Setting SupportedCultures for a Silverlight project RRS feed

  • Question

  • Hi,

    I am the author of a localization tool, which is an Add-In for Visual Studio.

    This question is related to adding localization support to Silverlight projects.

    It is fairly well documented in the community, that one step in adding localization support to Silverlight projects is to open the project file in an editor and modify the SupportedCultures property.

    E.g.

    <?xml version="1.0" encoding="utf-8"?>
    <Project ToolsVersion="4.0" DefaultTargets="Build" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
      <PropertyGroup>
      ...
        <SupportedCultures>en;nl</SupportedCultures>
    ...
      </PropertyGroup>
    ...
    

    You can google for "Silverlight SupportedCultures" to find information about this.

    Obviously, this is the kind of activity which a localization tool should do automatically. The question is, how?

    I guess that I could programatically unload the project, edit the file and reload the project, but this hardly seems like a good solution. There is surely some way to access this property using Visual Studio extensibility.

    This property is not in the normal project.properties collection. How can I access it?

    Thanks in advance,
    Phil

    Saturday, September 24, 2011 7:28 AM

Answers

  • HI Phil,

    You may take a look Microsoft.Build which provide programmatic access to, and control of, the MSBuild engine.

    However, as far as I know, we unable to modify the project build property directly when the project is loaded by VS, it will cause some IO issue.

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 29, 2011 2:00 AM
    Moderator

All replies

  • Hi Phil,

    Not all the properties of the msbuild script  have the corresponding properties of the project automation object. As far as I know, there is no defined “SupportedCultures” property for a Silverlight project documented. I believe it is required for one of the Silverlight based msbuild tasks but not for project itself.

     

    Based on the document How to: Create a Build that Targets a Specific Culture, the <SupportedCultures> is used to define builds to create targeted versions of your localized Silverlight-based application. It is a build behavior but not a project, the project can contains more culture supporting rather than the build version we defined.

     

    Of course, modify the property directly is a workaround for sure. In addition, you can try to override the SupportedCultures property when you want to build the project in your add-in. E.g. you can call an external msbuild process using /P to override the any properties from your add-in to build a specific language version output. More information about properties override, please see:   http://msdn.microsoft.com/en-us/library/ms164311.aspx

     

    We are not familiar with Silverlight, you may visit our Silverlight forums for better support. http://forums.silverlight.net/

     

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, September 26, 2011 6:07 AM
    Moderator
  • Hello,

    Would you mind letting me know the result of the suggestions? If you need further assistance, feel free to let me know. I will be more than happy to be of assistance.

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Wednesday, September 28, 2011 8:10 AM
    Moderator
  • Hello Yi,

    Thank you for the reply.

    The link you provided (How to: Create a Build that Targets a Specific Culture) describes the situation exactly. To support multiple cultures you have to unload the project and edit the project file directly. I already know that this works, but I want my Add-In to make this modification automatically.

    Although there is no user interface, Microsoft have (in that article) documented this method, so it seems the right thing to do.

    I don't want to add any build-actions to my Add-In, because I don't expect users to keep the Add-In loaded all of the time. I expect users to open the Add-In, use it to work on localization, and then close it. Users who are not involved in the localization will not even install the Add-In, but the build should still work correctly.

    If it is a build property, is there some generic way to access these properties by name?

    I have already looked though project.ConfigurationManager.ActiveConfiguration.Properties, without finding the SupportedCultures property. Is there some lower level method? (But not quite as low level as unloading, editing and reloading the project.)

    Best regards
    Phil

    Wednesday, September 28, 2011 11:10 PM
  • HI Phil,

    You may take a look Microsoft.Build which provide programmatic access to, and control of, the MSBuild engine.

    However, as far as I know, we unable to modify the project build property directly when the project is loaded by VS, it will cause some IO issue.

    Regards,

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Thursday, September 29, 2011 2:00 AM
    Moderator
  • Hello,

    I am writing to check the status of the issue on your side.  Would you mind letting us know the result of the suggestions? 

    Yi


    Yi Feng Li [MSFT]
    MSDN Community Support | Feedback to us
    Get or Request Code Sample from Microsoft
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, October 3, 2011 2:11 AM
    Moderator