构建配置在C#代码 [英] Build configuration in C# code

查看:105
本文介绍了构建配置在C#代码的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

有谁知道如何在C#代码获取当前构建配置$(配置)?

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

推荐答案

您可以 T,不是真的。
你可以做的是定义一些条件编译符号,如果你看一下你项目设置中的生成页面中,可以设置这些那里,所以你可以声明#如果写测试。

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.

一个DEBUG符号自动注入建立调试(默认情况下,这可以被关闭)。

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 in with different behaviour between debug and release builds is no good to anyone.

这篇关于构建配置在C#代码的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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