确定解决方案配置(Visual Studio) [英] Determine Solutions Configuration (Visual Studio)

查看:112
本文介绍了确定解决方案配置(Visual Studio)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

是否可以通过代码确定正在运行的解决方案配置?例如,调试与发布?。

Is there a way, in code, to determine what "Solutions Configuration" you are running in? For example, 'Debug' vs. 'Release?

我有一个服务,我想在Debug中的IDE中测试,现在我已经设置了bool如果将其设置为true,则运行 service(然后使用OnStart方法运行我的 main方法);如果将其设置为false,则仅运行 main方法。效果很好,但是我经常在测试后忘记重置bool,然后当我去安装该服务时失败了,我必须回去,重置bool,重新编译等。

I have a service that I like to test in the IDE in Debug, right now I have bool that I set which either runs the 'service' if set to true (which then uses the OnStart method to run my 'main' method), if it's set to false I just run the 'main' method. This works great but I often forget to reset the bool after testing and then when I go to install the service it fails and I have to go back, reset the bool, recompile etc.

如果我可以通过编程方式确定我在Debug中正在IDE中运行,那么我可以解决此问题。

If I could just determine programatically that I was running in the IDE in Debug then I could get around this issue.

编辑:
经过深思熟虑,我想我最终真正需要确定的是确定我是否正在玩 ide而不是soulutions配置。这将允许我以调试或其他配置进行编译。

While thinking this through, I guess what I really need in the end is to determine if I'm in the 'playing' the app in the ide and not the soulutions configuration. This would allow me to compile in either debug or other configuration.

最简单的解决方案似乎是在检查'System.Diagnostics.Debugger.IsAttached'

The simpliest solution seems to check 'System.Diagnostics.Debugger.IsAttached'

推荐答案

要确定您是否在IDE中的调试下运行,请查看 Debugger 类,尤其是 IsAttached 财产...

To determine whether you are running under debug in the IDE, look at the Debugger class, specifically the IsAttached property...

这篇关于确定解决方案配置(Visual Studio)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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