第一种:需要把调试方法改成debug
代码用 #if debug 包裹
using system; using system.collections.generic; using system.text; using system.io; namespace splitpackage { public static class envconfig { static envconfig() { #if debug toolspath = @"d:\workspace\shopstyle\tool"; #else toolspath = environment.currentdirectory; #endif int rootidx = toolspath.lastindexof(@"\"); if (rootidx > 0) { rootpath = toolspath.substring(0, rootidx); } } public static string toolspath { get; private set; } public static string tmplatefile { get { return path.combine(toolspath, @"template\default.pm"); } } public static string rootpath { get; private set; } public static string modulepath { get { return path.combine(rootpath, "module"); } } public static string configpath { get { return path.combine(rootpath, "conf"); } } } }
第二种:
利用宏定义
#define debug// c#的宏定义必须出现在所有代码之前。当前我们只让debug宏有效。
using system.diagnostics; //必须包含这个包
#define debug using system.diagnostics; namespace testconsole { class toolkit { [conditionalattribute("li")] // attribute名称的长记法 [conditionalattribute("debug")] public static void method1() { console.writeline("created by li, buged.11"); } [conditionalattribute("li")] [conditionalattribute("nobug")] public static void method2() { console.writeline("created by li, nobug."); } [conditional("zhang")] // attribute名称的短记法 [conditional("debug")] public static void method3() { console.writeline("created by zhang, buged.11"); } [conditional("zhang")] [conditional("nobug")] public static void method4() { console.writeline("created by zhang, nobug."); } } static void main(string[] args) { toolkit.method1(); toolkit.method2(); toolkit.method3(); toolkit.method4(); } } }
如对本文有疑问, 点击进行留言回复!!
使用Visual Studio2019创建C#项目(窗体应用程序、控制台应用程序、Web应用程序)
C#实现获取本地内网(局域网)和外网(公网)IP地址的方法分析
浅谈Visual Studio 2019 Vue项目的目录结构
网友评论