Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/tfs/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用msbuild扩展包验证文件夹是否存在?_Msbuild - Fatal编程技术网

使用msbuild扩展包验证文件夹是否存在?

使用msbuild扩展包验证文件夹是否存在?,msbuild,Msbuild,如何使用msbuild扩展包任务可靠地验证文件夹的存在 如何在不抛出错误和停止生成的情况下执行此操作?您可以在目标上使用Exists条件吗 仅当与msbuild文件位于同一目录中时,才会执行OnlyIfExists目标 <ItemGroup> <TestPath Include="Testing" /> </ItemGroup> <Target Name="OnlyIfExists" Condition="Exists(@(TestPath))"

如何使用msbuild扩展包任务可靠地验证文件夹的存在


如何在不抛出错误和停止生成的情况下执行此操作?

您可以在目标上使用Exists条件吗

仅当与msbuild文件位于同一目录中时,才会执行OnlyIfExists目标

<ItemGroup>
    <TestPath Include="Testing" />
</ItemGroup>
<Target Name="OnlyIfExists" Condition="Exists(@(TestPath))">
    <Message Text="This ran!" Importance="high" />
</Target>

不需要使用扩展包,MSBuild可以很好地处理这个问题。您需要考虑这是否是可能作为生成的一部分创建或删除的文件夹。如果是,则需要确保使用在目标中声明的动态项目组(在检查多个文件夹的情况下),或者如果只检查一个文件夹,则可以使用路径。此示例显示了以下两个方面:

<Target Name="MyTarget">
   <!-- single folder with property -->
   <PropertyGroup>
      <_CheckOne>./Folder1</_CheckOne>
      <_CheckOneExistsOrNot
          Condition="Exists('$(_CheckOne)')">exists</_CheckOneExistsOrNot>
      <_CheckOneExistsOrNot
          Condition="!Exists('$(_CheckOne)')">doesn't exist</_CheckOneExistsOrNot>
   </PropertyGroup>
   <Message
      Text="The folder $(_CheckOne) $(_CheckOneExistsOrNot)"
      />

   <!-- multiple folders with items -->
   <ItemGroup>
      <_CheckMultiple Include="./Folder2" />
      <_CheckMultiple Include="./Folder3" />
   </ItemGroup>
   <Message
      Condition="Exists('%(_CheckMultiple.Identity)')"
      Text="The folder %(_CheckMultiple.Identity) exists"
      />
   <Message
      Condition="!Exists('%(_CheckMultiple.Identity)')"
      Text="The folder %(_CheckMultiple.Identity) does not exist"
      />
</Target>

/文件夹1
存在
不存在