The following, when pasted into the bottom of an F# project, has the suggested effect (if c:\temp\foo.txt
exists, then a #define
for THE_FILE_EXISTS
is added). I expect that only minor modifications would be needed for a C++ project, since they both use MSBuild. This is a little hacky maybe, it is the first thing I got working.
<UsingTask TaskName="SeeIfFileExists" TaskFactory="CodeTaskFactory"
AssemblyFile="$(MSBuildToolsPath)\Microsoft.Build.Tasks.v4.0.dll">
<ParameterGroup>
<Path ParameterType="System.String" Required="true" />
<ItExists ParameterType="System.Boolean" Output="true" />
</ParameterGroup>
<Task>
<Code Type="Fragment" Language="cs">
<![CDATA[
ItExists = System.IO.File.Exists(Path);
]]>
</Code>
</Task>
</UsingTask>
<Target Name="SeeIfFileExistsTarget" BeforeTargets="PrepareForBuild">
<SeeIfFileExists Path="c:\temp\foo.txt" >
<Output TaskParameter="ItExists" ItemName="TheFileExists" />
</SeeIfFileExists>
<PropertyGroup>
<DefineConstants Condition="'@(TheFileExists)'=='True'"
>$(DefineConstants);THE_FILE_EXISTS</DefineConstants>
</PropertyGroup>
</Target>
It just occurred to me that
<PropertyGroup>
<DefineConstants Condition="Exists('c:\temp\foo.txt')"
>$(DefineConstants);THE_FILE_EXISTS</DefineConstants>
</PropertyGroup>
is probably sufficient, but not nearly as sexy.