Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > ASP .Net > Can I change my code depending on the build type?

Reply
Thread Tools

Can I change my code depending on the build type?

 
 
=?Utf-8?B?bXVzb3NkZXY=?=
Guest
Posts: n/a
 
      05-08-2006
I've got a function that needs to work slightly differently on the
development server from the production server, but of course I don't want to
be changing code just before compiling a release version!?

I'm thinking I could use some #if #else #endif type statements to change
certain things, depending on the build type. I'm thinking of something like
this in my .cs file...

#if DEBUG
private string MyFunc()
{
// debug version
}
#else
private string MyFunc()
{
// release version
}
#end if

Would this work!? If not, how could I achieve a similar effect? (.net 2)

Cheers


Dan
 
Reply With Quote
 
 
 
 
=?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=
Guest
Posts: n/a
 
      05-08-2006
Yes, that works.

I use it myself in an application that adds a lot of records to a
database. The release version puts data in a buffer and saves them when
the buffer is full or has lived a certain time, but the debug version
flushes the buffer for each record so that they show up in the database
immediately.

musosdev wrote:
> I've got a function that needs to work slightly differently on the
> development server from the production server, but of course I don't want to
> be changing code just before compiling a release version!?
>
> I'm thinking I could use some #if #else #endif type statements to change
> certain things, depending on the build type. I'm thinking of something like
> this in my .cs file...
>
> #if DEBUG
> private string MyFunc()
> {
> // debug version
> }
> #else
> private string MyFunc()
> {
> // release version
> }
> #end if
>
> Would this work!? If not, how could I achieve a similar effect? (.net 2)
>
> Cheers
>
>
> Dan

 
Reply With Quote
 
 
 
 
=?Utf-8?B?bXVzb3NkZXY=?=
Guest
Posts: n/a
 
      05-08-2006
fantastic! cheers

"Göran Andersson" wrote:

> Yes, that works.
>
> I use it myself in an application that adds a lot of records to a
> database. The release version puts data in a buffer and saves them when
> the buffer is full or has lived a certain time, but the debug version
> flushes the buffer for each record so that they show up in the database
> immediately.
>
> musosdev wrote:
> > I've got a function that needs to work slightly differently on the
> > development server from the production server, but of course I don't want to
> > be changing code just before compiling a release version!?
> >
> > I'm thinking I could use some #if #else #endif type statements to change
> > certain things, depending on the build type. I'm thinking of something like
> > this in my .cs file...
> >
> > #if DEBUG
> > private string MyFunc()
> > {
> > // debug version
> > }
> > #else
> > private string MyFunc()
> > {
> > // release version
> > }
> > #end if
> >
> > Would this work!? If not, how could I achieve a similar effect? (.net 2)
> >
> > Cheers
> >
> >
> > Dan

>

 
Reply With Quote
 
=?Utf-8?B?bXVzb3NkZXY=?=
Guest
Posts: n/a
 
      05-08-2006
Hi Goran...

I can't get this to work - I wonder if you could shed any light on it...

Basically, I've just setup a simple web, with a config and an aspx page,
which has the following in Page_Load()...

#if DEBUG
Response.Write("debug!");
#else
Response.Write("release!");
#endif

However, when I run this page (thru IIS), it *always* writes "debug!" - even
if I set compilation debug="false" in web.config.

Is there something else I need to enable?! I'm not using Web Publish or
anything like that, just a straightforward Rebuild and then point IE at the
webserver.

Any suggestions!?

"Göran Andersson" wrote:

> Yes, that works.
>
> I use it myself in an application that adds a lot of records to a
> database. The release version puts data in a buffer and saves them when
> the buffer is full or has lived a certain time, but the debug version
> flushes the buffer for each record so that they show up in the database
> immediately.
>
> musosdev wrote:
> > I've got a function that needs to work slightly differently on the
> > development server from the production server, but of course I don't want to
> > be changing code just before compiling a release version!?
> >
> > I'm thinking I could use some #if #else #endif type statements to change
> > certain things, depending on the build type. I'm thinking of something like
> > this in my .cs file...
> >
> > #if DEBUG
> > private string MyFunc()
> > {
> > // debug version
> > }
> > #else
> > private string MyFunc()
> > {
> > // release version
> > }
> > #end if
> >
> > Would this work!? If not, how could I achieve a similar effect? (.net 2)
> >
> > Cheers
> >
> >
> > Dan

>

 
Reply With Quote
 
=?UTF-8?B?R8O2cmFuIEFuZGVyc3Nvbg==?=
Guest
Posts: n/a
 
      05-08-2006
The setting in web.config is only used if the web server does the
compilation. If you build the solution in Visual Studio, it's the
setting in the Configuration Manager that is used.

musosdev wrote:
> Hi Goran...
>
> I can't get this to work - I wonder if you could shed any light on it...
>
> Basically, I've just setup a simple web, with a config and an aspx page,
> which has the following in Page_Load()...
>
> #if DEBUG
> Response.Write("debug!");
> #else
> Response.Write("release!");
> #endif
>
> However, when I run this page (thru IIS), it *always* writes "debug!" - even
> if I set compilation debug="false" in web.config.
>
> Is there something else I need to enable?! I'm not using Web Publish or
> anything like that, just a straightforward Rebuild and then point IE at the
> webserver.
>
> Any suggestions!?
>
> "Göran Andersson" wrote:
>
>> Yes, that works.
>>
>> I use it myself in an application that adds a lot of records to a
>> database. The release version puts data in a buffer and saves them when
>> the buffer is full or has lived a certain time, but the debug version
>> flushes the buffer for each record so that they show up in the database
>> immediately.
>>
>> musosdev wrote:
>>> I've got a function that needs to work slightly differently on the
>>> development server from the production server, but of course I don't want to
>>> be changing code just before compiling a release version!?
>>>
>>> I'm thinking I could use some #if #else #endif type statements to change
>>> certain things, depending on the build type. I'm thinking of something like
>>> this in my .cs file...
>>>
>>> #if DEBUG
>>> private string MyFunc()
>>> {
>>> // debug version
>>> }
>>> #else
>>> private string MyFunc()
>>> {
>>> // release version
>>> }
>>> #end if
>>>
>>> Would this work!? If not, how could I achieve a similar effect? (.net 2)
>>>
>>> Cheers
>>>
>>>
>>> Dan

 
Reply With Quote
 
=?Utf-8?B?bXVzb3NkZXY=?=
Guest
Posts: n/a
 
      05-08-2006
Thanks.. think that's it.

Only problem is that for the Release profile, it won't let me select
"Release" configuration for one of projects in the solution - the only option
is debug.

Any idea why?!


"Göran Andersson" wrote:

> The setting in web.config is only used if the web server does the
> compilation. If you build the solution in Visual Studio, it's the
> setting in the Configuration Manager that is used.
>
> musosdev wrote:
> > Hi Goran...
> >
> > I can't get this to work - I wonder if you could shed any light on it...
> >
> > Basically, I've just setup a simple web, with a config and an aspx page,
> > which has the following in Page_Load()...
> >
> > #if DEBUG
> > Response.Write("debug!");
> > #else
> > Response.Write("release!");
> > #endif
> >
> > However, when I run this page (thru IIS), it *always* writes "debug!" - even
> > if I set compilation debug="false" in web.config.
> >
> > Is there something else I need to enable?! I'm not using Web Publish or
> > anything like that, just a straightforward Rebuild and then point IE at the
> > webserver.
> >
> > Any suggestions!?
> >
> > "Göran Andersson" wrote:
> >
> >> Yes, that works.
> >>
> >> I use it myself in an application that adds a lot of records to a
> >> database. The release version puts data in a buffer and saves them when
> >> the buffer is full or has lived a certain time, but the debug version
> >> flushes the buffer for each record so that they show up in the database
> >> immediately.
> >>
> >> musosdev wrote:
> >>> I've got a function that needs to work slightly differently on the
> >>> development server from the production server, but of course I don't want to
> >>> be changing code just before compiling a release version!?
> >>>
> >>> I'm thinking I could use some #if #else #endif type statements to change
> >>> certain things, depending on the build type. I'm thinking of something like
> >>> this in my .cs file...
> >>>
> >>> #if DEBUG
> >>> private string MyFunc()
> >>> {
> >>> // debug version
> >>> }
> >>> #else
> >>> private string MyFunc()
> >>> {
> >>> // release version
> >>> }
> >>> #end if
> >>>
> >>> Would this work!? If not, how could I achieve a similar effect? (.net 2)
> >>>
> >>> Cheers
> >>>
> >>>
> >>> Dan

>

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      05-09-2006
Hi Dan,

As for the following behavior you mentioned:

============
it won't let me select
"Release" configuration for one of projects in the solution - the only
option
is debug.
============

this is due to the new dynamic compilation model of ASP.NET 2.0
application, and as for ASP.NET 2.0 web project, it is different from
original ASP.NET 1.X/VS 2003 web project, there is no prebuilt project
assembly, all the stuffs are dynamically get compiled. So the debug/release
is depend on the web.config file's <compilation debug=xxx> setting. The
following blog article has a detailed description on the new compilation
behavior:

#Debug and Release Builds in ASP.NET 2.0
http://odetocode.com/Blogs/scott/arc...1/15/2464.aspx

Also, for ASP.NET 2.0 application, we can precompile the whole site, and
the ASP.NET dev team has provided a web deployment project that can help
control the precompilation more convenient which include specifying the
release/debug precompilation setting:


#Visual Studio 2005 Web Deployment Projects
http://msdn.microsoft.com/asp.net/re...structure/wdp/

Hope this helps.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)










 
Reply With Quote
 
=?Utf-8?B?bXVzb3NkZXY=?=
Guest
Posts: n/a
 
      05-09-2006
Hi Steven,

That's the third time I've read that blog post ) Unfortunately, I'm still
no wiser.

Reading that, it looks like I can't get a release build of my code from
VS2005 unless I use the Publish command - is that right?

If that's the case, that's fine - but I'm getting "Ambiguous match" problems
when I do that. Is there no way to make a Release build without Publish or
WDP?

Thanks for your time (and patience!)


Dan

"Steven Cheng[MSFT]" wrote:

> Hi Dan,
>
> As for the following behavior you mentioned:
>
> ============
> it won't let me select
> "Release" configuration for one of projects in the solution - the only
> option
> is debug.
> ============
>
> this is due to the new dynamic compilation model of ASP.NET 2.0
> application, and as for ASP.NET 2.0 web project, it is different from
> original ASP.NET 1.X/VS 2003 web project, there is no prebuilt project
> assembly, all the stuffs are dynamically get compiled. So the debug/release
> is depend on the web.config file's <compilation debug=xxx> setting. The
> following blog article has a detailed description on the new compilation
> behavior:
>
> #Debug and Release Builds in ASP.NET 2.0
> http://odetocode.com/Blogs/scott/arc...1/15/2464.aspx
>
> Also, for ASP.NET 2.0 application, we can precompile the whole site, and
> the ASP.NET dev team has provided a web deployment project that can help
> control the precompilation more convenient which include specifying the
> release/debug precompilation setting:
>
>
> #Visual Studio 2005 Web Deployment Projects
> http://msdn.microsoft.com/asp.net/re...structure/wdp/
>
> Hope this helps.
>
> Regards,
>
> Steven Cheng
> Microsoft Online Community Support
>
>
> ==================================================
>
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
>
> ==================================================
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
>
>
>
>
>
>
>
>
>
>

 
Reply With Quote
 
Steven Cheng[MSFT]
Guest
Posts: n/a
 
      05-10-2006
Thanks for your response Dan,

Actually the fixed "Debug" option in the VS 2005 SOLUTION for ASP.NET
project is just a dummy setting which won't make actual effect. That just
tell us that for ASP.NET 2.0 project, there is no concept of development
time prebuilt project assemblies. And for ASP.NET 2.0 pages and classes in
the App_Code, they will be dynamically compiled, and the debug/release
version just rely on the web.config's <compilation debug=...> setting.

Are you correctly put such case dependent code in page's codebehind for in
custom helper class's file? If in custom helper class, maybe you can
consider arrange them into a separate class library which will be more
convenient to control the debug/release output since class library project
is prebuilt at development time.

Regards,

Steven Cheng
Microsoft Online Community Support


==================================================

When responding to posts, please "Reply to Group" via your newsreader so
that others may learn and benefit from your issue.

==================================================


This posting is provided "AS IS" with no warranties, and confers no rights.



Get Secure! www.microsoft.com/security
(This posting is provided "AS IS", with no warranties, and confers no
rights.)

 
Reply With Quote
 
=?Utf-8?B?bXVzb3NkZXY=?=
Guest
Posts: n/a
 
      05-10-2006
Steven,

Thanks for the patience!

Okay, so last first... yeah, I could do that. But the code I'm altering is
really integral to the application, so I don't *really* want to seperate it
out if I can help it.

What's more worrying though, is that whether I compilation debug= to true OR
false in my web.config, I always get the debug version, which would indicate
that it doesn't seem to be making any difference?

I don't actually need the alternate functions, I could just replace before
the final build, but it's the fact that I can't seem to switch it which is
making me persevere!

Any ideas?!

"Steven Cheng[MSFT]" wrote:

> Thanks for your response Dan,
>
> Actually the fixed "Debug" option in the VS 2005 SOLUTION for ASP.NET
> project is just a dummy setting which won't make actual effect. That just
> tell us that for ASP.NET 2.0 project, there is no concept of development
> time prebuilt project assemblies. And for ASP.NET 2.0 pages and classes in
> the App_Code, they will be dynamically compiled, and the debug/release
> version just rely on the web.config's <compilation debug=...> setting.
>
> Are you correctly put such case dependent code in page's codebehind for in
> custom helper class's file? If in custom helper class, maybe you can
> consider arrange them into a separate class library which will be more
> convenient to control the debug/release output since class library project
> is prebuilt at development time.
>
> Regards,
>
> Steven Cheng
> Microsoft Online Community Support
>
>
> ==================================================
>
> When responding to posts, please "Reply to Group" via your newsreader so
> that others may learn and benefit from your issue.
>
> ==================================================
>
>
> This posting is provided "AS IS" with no warranties, and confers no rights.
>
>
>
> Get Secure! www.microsoft.com/security
> (This posting is provided "AS IS", with no warranties, and confers no
> rights.)
>
>

 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Change a constant value, depending on a generic Barry VHDL 6 01-16-2009 03:16 AM
Build of extension module depending on external lib fails on Solaris 10 Eric Brunel Python 1 11-21-2008 10:33 PM
repeater control - change the background color depending on a value bill ASP .Net Web Controls 2 03-20-2006 08:00 PM
How to change data displayed in one GridView depending on selection made in the second one? (ASP.NET 2.0) misiek ASP .Net 7 02-28-2006 09:40 AM
SWsoft Acronis Disk Director Suite 9.0 Build 508, Acronis OS Selector 8.0 Build 917, Acronis Partition Expert 2003 Build 292, Acronis Power Utilities 2004 Build 502, F-SECURE.ANTI vIRUS.PROXY v1.10.17.WINALL, F-SECURE.ANTI vIRUS v5.50.10260 for CITRI vvcd Computer Support 0 09-25-2004 01:38 AM



Advertisments