C# 中有没有一种简单的方法可以根据操作系统版本获得条件编译符号
我有一堆单元测试需要根据 Windows 操作系统版本进行条件编译。 此单元测试正在测试仅在 Windows Vista 及更高版本中可用的 TxF。
#if WIN_OS_VERSION >= 6.0
// Run unit tests
#endif
I have a bunch of unit tests that need to be conditional compiled based on Windows OS version.
This unit tests are testing TxF that is only available in Windows Vista and above.
#if WIN_OS_VERSION >= 6.0
// Run unit tests
#endif
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
我认为没有办法根据操作系统版本有条件地编译代码。 #define 的文档指出(重点是我的):
您必须有条件地运行它:
更新: >
之前已经提出过这个问题。
I don't think there's a way to conditionally compile code based on OS version. The documentation for #define states (emphasis mine):
You will have to conditionally run it instead:
Update:
This has been asked before.
您可以自己简单地管理调试符号。
只需提出一个您可以坚持的模式(记录它!),然后当您为新平台进行编译时,只需记住更改处理器指令即可。
例如,您可以有符号
然后您可以使用#ifdef进行条件编译
然后您可以在项目属性中定义这些常量。或者,如果您喜欢冒险,您可能可以定义一个 MSBuild 任务,导出正确的符号以在编译时定义,但这比我的工资等级稍高一些。
You can simply manage the debug symbols yourself.
just come up with a schema that you can stick to (Document It!) and then when you compile for a new platform just remember to change the processor directives.
for example you could have symbols
Then you can use
#ifdef
's to conditionally compileThen you can just define these constants in your project properties. Or if you are feeling adventurous you could probably define an MSBuild Task that exports the correct symbol(s) to define at compilation time, but thats a litle above my pay grade.