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

XmlPeek throws non-specific exception on empty-string result with item output #3399

Open
Adam-S-Daniel opened this issue Jun 11, 2018 · 0 comments
Labels

Comments

@Adam-S-Daniel
Copy link
Contributor

Steps to reproduce

Have the XmlPeek task query XML such that at least one result will be a zero-length string. Include an Output element that uses the ItemName attribute.

Project file (repro.proj)

<Project>
  <PropertyGroup>
    <FooXml>&lt;DriftReport xmlns="http://schemas.microsoft.com/sqlserver/dac/DriftReport/2012/02"&gt;
  &lt;Additions&gt;
    &lt;Object Name="" Parent="[db_owner]" Type="SqlRoleMembership" /&gt;
    &lt;Object Name="[foo\foo]" Parent="" Type="SqlUser" /&gt;
  &lt;/Additions&gt;
  &lt;Removals /&gt;
  &lt;Modifications /&gt;
&lt;/DriftReport&gt;</FooXml>
  </PropertyGroup>
  <Target Name="Default">  
    <ItemGroup>
      <_DriftChangeType Include="Additions">
        <IgnoreType>dummy value</IgnoreType>
      </_DriftChangeType>
      <_DriftChangeType Include="Removals;Modifications">
        <IgnoreType>SqlForeignKeyConstraint</IgnoreType>
      </_DriftChangeType>
    </ItemGroup>
    <XmlPeek
      XmlContent="$(FooXml)"
      Namespaces="&lt;Namespace Prefix='dr' Uri='http://schemas.microsoft.com/sqlserver/dac/DriftReport/2012/02'/&gt;"
      Query="/dr:DriftReport/dr:%(_DriftChangeType.Identity)/*[local-name()='Object' and not(@Type='%(_DriftChangeType.IgnoreType)')]/@Name">
      <Output ItemName="_Drift%(_DriftChangeType.Identity)" TaskParameter="Result" />
    </XmlPeek>
  </Target>
</Project>

Directory contents:

/
- repro.proj

Command line:

msbuild repro.proj /v:diag

Expected behavior

XmlPeek throws exception with text pointing to the root cause, e.g.

C:\foo\repro.proj(27,7): error MSBXXXX: The "XmlPeek" task results included one or more zero length strings. "_DriftAdditions" parameter "Include" cannot have zero length.

Actual behavior

XmlPeek throws an exception with text that makes it difficult to infer the root cause.

Using "XmlPeek" task from assembly "Microsoft.Build.Tasks.Core, Version=15.1.0.0, Culture=neutral, PublicKeyToken=b03f5f7f11d50a3a".
Task "XmlPeek" (TaskId:2)
Task Parameter:XmlContent=<DriftReport xmlns="http://schemas.microsoft.com/sqlserver/dac/DriftReport/2012/02">
<Additions>
<Object Name="" Parent="[db_owner]" Type="SqlRoleMembership" />
<Object Name="[foo\foo]" Parent="" Type="SqlUser" />
</Additions>
<Removals />
<Modifications />
</DriftReport> (TaskId:2)
Task Parameter:Namespaces= (TaskId:2)
Task Parameter:Query=/dr:DriftReport/dr:Additions/*[local-name()='Object' and not(@type='dummy value')]/@name (TaskId:2)
Found "". (TaskId:2)
Found "[foo\foo]". (TaskId:2)
C:\foo\repro.proj(27,7): error MSB4028: The "XmlPeek" task's outputs could not be retrieved from the "Result" parameter. Parameter "includeEscaped" cannot have zero length.
Done executing task "XmlPeek" -- FAILED. (TaskId:2)

Environment data

msbuild /version output:

Microsoft (R) Build Engine version 15.7.179.6572 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.

15.7.179.6572

Key line from MSBuild source

XmlPeek.Execute() adds an invalid Item, with empty string as its Identity/Include value:
https://github.com/Microsoft/msbuild/blob/9ed9a33898750567e1ac653174038e542158cf02/src/Tasks/XmlPeek.cs#L247

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

2 participants