By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
424,656 Members | 800 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 424,656 IT Pros & Developers. It's quick & easy.

Can I change my code depending on the build type?

P: n/a
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
May 8 '06 #1
Share this Question
Share on Google+
10 Replies


P: n/a
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

May 8 '06 #2

P: n/a
fantastic! cheers :D

"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

May 8 '06 #3

P: n/a
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

May 8 '06 #4

P: n/a
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

May 8 '06 #5

P: n/a
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

May 8 '06 #6

P: n/a
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.)




May 10 '06 #7

P: n/a
Hi Steven,

That's the third time I've read that blog post :o) 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.)




May 10 '06 #8

P: n/a
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.)

May 10 '06 #9

P: n/a
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.)

May 10 '06 #10

P: n/a
Thanks for your response Dan,

What's the actual behavior do you mean?

=======================
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?
=======================

Based on my local test, (in vs 2005 through file test server), the
conditional compiled block will just match the setting in the web.config's
<compilation debug=xxx> attribute. Also, I've tried set this attribute for
a particular sbu directory in the application directory and that worked(
the pages under that directory conforms to the sub web.config's compilation
setting).

Is there any particular setting or scenario in your application that could
cause the difference?

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.)


May 12 '06 #11

This discussion thread is closed

Replies have been disabled for this discussion.