加入收藏 | 设为首页 | 会员中心 | 我要投稿 李大同 (https://www.lidatong.com.cn/)- 科技、建站、经验、云计算、5G、大数据,站长网!
当前位置: 首页 > 编程开发 > asp.Net > 正文

asp.net – .aspx文件中的条件编译

发布时间:2020-12-16 06:53:03 所属栏目:asp.Net 来源:网络整理
导读:我需要.ASPX文件基于条件编译符号表现不同. 让我们说一个简单的例子: %@ Control Language="C#" AutoEventWireup="true" (...) %% #ifdef DEBUG % asp:SomeDebugControlHere runat="server"/ .. well .. a LOT of code here% #else % asp:SomeReleaseContro
我需要.ASPX文件基于条件编译符号表现不同.

让我们说一个简单的例子:

<%@ Control Language="C#" AutoEventWireup="true" (...) %>
<% #ifdef DEBUG %>
     <asp:SomeDebugControlHere runat="server"/>
     .. well .. a LOT of code here
<% #else %>
    <asp:SomeReleaseControlHere runat="server"/>
    .. and a LOT of other code here
<% #endif %>

后来编辑:更多澄清.问题是SomeDebugControlHere类甚至没有在发布版本中定义(它在现实生活中更复杂,但是请注意这个例子).所以在page.aspx.designer.cs中我需要在调试版本中得到这个:

/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.SomeDebugControlHere myControl

这在发布版本中:(并且从不都是)

/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.SomeReleaseControlHere myControl

显然我需要ASPX文件中的标记不同,但我还需要修改designer.cs文件以合并新的对象/类.

我只是希望有人知道一种聪明的方法,通过一些控制继承来做这件事,任何允许我根据编译构建设置指定不同控件类的东西.

解决方法

你只需要一个调整,应该是:

<% #if DEBUG %>

如果你希望它表现得像一组C#代码那样.

(编辑:李大同)

【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容!

    推荐文章
      热点阅读