众所周知的元数据MSBuild 3.5 中的通配符

发布于 2024-09-27 14:59:56 字数 1036 浏览 0 评论 0原文

我目前正在尝试使用 MSBuild 来设置项目,但遇到了一些通配符问题。

我正在尝试使用以下代码片段:

<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Xsd Include="App_Data\*.xsd">
      <Generator>MSDataSetGenerator</Generator>
      <LastGenOutput>%(Xsd.Filename).Designer.cs</LastGenOutput>
      <SubType>Designer</SubType>
    </Xsd>
    <Xss Include="App_Data\*.xss">
      <DependentUpon>%(Xss.Filename).xsd</DependentUpon>
    </Xss>
    <Xsc Include="App_Data\*.xsc">
      <DependentUpon>%(Xsc.Filename).xsd</DependentUpon>
    </Xsc>
  </ItemGroup>
  <Target Name="PrintMetaData">
    <Message Text="@(Xss->'%(DependentUpon)')"/>
  </Target>
</Project>

使用 3.5 版本的 MSBuild 我得到以下输出:

“.xsd;.xsd;.xsd;.....etc.xsd;”

使用 4.0 版本的 MSBuild 我得到了预期的结果:文件名列表。

有谁知道这是否是一个已知的解决方法问题,或者是否有我缺少的 MSBuild 补丁?

谢谢!

I'm currently trying to use MSBuild to set up a project, and am having some issues with wildcards.

I'm trying to use the following snippet:

<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <Xsd Include="App_Data\*.xsd">
      <Generator>MSDataSetGenerator</Generator>
      <LastGenOutput>%(Xsd.Filename).Designer.cs</LastGenOutput>
      <SubType>Designer</SubType>
    </Xsd>
    <Xss Include="App_Data\*.xss">
      <DependentUpon>%(Xss.Filename).xsd</DependentUpon>
    </Xss>
    <Xsc Include="App_Data\*.xsc">
      <DependentUpon>%(Xsc.Filename).xsd</DependentUpon>
    </Xsc>
  </ItemGroup>
  <Target Name="PrintMetaData">
    <Message Text="@(Xss->'%(DependentUpon)')"/>
  </Target>
</Project>

using the 3.5 version of MSBuild I get the following output:

".xsd;.xsd;.xsd;.....etc.xsd;"

using the 4.0 version of MSBuild I get the expected result: a list of the filenames.

Does anyone know if this is a known issue with a workaround, or if there's a patch for MSBuild I'm missing?

Thanks!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

难得心□动 2024-10-04 14:59:56

我有一个非常相似的问题。请参阅:MsBuild 中项目的评估范围和顺序 .

使用 4.0 之前的 MSBuild,您无法通过同时批处理其自己众所周知的元数据来声明项目并设置其一些元数据。

也不要忘记,在解析开始时,目标之外的项目会被评估一次。因此,您无法使用 4.0 之前的 MSBuild 在目标之外进行批处理。因此,解决方法可能是将批处理部分(或整个声明放入目标中):

<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <XsdFiles Include="App_Data\*.xsd">
      <Generator>MSDataSetGenerator</Generator>
      <SubType>Designer</SubType>
    </XsdFiles>
    <XssFiles Include="App_Data\*.xss" />
    <XscFiles Include="App_Data\*.xsc" />
  </ItemGroup>
  <Target Name="PrintMetaData">
    <ItemGroup>
      <Xsd Include="@(XsdFiles)">
        <LastGenOutput>%(XsdFiles.Filename).Designer.cs</LastGenOutput>
      </Xsd>
      <Xss Include="@(XssFiles)">
        <DependentUpon>%(XssFiles.Filename).xsd</DependentUpon>
      </Xss>
      <Xsc Include="@(XscFiles)">
        <DependentUpon>%(XscFiles.Filename).xsd</DependentUpon>
      </Xsc>
    </ItemGroup>
    <Message Text="@(Xss->'%(DependentUpon)')"/>
  </Target>
</Project>

如果您想将整个 ItemGroup 放入目标中,请不要忘记仅在声明项目后通过批处理来设置元数据。您必须分两步完成此操作。

I had a quite similar problem. See : Scope and order of evaluation of Items in MsBuild .

With MSBuild prior to 4.0 you cannot declare an item and set some of his Metadata by batching over its own well-known metadata at the same time.

Don't also forget that Items outside of Targets are evaluated once, in the beginning of the parsing. Thus, you cannot do batching outside of targets with MSBuild prior to 4.0. So a workaround could be to put your batching part (or the whole declaration in your target) :

<Project ToolsVersion="3.5" xmlns="http://schemas.microsoft.com/developer/msbuild/2003">
  <ItemGroup>
    <XsdFiles Include="App_Data\*.xsd">
      <Generator>MSDataSetGenerator</Generator>
      <SubType>Designer</SubType>
    </XsdFiles>
    <XssFiles Include="App_Data\*.xss" />
    <XscFiles Include="App_Data\*.xsc" />
  </ItemGroup>
  <Target Name="PrintMetaData">
    <ItemGroup>
      <Xsd Include="@(XsdFiles)">
        <LastGenOutput>%(XsdFiles.Filename).Designer.cs</LastGenOutput>
      </Xsd>
      <Xss Include="@(XssFiles)">
        <DependentUpon>%(XssFiles.Filename).xsd</DependentUpon>
      </Xss>
      <Xsc Include="@(XscFiles)">
        <DependentUpon>%(XscFiles.Filename).xsd</DependentUpon>
      </Xsc>
    </ItemGroup>
    <Message Text="@(Xss->'%(DependentUpon)')"/>
  </Target>
</Project>

If you want to put the whole ItemGroup in your target, don't forget to set the metadata by batching only once your item is declared. You must do this in two steps.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文