I am trying to use a Directory.Build.props file to define a simple preprocessor constant for to my solution.
For testing purposes I created a console application (C#) and added a Directoy.Build.props file right next to the generated .csproj file:
<Project>
<PropertyGroup>
<DefineConstants>TEST1</DefineConstants>
</PropertyGroup>
</Project>
I also manually edited the .csproj itself to test the <DefineConstants>
actually works:
<DefineConstants>DEBUG;TRACE;TEST2;</DefineConstants>
Now the actual code:
static void Main(string[] args)
{
#if TEST1
// NOT WORKING!
Console.WriteLine("<DefineConstants>TEST1</DefineConstants> in Directory.Build.props"); // NOT WORKING!
#else
Console.WriteLine("failed TEST1 in Directory.Build.props");
#endif
#if TEST2
// WORKS!
Console.WriteLine("<DefineConstants>TEST2</DefineConstants> in csproj"); // WORKS!
#else
Console.WriteLine("failed TEST2 in csproj");
#endif
}
So why does MSBuild fails to find my constant in Directory.Build.props?