0

I have an .msbuild import that defines a property group containing preprocessor definitions, among other things:

<PropertyGroup>
  <DefineConstants>$(DefineConstants);MY_CONSTANT_VALUE</DefineConstants>
</PropertyGroup>

This is <import>ed into both csproj and vcxproj files. At build time, the C# preprocessor appears not to have visibility of the defined constants. However, an equivalent C++ preprocessor definition in the same file works correctly, and the constants are discovered:

<ItemDefinitionGroup>
  <ClCompile>
    <PreprocessorDefinitions>$(PreProcessorDefinitions);MY_CONSTANT_VALUE</PreprocessorDefinitions>
  </ClCompile>
<ItemDefinitionGroup>

Any ideas why this only works in C++?

greenback
  • 1,506
  • 2
  • 17
  • 29

1 Answers1

0

Default property group declaration doesn't cater about previously existed properties and defined like this:

<DefineConstants>TRACE</DefineConstants>

So make sure you are importing your .msbuild file at the end of your .csproj.vbproj, not in the beginning.

If this doesn't help - can you provide a log of msbuild with diagnostic level of verbosity and post link here.

Alexey Shcherbak
  • 3,394
  • 2
  • 27
  • 44
  • 1
    Thanks, I tried importing at the end of the csproj, but the constant was still undefined. In the end I modified in each csproj to contain a new macro that is defined in the .msbuild import. This is fine for now, as I only need the flexibility for pre-processor constants, but would be nice to be able to inherit entire blocks of XML in the same way as vcxproj files. – greenback Sep 25 '14 at 09:59