Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

How to pass item (ITaskItem) with all metadata into the task? #5877

Open
Denis535 opened this issue Nov 11, 2020 · 3 comments
Open

How to pass item (ITaskItem) with all metadata into the task? #5877

Denis535 opened this issue Nov 11, 2020 · 3 comments
Labels
Milestone

Comments

@Denis535
Copy link

When you use %(Item.Identity) syntax then MSBuild creates new item with the same Identity. So, all other metadata is lost!

<PrintItem Reference="%(ReferencePath.Identity)" /> // Metadata is lost

<UsingTask TaskName="PrintItem" TaskFactory="CodeTaskFactory" AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.Core.dll">
    <ParameterGroup>
        <Item ParameterType="Microsoft.Build.Framework.ITaskItem" Required="true" />
    </ParameterGroup>
    <Task>
        <Using Namespace="System" />
        <Code Type="Fragment" Language="cs">
            <![CDATA[
            Log.LogMessage( MessageImportance.High, "Item: {0}", Item );
            foreach (var metadata in Item.MetadataNames.Cast<string>()) {
                Log.LogMessage( MessageImportance.High, "Metadata: {0} = {1}", metadata, Item.GetMetadata( metadata ) );
            }
            ]]>
        </Code>
    </Task>
</UsingTask>

<ItemGroup>
    <NewItem Include="%(Item.Identity)" /> // Metadata is lost
</ItemGroup>

Is there a way to avoid losing metadata?

@Denis535 Denis535 added bug needs-triage Have yet to determine what bucket this goes in. labels Nov 11, 2020
@Denis535
Copy link
Author

This works but looks strange.

<PrintItem Reference="@(ReferencePath)" Condition="%(ReferencePath.Identity) != ''" />

@rainersigwald
Copy link
Member

That's the standard idiom.

@rainersigwald rainersigwald added this to the Discussion milestone Nov 12, 2020
@rainersigwald rainersigwald removed bug needs-triage Have yet to determine what bucket this goes in. labels Nov 12, 2020
@danmoseley
Copy link
Member

Ideally the task accepts the list and loops over it -- that is why it looks clunky when you have to pass one at a time.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

4 participants