Target platform/processor at compile time

后端 未结 3 2042
鱼传尺愫
鱼传尺愫 2021-01-12 06:40

Is there a #define in C# that allows me to know, at compile time, if I\'m compiling for x86 (Win32) or x64 (Win64)?

3条回答
  •  温柔的废话
    2021-01-12 07:01

    By default there is no way to do this. The reason is that C# code is not designed to target a particular platform as it runs on the CLR.

    It is possible to hand roll this though. You can use the project configuration settings in Visual Studio to define your own constants. Or if you want it a little more streamline you can edit the .csproj yourself and hand roll some more configurations which have various defines.

    For instance you can make your project file look like the following. I removed some of the information to make the x86/amd64 information clear.

      
        
        TRACE;DEBUG;X86
      
      
        
        TRACE;DEBUG;AMD64
        prompt
        4
      
    

    Adding this to a .csproj file gives me 2 new platform configurations in my project.

提交回复
热议问题