MsBuild中项目评估的范围和顺序 [英] Scope and order of evaluation of Items in MsBuild

查看:56
本文介绍了MsBuild中项目评估的范围和顺序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道为什么在下面的代码中,MsBuild拒绝设置后缀元数据.它确实可以使用CreateItem任务而不是ItemGroup声明(因为CreateItem是在构建时计算的),但是我不能在这里执行此操作,因为此代码在属性文件"中:该项目没有目标,只是一堆我包含在实际项目中的属性/项目.

I wonder why in the following code, MsBuild refuses to set the Suffix Metadata. It does work with a CreateItem task instead of the ItemGroup Declaration (because CreateItem is computed at build time) but I can't do this here because this code is in a "property file" : the project has no target, it's just a bunch of properties/items I include in real projects.

<ItemGroup>
        <Layout Include="Bla">
            <PartnerCode>bla</PartnerCode>
        </Layout>
        <Layout Include="Bli">
            <PartnerCode>bli</PartnerCode>
        </Layout>
</ItemGroup>

<ItemGroup Condition="'$(LayoutENV)'=='Preprod'">
        <LayoutFolder Include="Preprod">
            <Destination>..\Compil\layout\pre\</Destination>
        </LayoutFolder>
</ItemGroup>


<ItemGroup>
    <Destinations Include="@(LayoutFolder)" >
        <Suffix>%(Layout.PartnerCode)</Suffix>
    </Destinations>
</ItemGroup>

目的地构建良好,但未设置后缀元数据.

Destinations is well built but the Suffix Metadata is not set.

就目前而言,我已经在我需要的每个项目中复制了目标定义",但它不是很干净.如果有人有更好的解决方案,我会很感兴趣!

As for now, I have duplicated the Destinations Definition in every project I needed it but it's not very clean. If someone has a better solution, I'm interested!

推荐答案

似乎我试图在目标外部动态设置元数据,这是不可能的. 我尝试通过在Layout项上进行批处理来设置后缀元数据,但是在完成批处理时未正确设置Layout项.当msbuild解析我的属性文件时,就完成了批处理,它不等待Layout声明.

It appears that I try to set Metadata dynamically outside a target which is impossible. I try to set the Suffix Metadata by batching over Layout items but Layout items are not properly set when the batching is done. The batching is done when msbuild parse my property files, it does not wait for Layout to be declared.

尽管如此,就像MadGnome指出的那样,我可以对LayoutFolder(这是我的包含项的源项目)进行批处理,因为MSBuild确实在等待声明它.

Nevertheless, like MadGnome pointed out, I can batch over LayoutFolder (which is the source items for my includes) because MSBuild does wait for it to be declared.

这篇关于MsBuild中项目评估的范围和顺序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆