Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to check if a file exist and is empty in msbuild

I want to check if a file exist and is not empty in msbuild. How do I do that

like image 886
Amin Avatar asked Oct 14 '25 03:10

Amin


1 Answers

You can use Exists and ReadAllText to get the contents of a file.

  <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>
like image 96
Michael Baker Avatar answered Oct 18 '25 04:10

Michael Baker



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!