Reuse define statement from .h file in C# code

前端 未结 7 1886
广开言路
广开言路 2021-01-18 14:08

I have C++ project (VS2005) which includes header file with version number in #define directive. Now I need to include exactly the same number in twin C# project. What is th

相关标签:
7条回答
  • 2021-01-18 14:39

    You could always use the pre-build event to run the C preprocessor on the .cs file and the post build event to undo the pre-build step. The preprocessor is just a text-substitution system, so this is possible:

    // version header file
    #define Version "1.01"
    
    // C# code
    #include "version.h"
    // somewhere in a class
    string version = Version;
    

    and the preprocessor will generate:

    // C# code
    // somewhere in a class
    string version = "1.01";
    
    0 讨论(0)
提交回复
热议问题