다음을 통해 공유


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 will produce 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 do not 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 is a valid culture identifier.

Files

Required ITaskItem[] parameter.

Specifies the list of files with embedded culture names to assign a culture to.

Remarks

In addition to the parameters listed above, 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="https://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 parenthesis 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

Concepts

MSBuild Tasks

Other Resources

MSBuild Task Reference