Tech Off Thread

13 posts

Forum Read Only

This forum has been made read only by the site admins. No new threads or comments can be added.

DEBUG, TRACE and custom constants In ASP.NET 2.0 Projects

Back to Forum: Tech Off
  • User profile image
    Yargnits

    Ok, so I see the non-web Visual Studio 2005 projects still have the options in their properties to define DEBUG and TRACE constants as well as custom constants so that you can specify #if DEBUG, etc. in your code so that it compiles only if that constant is defined.

    However, I do not see that option in a web projects properties to do the same.  I even checked the solution properties, but I could not find anything.

    Is there something that you have to put in the web.config file to make these constants be defined based on what build configuration you are building with?

    Thanks

  • User profile image
    Yargnits

    I finally found the answer.  It is in the web.config file.

    It is done in the compilerOptions value of the compiler section.  The following needs to be added to the web.config file:

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


    Of course this means that you have to have a seperate web.config file setting for each build configuration.  But this can be streamlined by using the Web Deployment Projects add-in for Visual Studio 2005.

  • User profile image
    borosen

    Thanks

    When I add these elements to the web.config, the Error List of the IDE shows 6 messages, all regarding the same issue:

    Could not find schema information for the element/attribute...

    How do I include this schema information?

  • User profile image
    bitmask

    Note that DEBUG will be defined if you have debug="true" in the web.config.

    You could also change machine.config if you wanted the options in place for an entire machine - a little dicey to change the entire machine's config, though.

  • User profile image
    bitmask

    borosen:

    This doesn't work under medium trust. Are you in a partial trust envionment?

  • User profile image
    Yargnits

    Do you have a schema listed in your <configuration> element?  I had a schema in there for a bit (I'm not exactly sure how it got in there), and I got some schema violation error messages.  I removed that.

    Some sites that I found said that the <compilers> element was supposed to go under the system.web\compilation section, but I received errors when I put it in there.  Once I moved it to system.codedom, it was all good.  So you could try it in system.web\compilation and see if that works for you.

  • User profile image
    Yargnits

    bitmask,

    Are you talking setting the <compilation debug="true"> in <system.web> automatically defines DEBUG?  I set that on my web.config and it doesn't seem to be defined.  Am I looking at the wrong debug value?

  • User profile image
    bitmask

    Yes, <compilation debug="true"> should define DEBUG. Are you using the Publish command or Web Deploy project? They would change the setting.

  • User profile image
    borosen

    I do not have any schema listed in the configuration element.

    It just a simple folderbased website containing one aspx page and web.config.

    When I have it in system.codedom it works just fine, I just get these 6 messages (note, not errors nor warnings).

    If I put it in system.web/compilation I get a warning, the documents also states that the compilers element of system.web/compilation has been deprecated.


  • User profile image
    Yargnits

    Ah, sorry, missed that they were just regular messages.  I appear to get the same messages.  None of the sites that I've looked at for this setting gave any schema definition for this section.  So I'm not sure how to stop those messages.  The nice this is, if the web.config file is not open, the messages will not show in the list.

  • User profile image
    Yargnits

    bitmask wrote:
    Are you using the Publish command or Web Deploy project? They would change the setting.


    Actually, I'm just going off of the developement envrionment (the #if DEBUG section turns to a grey font if DEBUG is not defined and is the standard font colors if DEBUG is defined).

    I'll play around with it and see what happens.  Thanks for the info.

  • User profile image
    bitmask

    Yeah - the IDE isn't smart enough to detect when DEBUG is in effect. It all works out at runtime, though.

  • User profile image
    blowdart

    Yargnits wrote:
    Ah, sorry, missed that they were just regular messages.  I appear to get the same messages.  None of the sites that I've looked at for this setting gave any schema definition for this section.  So I'm not sure how to stop those messages.  The nice this is, if the web.config file is not open, the messages will not show in the list.


    Yea ignore them, I get those for manually setting up authenticaton entries.

    Damned idiots.

    Or delete the default namespace and lo, it all comes back.

Conversation locked

This conversation has been locked by the site admins. No new comments can be made.