如果项目列表中缺少任何文件,我想运行任务。我该怎么做?
我当前的脚本有一个“源”文件列表@(MyComFiles),我使用以下任务翻译另一个“目标”文件列表@(MyInteropLibs):
<CombinePath BasePath="$(MyPath)\interop"
Paths="@(MyComFiles->'%(filename).%(extension)')">
<Output TaskParameter="CombinedPaths"
ItemName="MyInteropLibs" />
</CombinePath>
我想检查 @(MyInteropLibs) 中的任何文件是否丢失并运行一个任务来创建它们。
最佳答案
如果您只需要创建丢失的文件,而不需要获取丢失文件的列表,您可以使用 touch task ,如果文件不存在,则会创建。
<Touch Files="@(MyInteropLibs)" AlwaysCreate="True" />
如果您只想创建丢失的文件,并避免更改现有文件的时间戳,那么批处理可以提供帮助
<Touch Files="%(MyInteropLibs.FullPath)" AlwaysCreate="True"
Condition=" ! Exists(%(MyInteropLibs.FullPath)) "/>
如果您想要创建的文件列表,则
<Touch Files="%(MyInteropLibs.FullPath)" AlwaysCreate="True"
Condition=" ! Exists(%(MyInteropLibs.FullPath)) ">
<Output TaskParameter="TouchedFiles" ItemName="CreatedFiles"/>
</Touch>
<Message Text="Created files = @(CreatedFiles)"/>
关于msbuild - 如何使用 msbuild 检查项目列表中是否存在任何文件?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/802070/