Is it possible to have conditional compilation for an ASP.NET comment?

I would like to do something like this

<# if ANYPREPROCESSORCONSTANT #>
<%--
<# endif #>

Is it possible (I want to conditionally put asp.net COMMENT, I do not want to call the conditionaly method)?

Update: it seems impossible, finally, no one can give the correct answer :)

+3
source share
3 answers

You can do it:

<% #if DEBUG %>
<div id="debug"></div>
<% #else %>
<div id="release"></div>
<% #endif %>

Although it is not very readable, in my opinion ... use it only when necessary!

+2
source

Yes, you define the compiler constants for the website project in the web.config file, as shown below. Please note that the comment must be completely enclosed in the line #if ... # end if construct. Otherwise, you are commenting on #end if.

<system.codedom>
    <compilers>
        <compiler language="c#;cs;csharp" extension=".cs" type="Microsoft.CSharp.CSharpCodeProvider,System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089" warningLevel="4">
            <providerOption name="CompilerVersion" value="v3.5"/>
            <providerOption name="WarnAsError" value="false"/>
        </compiler>
        <compiler compilerOptions="/d:DEBUG,TRACE,DEBUG_SURVEYCODE,GPT,TRACE_ARGS,TRACE_ARGS_OUTPUT,TRACE_FILES,DEBUG_USER" language="vb;vbs;visualbasic;vbscript" extension=".vb" type="Microsoft.VisualBasic.VBCodeProvider, System, Version=2.0.0.0, Culture=neutral, PublicKeyToken=b77a5c561934e089"/>
    </compilers>
</system.codedom>

 <% #if TRACE_ARGS_OUTPUT %>
 <!-- this traces output comment -->
 <% #end if %>
 <% #if TRACE_ARGS_OUTPUT = FALSE %>
 <!-- this does not output comment -->
 <% #end if %>
+1
source

, , ?

You will have to process the conditional expression in your development time code behind ...

#if SOMEDEFINE
DoSomething();

#endif

0
source

Source: https://habr.com/ru/post/1736041/


All Articles