简体   繁体   English

#if debug - > #if myOwnConfig?

[英]#if debug --> #if myOwnConfig?

is there a way in c# to use a custom Configuration like "#if DEBUG" 在c#中有一种方法可以使用像“#if DEBUG”这样的自定义配置

I need a "#if OFFLINE" as my Build-Config's name is "Offline" (only for further debug-purposes too)... 我需要一个“#if OFFLINE”,因为我的Build-Config名称是“离线”(仅用于进一步的调试目的)...

Thanks! 谢谢!

  1. Build -> Configuration manager -> Active solution configuration -> New... Build - > Configuration manager - > Active solution configuration - > New ...
  2. Create a new configuration "Offline". 创建一个新的配置“离线”。
  3. Project -> Properties -> Build -> Configuration -> Offline 项目 - >属性 - >构建 - >配置 - >离线
  4. Conditional compilation symbols: type OFFLINE 条件编译符号:键入OFFLINE
  5. Save project. 保存项目。

Yes, you can. 是的你可以。 But before you can, follow these steps: 但在您可以之前,请按照下列步骤操作:

  1. In Visual Studio, go to Properties -> Build. 在Visual Studio中,转到“属性” - >“构建”。
  2. At the configuration dropdown, select "Offline" 在配置下拉列表中,选择“离线”
  3. Add "OFFLINE" to the "Conditional compilation symbols" text box 将“OFFLINE”添加到“条件编译符号”文本框中

If you skip these steps, your #if OFFLINE won't work because in that case, OFFLINE isn't defined. 如果跳过这些步骤,则#if OFFLINE将无效,因为在这种情况下,未定义OFFLINE

I followed exactly the same steps as above. 我按照与上面完全相同的步骤进行操作。 But they are not working. 但他们没有工作。 They are missing one steps or they didn't explain this clearly. 他们缺少一步,或者他们没有清楚地解释这一点。

When you are doing step 4. Conditional compilation symbols: type OFFLINE. 当您执行步骤4.条件编译符号:键入OFFLINE。 You also need to uncheck "Define DEBUG constant". 您还需要取消选中“Define DEBUG constant”。 Otherwise the new symbol OFFLINE won't work. 否则新符号OFFLINE将不起作用。

I posted this here in case someone wasted lots of time as me when try to do the same thing. 我在这里发布这个以防万一有人在尝试做同样的事情时浪费了很多时间。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM