Solution-wide #define

前端 未结 11 2301
予麋鹿
予麋鹿 2020-12-05 09:29

Is there a way to globally declare a #define?

Like I want to have a file that has for instance,

#define MONO

and I want all source-

11条回答
  •  谎友^
    谎友^ (楼主)
    2020-12-05 09:52

    In case you have both C# and C++ projects in the solution and need to share preprocessor definitions among them. Create some SolutionDefines.targets file near your *.sln as follows

    
    
        
            $(DefineConstants);MY_DEFINITION
        
      
        
          MY_DEFINITION;%(PreprocessorDefinitions)
        
      
    
    

    Then add to C/C++/C# *.vcproj/*.vcxproj/*.csproj project files this line somewhere in the end

    
    

    Ok, now you can enjoy #if MY_DEFINITION in C# and #ifdef MY_DEFINITION in C/C++. Visual Studio C# editor doesn't like this way and tells there is no MY_DEFINITION defined. But, C# compiler csc.exe gets the symbol properly.

提交回复
热议问题