Reputation: 41
I want to check if a file exist and is not empty in msbuild. How do I do that
Upvotes: 4
Views: 1070
Reputation: 3434
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>
Upvotes: 2