Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/blackberry/2.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_Msbuild 4.0 - Fatal编程技术网

如何在msbuild中检查文件是否存在且为空

如何在msbuild中检查文件是否存在且为空,msbuild,msbuild-4.0,Msbuild,Msbuild 4.0,我想检查文件是否存在,并且在msbuild中是否为空。如何执行该操作您可以使用Exists和ReadAllText获取文件内容 <Target Name="Build"> <PropertyGroup> <TheFile>C:\Windows\System32\notepad.exe</TheFile> <FileContents Condition="Exists($(TheFile))">$(

我想检查文件是否存在,并且在msbuild中是否为空。如何执行该操作

您可以使用
Exists
ReadAllText
获取文件内容

  <Target Name="Build">  
    <PropertyGroup>
      <TheFile>C:\Windows\System32\notepad.exe</TheFile>
      <FileContents Condition="Exists($(TheFile))">$([System.IO.File]::ReadAllText('C:\\Windows\System32\notepad.exe'))</FileContents>
    </PropertyGroup>
    <Message Condition="'$(FileContents)' != ''" Text="The file is not empty $(FileContents)" />
  </Target>

C:\Windows\System32\notepad.exe
$([System.IO.File]::ReadAllText('C:\\Windows\System32\notepad.exe'))