如何在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'))