디버그 빌드에서 릴리스 빌드를 감지하는 가장 좋은 방법은 무엇입니까?.그물

StackOverflow https://stackoverflow.com/questions/50900

  •  09-06-2019
  •  | 
  •  

문제

그래서 mvc 앱에서 사용하는 약 10개의 짧은 CSS 파일이 있습니다.Error.css login.css 등이 있습니다 ...(적어도 나에게는) 쉽게 업데이트하고 편집할 수 있게 해주는 매우 짧은 CSS 파일입니다.내가 원하는 것은 if else 분기를 최적화하고 최종 비트에 통합하지 않는 것입니다.나는 이런 것을하고 싶다

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" /> 
}

모든 CSS 파일을 결합하고 최소화하는 msbuild 작업을 수행하겠습니다.마지막 비트에서 if else 분기를 제거할 수 있는 방법이 있는지 알고 싶습니다.

도움이 되었습니까?

해결책

특히 C#에서는 다음과 같습니다.

#if (DEBUG)
   Debug Stuff
#endif

C#에는 다음과 같은 전처리기 지시문이 있습니다.

#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 

다른 팁

  if (System.Diagnostics.Debugger.IsAttached)
  {
           // Do this
  }
  else
  {
            // Do that
  }

구글을 이용했어야 했는데.

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

프로젝트 속성에서 "구성 설정" -> "빌드" "디버그 상수 정의"옵션이 확인되었는지 확인하십시오.

당신은 사용해 볼 수 있습니다

HttpContext.Current.IsDebuggingEnabled

이는 구성의 노드에 의해 제어됩니다.제 생각에는 이것이 조건부 컴파일보다 더 좋은 솔루션입니다.

그러나 편집을 기반으로 제어하고 싶다면 다음을 사용할 수 있다고 생각합니다. 조건부 속성.

문안 인사,

컴파일러 상수.C# 구문은 기억나지 않지만 VB에서는 다음과 같이 수행합니다.

#If CONFIG = "Debug" Then
  'do somtehing
#Else
  'do something else
#EndIf
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top