Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/asp.net/33.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Asp.net 在.aspx文件中进行条件编译_Asp.net - Fatal编程技术网

Asp.net 在.aspx文件中进行条件编译

Asp.net 在.aspx文件中进行条件编译,asp.net,Asp.net,我需要.ASPX文件根据条件编译符号的不同行为 让我们举一个简单的例子: <%@ Control Language="C#" AutoEventWireup="true" (...) %> <% #ifdef DEBUG %> <asp:SomeDebugControlHere runat="server"/> .. well .. a LOT of code here <% #else %> <asp:SomeR

我需要.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
///自动生成的字段。
///将字段声明从设计器文件修改为代码隐藏文件。
/// 
受保护的全局::System.Web.UI.SomeDebugControlHere myControl
在发布版本中:(但决不能两者兼而有之)

///自动生成的字段。
///将字段声明从设计器文件修改为代码隐藏文件。
/// 
受保护的全局::System.Web.UI.SomeReleaseControlHere myControl
显然,我需要ASPX文件中的标记有所不同,但我也需要修改designer.cs文件以合并新的对象/类


我只是希望有人知道一种聪明的方法来实现这一点,或者通过一些控件继承,任何允许我根据编译构建设置指定不同控件类的方法。

如果您只需要调整一下,应该是:

<% #if DEBUG %>


如果您想让它像一组C代码一样工作。

使用编译符号编译时,似乎会有所不同,这取决于您声明它们的位置:作为项目属性、使用@Page指令或在web.config中

只有在web.config中定义的符号似乎在.aspx文件中起作用

<compiler
      language="c#;cs;csharp" extension=".cs"
      compilerOptions="/d:MY_CONSTANT"
      type="Microsoft.CSharp.CSharpCodeProvider, 
        System, Version=2.0.0.0, Culture=neutral, 
        PublicKeyToken=b77a5c561934e089" />
    </compilers>


找到了一些关于此的信息,我认为在某种程度上,答案在设计器文件中自动生成的注释中:

/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.SomeDebugControlHere myControl
///自动生成的字段。
///将字段声明从设计器文件修改为代码隐藏文件。
/// 
受保护的全局::System.Web.UI.SomeDebugControlHere myControl

您可能应该将这些控件的声明移动到代码隐藏文件中,并将它们封装在匹配的
#ifdef
语句中。

这就是重点。。这不起作用:-(.我需要基于此符号更改代码隐藏文件。它不起作用(VS2008和/或VS2010)@Radu094-你是什么意思?你能再解释一下你在代码背后要做什么吗?我有一个项目,其中符号也在
指令中工作。在你提到的中,描述了设置不是加法的,这意味着如果你指定
编译器选项=“/d:MY_常量”
在@Page指令中,它覆盖了您在web.config中指定的/d标志。在示例代码中,您显示了#ifdef DEBUG——请注意,C#要求它是#if DEBUG。我认为这才是真正的问题
/// Auto-generated field.
/// To modify move field declaration from designer file to code-behind file.
/// </remarks>
protected global::System.Web.UI.SomeDebugControlHere myControl