none
What does BuildMacro actually do

    Question

  • When I create property sheets in C++ projects in VS, at least in 10 or 12, if I create what the GUI calls "User Macros" I see the appear in resultant property sheet file as properties in a <PropertyGroup> element which I understand. However the properties also appear later in the file in an <ItemGroup> like this

      <ItemGroup>
        <BuildMacro Include="Foo">
          <Value>$(Foo)</Value>
        </BuildMacro>

    </ItemGroup>

    My question is what does this do? Does this mean I can use these properties in some way that I can't if they just properties in the <PropertyGroup>? Why would I care if they appear as items in the item group as well? Does <BuildMacro> have some special meaning to MSBuild independent of VS or is this just  for VS internal use?

    I have done some experimentation and looked on line but not found anything useful.

    Friday, January 18, 2013 6:36 PM

All replies

  • OK, so after more playing I found one thing that it does. It seems to make the property editable in the Visual Studio "User Macro" property screen. If I remove the <BuildMacro> for a given property it disappears. This makes some sense as you presumably don't want the property editor to show world + dog properties. The syntax does seem very convoluted though if the sole purpose it to convey what is in effect a boolean flag. So does it do anything else?
    Friday, January 18, 2013 9:46 PM
  • Hi,

    As you definition, we can learn that %(BuildMacro.Value) equals $(Foo).

    We can set $(Foo) via msbuild command like: msbuild <project name> /p: zoo=<value>

    About more information of item definition, please view:

    http://msdn.microsoft.com/en-us/library/bb651788.aspx

    Best regards,


    Ego [MSFT]
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    Monday, January 21, 2013 6:57 AM
  • If you search for "BuildMacro" in the *.targets files installed under "C:\Program Files (x86)\MSBuild", you'll see that the SetUserMacroEnvironmentVariables target in Microsoft.Cpp.targets collects all the BuildMacro items that have an EnvironmentVariable metadata with the value "true", and sets an environment variable for each.  This would have been more difficult to implement if the property sheet only defined properties rather than BuildMacro items.

    It seems the target also creates a property for each such BuildMacro item, via TaskParameter="OutputEnvironmentVariable".  I don't know why it does that; hasn't the property sheet already created those properties?

    Wednesday, January 23, 2013 5:46 PM