3

我希望能够根据我在 VS2005 IDE 中选择的模式(调试或发布)指向 2 个程序集之一。像这样的东西(不起作用):

<%@ Control Language="C#" AutoEventWireup="true" CodeBehind="VideoDialog.ascx.cs" Inherits="Company.Web.Base.Controls.VideoDialog" %>

<% #if DEBUG %>
<%@ Register TagPrefix="Company" Assembly="Company" Namespace="Company.UI.Controls.VideoControl" %>
<% #else %>
<%@ Register TagPrefix="Company" Assembly="Company.UI.Controls.VideoControl" Namespace="Company.UI.Controls.VideoControl" %>
<% #endif %>

<Company:CompanyVideo ID="Video1" runat="server"></Company:CompanyVideo>

所以,我的问题是:如何在 ASPX 或 ASCX 页面中正确使用#if DEBUG?

4

3 回答 3

3
<%
//<compilation debug="false"> in web.config
//*.aspx

#if DEBUG
    Response.Write("<script type=\"text/javascript\">");
    Response.Write("$.validator.setDefaults({ debug: true })");
    Response.Write("</script>");
#endif

%>
于 2009-12-03T15:53:47.753 回答
3

我不知道如何得到你想要的,但我面临同样的问题。我在 web.config 中进行控制引用,然后执行构建后步骤以复制适当的 web.config 以进行发布/调试。它之所以有效,是因为无论如何您都需要一个不同的 web.config 来进行发布/调试(如果仅用于 debug="true" 属性),并且因为您可以有一个不同的后期构建步骤来进行调试和发布。

于 2009-06-25T22:06:23.483 回答
2

Another approach is to use HtmlHelper extension method. Basically you code a C# file with something like this:

namespace ExtensionHandlers
{
    public static class MetaTags
    {
        public static string GetMetaTags(this HtmlHelper html)
        {
            #if DEBUG

            return string1;

            #else

            return string2;

            #endif
        }
    }
}

Then in your ascx file import the file:

<%@ Import Namespace="ExtensionHandlers" %>

And finally where you want the code just do this:

<%= Html.GetMetaTags() %>

Disclaimer: I have not compiled this, there are probably coding errors. Good luck.

于 2010-10-07T16:47:46.887 回答