Edit

Share via


AssignCulture task

This task accepts a list of items that may contain a valid .NET culture identifier string as part of the file name, and produces items that have a metadata named Culture containing the corresponding culture identifier. For example, the file name Form1.fr-fr.resx has an embedded culture identifier "fr-fr," so this task produces an item that has the same filename with the metadata Culture equal to fr-fr. The task also produces a list of filenames with the culture removed from the filename.

Task parameters

The following table describes the parameters of the AssignCulture task.

Parameter Description
AssignedFiles Optional ITaskItem[] output parameter.

Contains the list of items received in the Files parameter, with a Culture metadata entry added to each item.

If the incoming item from the Files parameter already contains a Culture metadata entry, the original metadata entry is used.

The task only assigns a Culture metadata entry if the file name contains a valid culture identifier. The culture identifier must be between the last two dots in the filename.
AssignedFilesWithCulture Optional ITaskItem[] output parameter.

Contains the subset of the items from the AssignedFiles parameter that have a Culture metadata entry.
AssignedFilesWithNoCulture Optional ITaskItem[] output parameter.

Contains the subset of the items from the AssignedFiles parameter that don't have a Culture metadata entry.
CultureNeutralAssignedFiles Optional ITaskItem[] output parameter.

Contains the same list of items that is produced in the AssignedFiles parameter, except with the culture removed from the file name.

The task only removes the culture from the file name if it's a valid culture identifier.
Files Required ITaskItem[] parameter.

Specifies the list of files with embedded culture names to assign a culture to. The task tries to figure out if each file is a culture-specific resource, and if so, what culture. To skip this detection process and force a file to be culture-neutral, set the metadata entry WithCulture to false.

Remarks

In addition to the parameters listed in this article, this task inherits parameters from the TaskExtension class, which itself inherits from the Task class. For a list of these additional parameters and their descriptions, see TaskExtension base class.

Example

The following example executes the AssignCulture task with the ResourceFiles item collection.

<Project xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
    <ItemGroup>
        <ResourceFiles Include="MyResource1.fr.resx"/>
        <ResourceFiles Include="MyResource2.XX.resx"/>
    </ItemGroup>

    <Target Name="Culture">
        <AssignCulture
            Files="@(ResourceFiles)"
            <Output TaskParameter="AssignedFiles"
                ItemName="OutAssignedFiles"/>
            <Output TaskParameter="AssignedFilesWithCulture"
                ItemName="OutAssignedFilesWithCulture"/>
            <Output TaskParameter="AssignedFilesWithNoCulture"
                ItemName="OutAssignedFilesWithNoCulture"/>
            <Output TaskParameter="CultureNeutralAssignedFiles"
                ItemName="OutCultureNeutralAssignedFiles"/>
        </AssignCulture>
    </Target>
</Project>

The following table describes the value of the output items after task execution. Item metadata is shown in parentheses after the item.

Item collection Contents
OutAssignedFiles MyResource1.fr.resx (Culture="fr")

MyResource2.XX.resx (no additional metadata)
OutAssignedFilesWithCulture MyResource1.fr.resx (Culture="fr")
OutAssignedFilesWithNoCulture MyResource2.XX.resx (no additional metadata)
OutCultureNeutralAssignedFiles MyResource1.resx (Culture="fr")

MyResource2.XX.resx (no additional metadata)

See also