MSBUILD项目:从另一个项目获取项目列表,并打印出foreach

发布于 2025-01-25 20:45:32 字数 574 浏览 3 评论 0原文

例如,有两个项目:

Main.Proj

<MyCustomItemHa Include="path1"/>
<MyCustomItemHa Include="path2"/>
<MyCustomItemHa Include="path3"/>

还有一个单独的项目

Secondary.Proj

<Target Name="Printtt">
**   How can I execute <Message here for each of paths imported above? **
**   To Get output equivalent to: **
**     <Message Text="path1" />     **
**     <Message Text="path2" />     **
**     <Message Text="path3" />      **
**   for each MyCustomItemHa  from Main.Proj **
</Target>

For example, there are two projects:

Main.Proj

<MyCustomItemHa Include="path1"/>
<MyCustomItemHa Include="path2"/>
<MyCustomItemHa Include="path3"/>

And there is a separate project

Secondary.Proj

<Target Name="Printtt">
**   How can I execute <Message here for each of paths imported above? **
**   To Get output equivalent to: **
**     <Message Text="path1" />     **
**     <Message Text="path2" />     **
**     <Message Text="path3" />      **
**   for each MyCustomItemHa  from Main.Proj **
</Target>

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

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

发布评论

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

评论(1

蓝礼 2025-02-01 20:45:32

MSBUILD是一种声明性的语言,没有循环。 MSBuild中没有foreach循环。

您可以使用任务批处理 - 请参阅 msbuild batching << /a>。

例如,代码

    <ItemGroup>
        <Fruit Include="Apple" />
        <Fruit Include="Banana" />
    </ItemGroup>
    <Target Name="DisplayFruit">
        <Message Text="%(Fruit.Identity)" />
    </Target>

将显示

         Apple
         Banana

两个独立的项目无法“看到”对方,并且无法从彼此中获得itemgroup。但是您可以创建一个定义itemGroup的常见文件,每个项目都可以 import 公共文件。

MSBuild is a declarative language and has no loops. There is no foreach loop in MSBuild.

You can use task batching - see MSBuild batching.

As an example, the code

    <ItemGroup>
        <Fruit Include="Apple" />
        <Fruit Include="Banana" />
    </ItemGroup>
    <Target Name="DisplayFruit">
        <Message Text="%(Fruit.Identity)" />
    </Target>

will display

         Apple
         Banana

Two separate projects can't 'see' each other and can't get an ItemGroup from each other. But you can create a common file that defines the ItemGroup and each project can Import the common file.

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