views:

607

answers:

3

I want to be able to point to one of 2 assemblies based on what mode (DEBUG or RELEASE) I have selected in my VS2005 IDE. Something like this (which does not work):

<%@ 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>

So, my question is: How do I correctly use a #if DEBUG in an ASPX or ASCX page?

+1  A: 

I don't know how to get what you want, but I face the same problem. I do my control references in web.config and then do post build steps to copy the appropriate web.config for release/debug. It works because you need a different web.config for release/debug anyhow (if only for the debug="true" attribute) and because you can have a different post build step for debug and release.

MatthewMartin
Do you have any examples of how you do this? Another one of my tasks will be to introduce automatic builds to this company and I've done very little outside of a very basic build.
Keith Barrows
The magic is if "$(ConfigurationName)" == "Debug" ... batch file... More info:found SO Question with some advice http://stackoverflow.com/questions/150053/how-to-run-visual-studio-post-build-events-for-debug-build-only and the MSDN Docs: http://msdn.microsoft.com/en-us/library/ke5z92ks.aspx and a blog entry http://www.adduxis.com/blogs/blogs/sven/archive/2005/11/01/15.aspx
MatthewMartin
A: 
<%
//<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

%>
ohaiyo
A: 

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.

Jason