在运行时以编程方式读取目标平台 [英] Programmatically read target platform during run time

查看:32
本文介绍了在运行时以编程方式读取目标平台的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想知道(用于记录目的)商店应用程序是否已针对 x86/x64/AnyCPU/Win32 编译.

我找不到任何东西,但似乎这些信息应该在运行时可用.

解决方案

转到您的项目属性并为每个平台添加一个条件编译符号(在 Build 选项卡中).比方说PLATFORM_X86PLATFORM_X64PLATFORM_ANYCPU(您也可以从命令行使用/D 选项).>

您可以在代码中使用这样的符号:

#if PLATFORM_X86//特定于 X86 构建的代码#万一

如果您需要这样做来记录日志,您可以简单地声明一个常量,如:

#if PLATFORM_X86private const string Platform = "X86";#elif 平台_X64private const string Platform = "X64";#elif 平台_ANYCPUprivate const string Platform = "AnyCPU";#万一

当然,在为 AnyCPU 编译时,您可以使用 Environment.Is64BitProcess 来了解您在何处运行.

I want to know (for logging purposes) if the store application has been compiled for x86 / x64 / AnyCPU / Win32.

I couldn't find anything, but it seems that this information should be available during run time.

解决方案

Go to your project properties and for each platform add a Conditional compilation symbol (in Build tab). Let's say PLATFORM_X86, PLATFORM_X64 and PLATFORM_ANYCPU (you can also use /D option from command line).

You can use such symbols in your code:

#if PLATFORM_X86
    // Code specific for X86 builds
#endif

If you need to do it for logging you may simply declare a constant like:

#if PLATFORM_X86
private const string Platform = "X86";
#elif PLATFORM_X64
private const string Platform = "X64";
#elif PLATFORM_ANYCPU
private const string Platform = "AnyCPU";
#endif

Of course when compiling for AnyCPU you can use Environment.Is64BitProcess to know where you're running on.

这篇关于在运行时以编程方式读取目标平台的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆