locked
Override conditional compilation symbols RRS feed

  • Question

  • How do I override conditional compilation symbols? For instance, a project have TRACE constant defined and i want to undefined it during Team Build.
    Wednesday, October 15, 2008 9:23 PM

Answers

  • You may be hitting a limitation of the C# compiler here depending on what you're trying to do. You could define MYSYMBOL1 and MYSYMBOL2 by putting the following into your .rsp file:

    /p:DefineConstants="MYSYMBOL1;MYSYMBOL2"

    You can't, however assign values to those symbols. This limitation is documented here:
    http://msdn.microsoft.com/en-us/library/0feaad6z(VS.80).aspx

    "The C# #define does not allow a symbol to be given a value, as in languages such as C++. For example, #define cannot be used to create a macro or to define a constant."

    Program Manager, Team Foundation Build
    • Marked as answer by Alex Ivanoff Thursday, October 16, 2008 6:05 PM
    Thursday, October 16, 2008 6:02 PM
    Moderator

All replies

  • Alex, you can do this from your TFSBuild.proj file as follows:

    <PropertyGroup>
        <DefineTrace>False</DefineTrace>
    </PropertyGroup>

    Or, you can set it in your .rsp file as:

    /p:DefineTrace=False

    Alternatively, you could clear the "Define TRACE constant" in your project settings for the configuration you're building with Team Build:


    Program Manager, Team Foundation
    Thursday, October 16, 2008 10:20 AM
    Moderator
  • TRACE was just an example. What If I want to override a couple symbols, MYSYMBOL1 and MYSYMBOL2?
    Thursday, October 16, 2008 2:17 PM
  •  You can use the DefineConstants property to override symbols. If you set a symbols value to an empty string, that's functionally equivalent to "undefining" it as far as MSBuild is concerned.

    <PropertyGroup>
        <DefineConstants>MYSYMBOL1=MYVALUE1;MYSYMBOL2=MYVALUE2</DefineConstants>
    </PropertyGroup>

    Program Manager, Team Foundation
    Thursday, October 16, 2008 3:26 PM
    Moderator
  • How do you override DefineConstants from command line or .rsp file? I tried this:

    /p:DefineConstants=MYSYMBOL1=MYVALUE1%3bMYSYMBOL2=MYVALUE2

    but it did not work: only MYSYMBOL1 was defined.
    Thursday, October 16, 2008 3:31 PM
  • Actually, for that particular case, you could include this in your .rsp file (or on the MSBuild command line):

    /p:MySymbol1=MyOverride1;MySymbol2=MyOverride2
    Program Manager, Team Foundation Build
    Thursday, October 16, 2008 4:06 PM
    Moderator
  • Did you try it? The result is not what you expect: you overriding property MySymbol1, but I need to define compilation symbol.
    Thursday, October 16, 2008 4:14 PM
  • What tool do you need to define a compilation symbol for? CSC.EXE or something else?
    Program Manager, Team Foundation Build
    Thursday, October 16, 2008 5:26 PM
    Moderator
  • A few C# projects and a couple of WiX project.
    Thursday, October 16, 2008 5:44 PM
  • You may be hitting a limitation of the C# compiler here depending on what you're trying to do. You could define MYSYMBOL1 and MYSYMBOL2 by putting the following into your .rsp file:

    /p:DefineConstants="MYSYMBOL1;MYSYMBOL2"

    You can't, however assign values to those symbols. This limitation is documented here:
    http://msdn.microsoft.com/en-us/library/0feaad6z(VS.80).aspx

    "The C# #define does not allow a symbol to be given a value, as in languages such as C++. For example, #define cannot be used to create a macro or to define a constant."

    Program Manager, Team Foundation Build
    • Marked as answer by Alex Ivanoff Thursday, October 16, 2008 6:05 PM
    Thursday, October 16, 2008 6:02 PM
    Moderator
  • Use WriteLinesToFile to create an include or maybe a source file exporting the symbols?  Ugly but you get complete control.
    Thursday, October 16, 2008 10:32 PM