如何在运行时获取构建配置? [英] How to obtain build configuration at runtime?

查看:84
本文介绍了如何在运行时获取构建配置?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有人知道如何使用C#代码获取当前的构建配置 $(Configuration)吗?

解决方案

您不能,不是真的。
您可以做的是定义一些条件编译符号,如果您查看项目设置的生成页面,则可以在此处进行设置,以便编写#if语句进行测试。

会自动注入一个DEBUG符号(默认情况下,可以将其关闭)以进行调试。



可以这样写代码

  #if DEBUG 
RunMyDEBUGRoutine();
#else
RunMyRELEASERoutine();
#endif

但是,除非您有充分的理由,否则不要这样做。一个在调试版本和发行版本之间行为不同的应用程序对任何人都没有好处。


Does anyone know how to get the current build configuration $(Configuration) in C# code?

解决方案

You can't, not really. What you can do is define some "Conditional Compilation Symbols", if you look at the "Build" page of you project settings, you can set these there, so you can write #if statements to test them.

A DEBUG symbol is automatically injected (by default, this can be switched off) for debug builds.

So you can write code like this

#if DEBUG
        RunMyDEBUGRoutine();
#else
        RunMyRELEASERoutine();
#endif

However, don't do this unless you've good reason. An application that works with different behavior between debug and release builds is no good to anyone.

这篇关于如何在运行时获取构建配置?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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