2008-09-08 11 views
7

तो मेरे पास लगभग 10 छोटी सीएसएस फ़ाइलें हैं जिनका उपयोग मैं एमवीसी ऐप के साथ करता हूं। त्रुटि.css login.css आदि ... बस कुछ वास्तव में छोटी सीएसएस फ़ाइलें जो अद्यतन और संपादन को आसान बनाती हैं (कम से कम मेरे लिए)। मैं जो चाहता हूं वह कुछ ऐसा है जो अन्य शाखा को अनुकूलित करेगा और अंतिम बिट्स के भीतर इसे शामिल नहीं करेगा। मैं इसएक डिबग बिल्ड से रिलीज निर्माण का पता लगाने का सबसे अच्छा तरीका? .NET

if(Debug.Mode){ 

<link rel="stylesheet" type="text/css" href="error.css" /> 
<link rel="stylesheet" type="text/css" href="login.css" /> 
<link rel="stylesheet" type="text/css" href="menu.css" /> 
<link rel="stylesheet" type="text/css" href="page.css" /> 
} else { 
<link rel="stylesheet" type="text/css" href="site.css" /> 
} 

की तरह कुछ मैं एक MSBuild कार्य है कि, सभी सीएसएस फ़ाइलें गठबंधन होगा उन्हें कम करने और यह सब अच्छी चीजें होगा करना चाहते हैं। मुझे सिर्फ यह जानने की जरूरत है कि अंतिम बिट्स में अगर शाखा को हटाने का कोई तरीका है या नहीं।

+0

Stackoverflow में समानता सवाल, एक सवाल है, और कई, कई अलग अलग जवाब: http://stackoverflow.com/questions/654450/programatically-detecting-release-debug-mode-net http://stackoverflow.com/questions/798971/how-to-idenfiy-if-the-dll-is-debug-or-release-build-in-net http://stackoverflow.com/questions/1 9 4616/कैसे-to-tell-if-net-app-was-compiled-in-debug-or-release-mode http://stackoverflow.com/questions/50900/best-way-to-detect- ए-रिलीज-बिल्ड-ए-डीबग-बिल्ड-नेट http://stackoverflow.com/questions/890459/asp-net-release-build-vs-debug-build – Kiquenet

+0

कृपया मेरी पोस्ट देखें: [कैसे बताएं कि कोई असेंबली डीबग या रिलीज है या नहीं) (http: //dave-black.blogspot.com/2011/12/how-to-tell-if-assembly-is-debug-or.html) और [http://stackoverflow.com/questions/798971/how-to -idenfiy-अगर-dll-है-डिबग या रिहाई-बिल्ट-इन-नेट/5316565 # 5316565] (http://stackoverflow.com/questions/798971/how-to-idenfiy-if-the- डीएलएल-आईएस-डीबग-या-रिलीज-बिल्ड-इन-नेट/5316565 # 5316565) –

उत्तर

27

विशेष रूप से, इस तरह:

:

#if (DEBUG) 
    Debug Stuff 
#endif 

सी # निम्नलिखित पूर्वप्रक्रमक निर्देशों है

#if 
#else 
#elif // Else If 
#endif 
#define 
#undef // Undefine 
#warning // Causes the preprocessor to fire warning 
#error // Causes the preprocessor to fire a fatal error 
#line // Lets the preprocessor know where this source line came from 
#region // Codefolding 
#endregion 
5

मुझे Google का उपयोग करना चाहिए था। > "बिल्ड" "परिभाषित करें डीबग निरंतर" परियोजना संपत्तियों में चेक किया गया है -

#if DEBUG 
    Console.WriteLine("Debug mode.") 
#else 
    Console.WriteLine("Release mode.") 
#endif 

सुनिश्चित करें कि विकल्प "विन्यास सेटिंग्स" बनाओ।

1

कंपाइलर स्थिरांक। मैं सी # वाक्यविन्यास याद नहीं है, लेकिन यह कैसे मैं VB में यह करना है: सी # में

#If CONFIG = "Debug" Then 
    'do somtehing 
#Else 
    'do something else 
#EndIf 
7
if (System.Diagnostics.Debugger.IsAttached) 
    { 
      // Do this 
    } 
    else 
    { 
      // Do that 
    } 
+5

यह आपको डिबगर संलग्न होने पर (रनटाइम पर) बताता है, लेकिन यदि असेंबली डेबग (बनाम रिलीज) बिल्ड नहीं है। – AlfredBr

4

आप उपयोग करने के लिए कोशिश कर सकते हैं

HttpContext.Current.IsDebuggingEnabled 

इसे कॉन्फ़िगरेशन में नोड द्वारा नियंत्रित किया जाता है। मेरी राय में यह सशर्त संकलन की तुलना में अच्छा समाधान है।

हालांकि यदि आप एक compilatino के आधार पर नियंत्रण करने में सक्षम होना चाहते हैं तो मुझे लगता है कि आप ConditionalAttribute का उपयोग कर सकते हैं।

सादर,

+1

यह स्पष्ट रूप से केवल एएसपी.NET अनुप्रयोगों के लिए काम करता है। –