I want to check if a file exist and is not empty in msbuild. How do I do that
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With